Open erosman opened 3 months ago
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):
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.
Similar to #611.
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).
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"
There can be 2 approaches:
string
: One of "INCOGNITO_ONLY", "DEFAULT_AND_INCOGNITO", "DEFAULT_ONLY"
_defaults to "DEFAULT_ANDINCOGNITO"array
: Any of "INCOGNITO", "DEFAULT"
defaults to ["INCOGNITO", "DEFAULT"] in case of missing or falsy property, or empty array []
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"]
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.
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 extraincognito
parameter to the aforementioned APIs.Keyword
Use
incognito
in line with tabs.TabProposal
Add optional boolean
incognito
which defaults totrue