Open JabRef with a url handler#18
Conversation
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
Nice! This is I also thought for the VS Code extension - cc @palukku |
| if (window.chrome && chrome.tabs && chrome.tabs.update) { | ||
| try { | ||
| await new Promise((resolve) => | ||
| chrome.tabs.update({ url: "jabref://", active: false }, () => resolve()), |
There was a problem hiding this comment.
Thinking aloud:
Wouldn't it even possible to pass the import here? - OK, this would mean: back to native messaging "kind of"? -- Meaning: the URL handler is surely able to pass a command line argument to JabRef - and JabGui could be able to handle some arguments passing from the browser extension - no sophisticated "nice" CLI, maybe just process-browser-extension-url and then as additional parameter some URL, which is then internally parsed by JabRef. -- OK, then we have the issue with "command line too long". Then we are back on writing temporary files :)
Maybe, we need "web sockets" again -- if JabRef is started via the browser extension, JabRef could send a web socket call to the browser extension to say: Hey, I am ready to process. OK, but this needs a connection started from the browser extension - and we are back to 0.
There was a problem hiding this comment.
I was thinking the same thing.
It would mean managing the message in jabref, as by default it doesn't read the part after the // as the cli arguments (not sure why).
If so we could use the --importBibtex using this method, not needing the server to be active.
There was a problem hiding this comment.
Alternative:
UrlHandler as seperate program.
- Running JabRef - just continuing
- Non-Running JabRef: Start http server without UI.
But maybe not good if user then starts UI manually, this could be confusing - and we would need to update the http handling to work non-gui.
There was a problem hiding this comment.
I was thinking the same thing. It would mean managing the message in jabref, as by default it doesn't read the part after the
//as the cli arguments (not sure why).If so we could use the --importBibtex using this method, not needing the server to be active.
TBH, I like it better if the URL handler would just start JabRef and we would use HTTP for the "real" communication... Don't want to fiddle around with URL Handler issues (maybe even different browsers doing differently) - and maintaining an additional CLI interface.
Idea: "PING" JabRef on start of Browser (if enabled by the user)
There was a problem hiding this comment.
What's the problem with native messaging? It's the "official" method for browser-extension-to-app communication, and the current solution works relatively reliable. Since it would be only a fall-back in case of deactivated http server, this seems to me a fine path. And we already have the code for it, and it would be backwards compatible with a bit older JabRef versions...
There was a problem hiding this comment.
This might be more of a problem on linux, but with different systems/install methods things get complicated.
Url handlers could be the next best thing, althought they are limited in length (especially on windows).
There was a problem hiding this comment.
Yes, I feel like on Windows it's the opposite.
There was a problem hiding this comment.
Also mentioned at JabRef/JabRef-Browser-Extension#624 (comment).
Here on Windows, the new extension works very well.
My current reading is that it "only" causes trouble if the user did not start JabRef GUI when clicking on the import symbol. The decision to take is know to a) ensure that a newly started JabRef GUI accepts the http call properly or b) re-introduce native messaging for the newly started case (and maintain that interface including installation challenges.
To get an impression of the effort on JabRef's side regarding native messaging see the PR where we removed that: JabRef/jabref#14884
User description
Proof of concept.
This needs a slight change in the jabref packaging, then we can use it to call jabref as a url handler.
Currently it could be used to start the program if not already active.
In theory this might make it so we can pass any cli arguments using the url handler. Asks for a permission on first run but can then be registered.
At the moment it's a bit flaky on whether it imports the bib item after starting, but should be fixable by just moving some code around.
PR Type
Enhancement
Description
Add protocol handler support to launch JabRef via jabref:// URL
Implement automatic retry mechanism with polling to detect JabRef startup
Fallback to protocol handler when HTTP connection fails initially
Configurable timeout and polling interval for server availability checks
Diagram Walkthrough
flowchart LR A["Connection attempt"] --> B{"HTTP connection<br/>successful?"} B -->|Yes| C["Connected to JabRef"] B -->|No| D["Trigger jabref://<br/>protocol handler"] D --> E["Poll HTTP server<br/>with timeout"] E --> F{"Server<br/>reachable?"} F -->|Yes| C F -->|No| G["Connection timeout"]File Walkthrough
popup.js
Add protocol handler launch with server pollingpopup.js
openJabRefAndWait()function to trigger JabRef via protocolhandler and poll for server availability
(default 1s) for HTTP server detection
connectToJabRef()to attempt protocol handler launch wheninitial HTTP connection fails
and connection outcomes