Closed Bug 1470651 Opened 7 years ago Closed 3 years ago

Contextual Identities: Allow matching on cookieStoreId for browser.contentScripts.register

Categories

(WebExtensions :: General, enhancement, P3)

enhancement

Tracking

(firefox97 fixed)

RESOLVED FIXED
97 Branch
Tracking Status
firefox97 --- fixed

People

(Reporter: ntninja, Assigned: onlinericha19)

References

Details

(Keywords: dev-doc-complete, Whiteboard: [privacy])

Attachments

(1 file, 6 obsolete files)

# Problem Currently the `browser.contentScripts.register` function does not allow one to limit the set of matched tabs to tabs using a specific contextual identity making it impossible to synchronously modify the DOM of a page at `document_start`[1]. # Solution Add a new `cookieStoreId` field to the `RegisteredContentScriptOptions` interface that, if set, limits the set of matched tabs to those that belong to the given container. [1]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/contentScripts/register
Priority: -- → P3
Severity: normal → enhancement
Version: 62 Branch → unspecified
Whiteboard: [privacy]

Has any progress been made on this feature?

This would also help with my problem that normal contentScripts do not know in which container they run in. In CanvasBlocker there are settings that are dependent on the cookieStoreId (some rng seeds to make the rng consistent within a container but different between them - this is necessary to prevent fingerprint crosstask - so completely in the spirit of the containers which are a really great thing).
So to know these I have to send a message to the main script (via browser.runtime.connect) that then returns the cookieStoreId. But as this is an asynchronous operation I have a race condition (https://github.com/kkapsner/CanvasBlocker/issues/369).

Having the ability to register content scripts depending on the cookieStoreId could this problem.

Assignee: nobody → onlinericha19
Attachment #9181615 - Attachment description: Bug 1470651 Add support for contextual identities when registering content scripts. r=rpl → Bug 1470651 - Add support for contextual identities when registering content scripts. r=rpl
Attachment #9218395 - Attachment is obsolete: true
Attachment #9218574 - Attachment is obsolete: true
Attachment #9244203 - Attachment is obsolete: true
Attachment #9244336 - Attachment is obsolete: true
Blocks: 1738567
Attachment #9181615 - Attachment is obsolete: true
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
Attachment #9239468 - Attachment description: Bug 1470651 - Add support for multiple contextual identities when registering content scripts. r=rpl,robwu → Bug 1470651 - Support cookieStoreId option in contentScripts.register r=rpl,robwu
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/d847e5e30768 Support cookieStoreId option in contentScripts.register r=rpl,robwu

Backed out for failures on test_ext_contentScripts_register.js

[task 2021-12-07T14:06:36.728Z] 14:06:36     INFO -  TEST-START | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js
[task 2021-12-07T14:06:36.799Z] 14:06:36     INFO -  adb launch_application: am startservice -W -n 'org.mozilla.geckoview.test_runner/org.mozilla.geckoview.test_runner.XpcshellTestRunnerService$i0' -a android.intent.action.MAIN --es env0 XPCOM_DEBUG_BREAK=stack-and-abort --es env1 MOZ_CRASHREPORTER=1 --es env2 MOZ_CRASHREPORTER_NO_REPORT=1 --es env3 MOZ_DISABLE_NONLOCAL_CONNECTIONS=1 --es env4 MOZ_DEVELOPER_REPO_DIR=/builds/worker/checkouts/gecko --es env5 MOZ_DISABLE_CONTENT_SANDBOX=1 --es env6 MOZ_FETCHES_DIR=/builds/worker/fetches --es env7 MOZ_DISABLE_SOCKET_PROCESS=1 --es env8 MOZ_WEBRENDER=1 --es env9 MOZ_ACCELERATED=1 --es env10 LD_LIBRARY_PATH=/data/local/tmp/test_root/xpcb --es env11 MOZ_LINKER_CACHE=/data/local/tmp/test_root/xpcb --es env12 GRE_HOME=/data/local/tmp/test_root/xpcb --es env13 XPCSHELL_TEST_PROFILE_DIR=/data/local/tmp/test_root/xpc/p/36958c66-6d00-4c6f-b80e-b072b100c4b1 --es env14 HOME=/data/local/tmp/test_root/xpc/p --es env15 XPCSHELL_TEST_TEMP_DIR=/data/local/tmp/test_root/xpc/tmp/f9fa36d1-59d9-491f-9500-59c380a304b0 --es env16 MOZ_ANDROID_DATA_DIR=/data/local/tmp/test_root/xpcb --es env17 MOZ_IN_AUTOMATION=1 --es env18 MOZ_ANDROID_CPU_ABI=x86_64 --es env19 MOZHTTP2_PORT=43305 --es env20 MOZNODE_EXEC_PORT=34815 --es env21 TMPDIR=/data/local/tmp/test_root/xpc/p/36958c66-6d00-4c6f-b80e-b072b100c4b1 --es env22 XPCSHELL_MINIDUMP_DIR=/data/local/tmp/test_root/xpc/minidumps/36958c66-6d00-4c6f-b80e-b072b100c4b1 --es arg0 -g --es arg1 /data/local/tmp/test_root/xpcb --es arg2 --greomni --es arg3 /data/local/tmp/test_root/xpcb/geckoview-test_runner.apk --es arg4 -m --es arg5 -e --es arg6 'const _HEAD_JS_PATH = "/data/local/tmp/test_root/xpc/head.js";' --es arg7 -e --es arg8 'const _MOZINFO_JS_PATH = "/data/local/tmp/test_root/xpc/p/36958c66-6d00-4c6f-b80e-b072b100c4b1/mozinfo.json";' --es arg9 -e --es arg10 'const _PREFS_FILE = "/data/local/tmp/test_root/xpc/tmp/f9fa36d1-59d9-491f-9500-59c380a304b0/user.js";' --es arg11 -e --es arg12 'const _TESTING_MODULES_DIR = "/data/local/tmp/test_root/xpc/m";' --es arg13 -f --es arg14 /data/local/tmp/test_root/xpc/head.js --es arg15 -e --es arg16 'const _HEAD_FILES = ["/data/local/tmp/test_root/xpc/toolkit/components/extensions/test/xpcshell/head.js", "/data/local/tmp/test_root/xpc/toolkit/components/extensions/test/xpcshell/head_telemetry.js", "/data/local/tmp/test_root/xpc/toolkit/components/extensions/test/xpcshell/head_sync.js", "/data/local/tmp/test_root/xpc/toolkit/components/extensions/test/xpcshell/head_storage.js"];' --es arg17 -e --es arg18 'const _JSDEBUGGER_PORT = 0;' --es arg19 -e --es arg20 'const _TEST_CWD = "/data/local/tmp/test_root/xpc/toolkit/components/extensions/test/xpcshell";' --es arg21 -e --es arg22 'const _TEST_FILE = ["test_ext_contentScripts_register.js"];' --es arg23 -e --es arg24 'const _TEST_NAME = "xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js";' --es arg25 -e --es arg26 '_execute_test(); quit(0);' --ez use_multiprocess True --es out_file /data/local/tmp/test_root/xpc/logs/xpcshell-115d88bf-21f5-4570-ba15-5b507493467e.log
[task 2021-12-07T14:06:37.052Z] 14:06:37     INFO -  remotexpcshelltests.py | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js | 29152 | Launched Test App
[task 2021-12-07T14:06:40.651Z] 14:06:40     INFO -  remotexpcshelltests.py | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js | 29152 | Application ran for: 0:00:03.921890
[task 2021-12-07T14:06:40.732Z] 14:06:40  WARNING -  TEST-UNEXPECTED-FAIL | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js | xpcshell return code: 0
[task 2021-12-07T14:06:40.732Z] 14:06:40     INFO -  TEST-INFO took 4004ms
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  >>>>>>>
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  (xpcshell/head.js) | test MAIN run_test pending (1)
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  (xpcshell/head.js) | test run_next_test 0 pending (2)
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  (xpcshell/head.js) | test MAIN run_test finished (2)
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  running event loop
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js | Starting check_remote
[task 2021-12-07T14:06:40.733Z] 14:06:40     INFO -  (xpcshell/head.js) | test check_remote pending (2)
[task 2021-12-07T14:06:40.734Z] 14:06:40     INFO -  TEST-PASS | xpcshell.ini:toolkit/components/extensions/test/xpcshell/test_ext_contentScripts_register.js | check_remote - [check_remote : 1] useRemoteWebExtensions matches - false == false
Flags: needinfo?(onlinericha19)

Test failure on Android happens for the same reason as in bug 1743616.
To resolve that, see https://phabricator.services.mozilla.com/D124537#inline-732229

See Also: → 1743616
Attachment #9239468 - Attachment description: Bug 1470651 - Support cookieStoreId option in contentScripts.register r=rpl,robwu → Bug 1470651 - Add support for multiple contextual identities when registering content scripts. r=rpl,robwu

Depends on D124537

Attachment #9239468 - Attachment description: Bug 1470651 - Add support for multiple contextual identities when registering content scripts. r=rpl,robwu → Bug 1470651 - Support cookieStoreId option in contentScripts.register r=rpl,robwu
Attachment #9254978 - Attachment is obsolete: true
Pushed by rob@robwu.nl: https://hg.mozilla.org/integration/autoland/rev/9262f55fbcd6 Support cookieStoreId option in contentScripts.register r=rpl,robwu
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 97 Branch

What about browser.userScripts.register?

(In reply to erosman from comment #17)

What about browser.userScripts.register?

That will be addressed in bug 1738567, using the internals introduced in this bug.

Flags: needinfo?(onlinericha19)

Is the following the behaviour of setting cookieStoreId in browser.contentScripts.register?
(supposing user has allowed the extension to run in private mode)

  • no cookieStoreId => inject into all tabs
  • firefox-private => inject only into private tabs
  • firefox-default => inject only into non-private, non-container tabs
  • firefox-container-N => inject only into firefox-container-N tabs

(In reply to erosman from comment #19)

Is the following the behaviour of setting cookieStoreId in browser.contentScripts.register?
(supposing user has allowed the extension to run in private mode)

  • no cookieStoreId => inject into all tabs
  • firefox-private => inject only into private tabs
  • firefox-default => inject only into non-private, non-container tabs
  • firefox-container-N => inject only into firefox-container-N tabs

Yes. And cookieStoreId can be an array if you'd like to support injection in one or multiple targets.

Documentation changes are ready for review:

Flags: needinfo?(rob)
Flags: needinfo?(rob)
See Also: → 1764572
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: