Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Content scripts for custom protocols #26

Closed
sammacbeth opened this issue Jul 18, 2018 · 2 comments
Closed

Content scripts for custom protocols #26

sammacbeth opened this issue Jul 18, 2018 · 2 comments
Labels
Protocol Protocol API related issues

Comments

@sammacbeth
Copy link
Contributor

It does not seem currently possible to inject content-scripts into pages loaded via the protocol handler API. I tested the following methods:

  • content_scripts manifest key: Custom protocol patterns (e.g. dweb://*/*) are not accepted under the matches key. Also using <all_urls> does not trigger for custom protocols.
  • browser.tabs.executeScript for tab loading a custom protocol url. This gives me the error: "Missing host permission for the tab".

My use-case for content-scripts on these pages is to inject APIs into the pages. The content-script is required to create a communication channel between the page and the extension background. An alternative to using content-scripts would be a method to add APIs to a protocol, as part of browser.protocol.

@Gozala
Copy link
Contributor

Gozala commented Jul 19, 2018

Thanks for reporting. It seems that WebExtensions are supporting specific set of protocols only based on the documentation:

The special value "<all_urls>" matches all URLs under any of the supported schemes: that is "http", "https", "ws", "wss", "ftp" and "file".

Presumably list of supported protocols is there to avoid loading content scripts into things like about:, chrome:, resource:. So we'd need to discuss this with the Web Extension team to see what are our options there.

An alternative to using content-scripts would be a method to add APIs to a protocol, as part of browser.protocol.

I think this is reasonable. Still it's likely will need to use same content script infrastructure and to be honest I'm not sure there will be much benefit to this over just content scripts.

I would much rather prefer API like:

navigator.permissions.query({ name: something })  

Where addon's could subscribe to requests on something and optionally return implementation. I'm trying to discuss this but it's also unlikely to make it anytime soon.

I think the best bet right now would be to define a REST API to the extension background with a protocol handler itself. And then use fetch or XMLHttpRequest to interact with it.

@Gozala
Copy link
Contributor

Gozala commented Aug 7, 2019

Filled a bug in bugzilla for this https://bugzilla.mozilla.org/show_bug.cgi?id=1572187 as this can't be addressed here.

@Gozala Gozala closed this as completed Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Protocol Protocol API related issues
Projects
None yet
Development

No branches or pull requests

2 participants