zumoshi / BrowserSelect

Browser Select is a utility to dynamically select the browser you want instead of just having one default for all links.
GNU General Public License v2.0
288 stars 39 forks source link

[Feature request] BrowserSelect as native messaging host #56

Open kirill-gr opened 5 years ago

kirill-gr commented 5 years ago

If BrowserSelect operates as native messaging host, it will be possible to create browser extensions allowing BrowserSelect to open a URL in a different browser, like it does now for non-browser applications. https://developer.chrome.com/extensions/nativeMessaging https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Native_messaging

Use case example

Google docs are opened in a separate Google Chrome profile, which is created exclusively to work with Google Drive.

zumoshi commented 5 years ago

Hi This is interesting. I didn't know about native messaging. My plan for an extension was registering a protocol (e.g. bsurl:) and have the extension invoke browser select that way. Similar to what choosey does. But we couldn't display a list of browsers that way, just add a context menu option of open link in BrowserSelect.

Thanks for your suggestion. Although I'm currently busy with some projects and don't have a lot of free time for my open-source projects. but if you ended up working on it I will accept pull requests. If not I'll add it to the todo list, but don't expect it to be implanted in the next 3 months or so.

kirill-gr commented 5 years ago

Hi, Great that you are interested it this feature too. I have zero knowledge in Windows development, but could do a proof of concept on browser side (an extension that would call some external application instead of navigating a link).

kirill-gr commented 4 years ago

@zumoshi, Here's extension proof of concept: https://github.com/kromkrom/browser-select-extension-poc Extension checks if a URL should be opened in a different browser by consulting external application using native messaging. If external app says that a URL is handled, then extension closes any tab to be opened. There's also a simple Python app that plays role of BrowserSelect. It simply replies that it handles a URL if it contains "yandex.ru" in it. For Chrome to know about the host app, information about it have to be added to Windows registry (see extension.reg). I'm not quite sure if extension id will be the same for you. Its ID should be specified in allowed_origins in manifest.json.

zumoshi commented 4 years ago

Thanks for the code.

Regarding the extension id, as far as I know, it's hash of extension's files, so as long as I don't modify the files it should stay the same.

There are a few things that I wonder if we should do differently, for example, we can get a list of rules from browserSelect and handle the comparisons inside the extension instead of sending every URL to the app. That way browserselect won't have to stay open in the background all the time.

Or instead of onBeforeNavigate maybe we can use other events like on link clicks. mostly to prevent things like the extension closing an iframe and opening it in a new browser window. not to mention any event initiated from javascript (and not user action) can be potentially abused. for example to open many browser windows using browserselect to work around the browser's built-in limitations.

But for a PoC it works, and is a good code base to start off and will save me hours navigating the docs for native messaging. so thanks.

kirill-gr commented 4 years ago

Not sure it is a hash of files, since it didn't change while I was changing the code.

Loading rules into the extension should make things faster, but how to propagate rule updates?

Probably, choosing the right set of events to intercept will be one of the challenging tasks :) I used onBeforeNavigate as "catch all" to ease testing.