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

Discuss: scripting.registerContentScripts() when there are no host permissions #356

Closed
hanguokai opened this issue Feb 27, 2023 · 2 comments
Labels
discussion Needs further discussion opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari

Comments

@hanguokai
Copy link
Member

hanguokai commented Feb 27, 2023

Chrome, Firefox and Safari(>= 16.4) supports dynamic content script, i.e. scripting.registerContentScripts().

At present, if an extension doesn't have related host permissions, scripting.registerContentScripts() runs without error, and scripting.getRegisteredContentScripts() can get the registered info. But in fact, the registered content scripts don't run in the matched websites. From an ergonomic point of view, this is a bit counterintuitive.

So, I have a few suggestions for registerContentScripts(). Similar to identity.getAuthToken(), add an option parameter for requesting the host permission, and return whether it is registered successful.

browser.scripting.registerContentScripts(
  scripts: RegisteredContentScript[],

  // a new option object
  // if interactive is true, then promote the user to grant the host permissions if needed.
  // like permissions.request(), interactive is true only works with a user gesture.
  option?: { interactive: boolean },

  // return true if all content scripts are registered successful.
  callback?: success => void
)

This suggestion is only to improve the developer experience. It can be workaround by calling permissions.contains()/request() before scripting.registerContentScripts().

@xeenon xeenon added discussion Needs further discussion opposed: safari Opposed by Safari and removed needs-triage labels Mar 2, 2023
@zombie
Copy link
Collaborator

zombie commented Mar 2, 2023

While this doesn't sound unreasonable, I wouldn't support this API feature in Firefox. It might seem convenient for developers to add a flag and browser to automatically ask for permissions, but that might provide a false sense for developers that if this method call doesn't return an error, the new content scripts would run from now.

In Firefox MV3 (and in some configurations in other browsers), host permissions can be granted and revoked by users both before and after this method call, and is something that developers should be aware of and account for, using the existing browser.permissions methods and events.

In our opinion that would be the recommended way for this functionality, developers should check if they have all necessary permissions for the newly registered content scripts, and trigger the request for the user for any they might be lacking.

@zombie zombie added the opposed: firefox Opposed by Firefox label Mar 2, 2023
@Rob--W Rob--W added the opposed: chrome Opposed by Chrome label Mar 2, 2023
@hanguokai
Copy link
Member Author

In terms of the API itself, Ok, I close this issue.

But the API documentation needs to be improved. Developers needs to be warned that even if this API executes successfully it does not mean that content scripts will actually execute. Dynamic (even static) content scripts only run when the extension has related host permission. Host permissions may be removed by the user at any time. Developers need to use this API in conjunction with browser.permissions API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion Needs further discussion opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari
Projects
None yet
Development

No branches or pull requests

4 participants