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

Proposal: Incognito parameter in userScripts API #669

Open
erosman opened this issue Aug 7, 2024 · 4 comments
Open

Proposal: Incognito parameter in userScripts API #669

erosman opened this issue Aug 7, 2024 · 4 comments
Labels

Comments

@erosman
Copy link

erosman commented Aug 7, 2024

Proposal: Incognito parameter in userScripts API

Background

There are occasions that userscript developers might want to limit their userscript to non-incognito tabs.

More importantly, users would benefit greatly from the ability to limit a userscript to non-incognito tabs, which improves the overall security of a userscript.

Firefox in MV 2 supported incognito control via cookieStoreId in contentScripts.register() & userScripts.register() APIs.

Replacement APIs in MV3 i.e. scripting.registerContentScripts() & chrome.userScripts do not support the parameter (yet).

FireMonkey has been supporting this option since 2021.
Please note the following post for the use-case scenarios.
(User Metadata is the feature of FM to set/unset/override parameters set in a userscript)
See Also: [FireMonkey] should honor current container cookies

The feature has been requested of other userscript manager as well.
See Also: [Feature] Ability to disable scripts in and out of Private/Incognito mode

While Firefox has been supporting incognito via cookieStoreId along with container support, for the sake of consistency between browsers, it might be simpler to add an extra incognito parameter to the aforementioned APIs.

Keyword

Use incognito in line with tabs.Tab

Proposal

Add optional boolean incognito which defaults to true

  incognito?: boolean,
  // if `false`, don't inject into incognito tabs
  // defaults to true
@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels Aug 7, 2024
@Rob--W
Copy link
Member

Rob--W commented Aug 7, 2024

This feature sounds useful to not just the userScripts API but also the scripting API.

Although the proposal suggests a boolean incognito, there are actually three potential states of interest (could still be mapped to booleans with null, true, false):

  • Run everywhere (default)
  • Run in incognito / private browsing mode only.
  • Do not run in incognito / private browsing mode (only regular, i.e. non-private browsing mode).

While Chrome only recognizes "incognito" and "non-incognito", in Firefox the "non-incognito" case can be separated in even more cases ("container tabs"). Firefox enables extensions to identify separate cases by cookieStoreId, and there is already an issue tracking the addition of the cookieStoreId property in the scripting API at https://bugzilla.mozilla.org/show_bug.cgi?id=1764572.

@xeenon
Copy link
Collaborator

xeenon commented Aug 15, 2024

Similar to #611.

@xeenon xeenon added supportive: safari Supportive from Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels Aug 15, 2024
@Rob--W Rob--W added follow-up: chrome Needs a response from a Chrome representative supportive: firefox Supportive from Firefox and removed needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time labels Aug 15, 2024
@oliverdunk
Copy link
Member

I discussed this with the Chrome team. We're supportive, although feel quite strongly that this should be an enum ("INCOGNITO_ONLY", "DEFAULT_AND_INCOGNITO", "DEFAULT_ONLY" for example).

@oliverdunk oliverdunk added supportive: chrome Supportive from Chrome and removed follow-up: chrome Needs a response from a Chrome representative labels Aug 16, 2024
@erosman
Copy link
Author

erosman commented Aug 16, 2024

enum

1. Keyword

From the contextual point of view, using enum for incognito property might seem rather confusing i.e.

incognito = INCOGNITO_ONLY
incognito = DEFAULT_AND_INCOGNITO
incognito = DEFAULT_ONLY

It might be more logical to use an alternative keyword e.g.

context = "DEFAULT_AND_INCOGNITO"

2. Type

There can be 2 approaches:

  • string: One of "INCOGNITO_ONLY", "DEFAULT_AND_INCOGNITO", "DEFAULT_ONLY"
    defaults to "DEFAULT_AND_INCOGNITO"
  • array: Any of "INCOGNITO", "DEFAULT"
    defaults to ["INCOGNITO", "DEFAULT"] in case of missing or falsy property, or empty array []

3. Case

As mentioned in #563, a consensus on case would be beneficial as modern APIs (as well as developers) tend to favour lower_snake_case e.g. ["incognito", "default"]

Permission

In any case (enum or boolean), since incognito script injection often requires a specific permission, browsers should have a fallback (instead of a hard throw) in case permission had not been not granted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants