Open Bug 1643405 Opened 4 years ago Updated 2 years ago

User scripts don't run on pages with a caching service worker

Categories

(Core :: DOM: Service Workers, defect)

78 Branch
defect

Tracking

()

UNCONFIRMED

People

(Reporter: bugzilla, Unassigned)

References

Details

(Keywords: regressionwindow-wanted)

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0

Steps to reproduce:

Quoting from https://github.com/Tampermonkey/tampermonkey/issues/773 :

In an attempt to track down why a userscript wasn't working on a certain website (devdocs.io), I wrote a very simple test script and set it up to run on every page. It works everywhere except on devdocs.io. The problem didn't occur on Chromium.

// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http*:///
// @run-at document-start
// ==/UserScript==

(function() {
'use strict';
console.log('Test script running.');
})();

Quoting from https://github.com/Tampermonkey/tampermonkey/issues/773#issuecomment-552951807 :

Workaround for the moment:

go to about:config
search dom.caches.enabled and
set it to false.

Note: you might also need to unregister the service worker at about:debugging#/runtime/this-firefox.

Quoting from https://github.com/Tampermonkey/tampermonkey/issues/952#issuecomment-638423666 and following:

it does not seem to work on twitter.com for me...

Your twitter issue is most likely caused by https://github.com/Tampermonkey/tampermonkey/issues/773

Yeah, disabling dom.caches.enabled fixes it.

Actual results:

Quoting from https://github.com/Tampermonkey/tampermonkey/issues/773 :

It does exactly what it's supposed to do on pages that aren't devdocs.io. On that page, things get weird. No message shows up in the console, but Tampermonkey still shows the script as active by displaying it in the context menu and displaying the red badge with a number.

Also quoting from https://github.com/Tampermonkey/tampermonkey/issues/952#issuecomment-638423666:

it does not seem to work on twitter.com for me...

Expected results:

Quoting from https://github.com/Tampermonkey/tampermonkey/issues/773 :

The message "Test script running." should be printed to the console immediately after loading or reloading a page.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → DOM: Service Workers
Product: Firefox → Core
See Also: → 1177968

Perry, can you please try a guess on severity here? Thank you!

Flags: needinfo?(perry)

Hi, Tampermonkey dev here.

First I know there is a dedicated browser.userScript API, but Tampermonkey can't use it for several reasons. Therefore Tampermonkey injects its userscripts directly into the page. It's done this way at Chrome (and derivates), Safari and Firefox. The problem is that in opposition to Chrome script tags injected by content_scripts are not executed at pages with a strict CSP (issue 1267027).
To fix this Tampermonkey modifies the page's CSP to allow inline script tags if userscripts are supposed to run. This now fails if the page is loaded by a caching service worker, because it's almost impossible to detect these requests via browser.webRequest.

Thanks, Jan

Hey Jan

Can you please give more details on why you can't use the native userScripts API?

We designed and implemented it to provide better performance and security compared to other ways of injecting scripts, so it would definitely be preferable if extensions like yours used it.

If you find certain features missing, or have any other feedback on why the existing API is not suitable for your extension, I'd be glad to hear it (here, or in private if you prefer).

Flags: needinfo?(jan)
Severity: -- → S4
Flags: needinfo?(perry)

(In reply to Tomislav Jovanovic :zombie from comment #4)

Hey Jan

Can you please give more details on why you can't use the native userScripts API?

We designed and implemented it to provide better performance and security compared to other ways of injecting scripts, so it would definitely be preferable if extensions like yours used it.

If you find certain features missing, or have any other feedback on why the existing API is not suitable for your extension, I'd be glad to hear it (here, or in private if you prefer).

I've created a new issue for my very special(?) problem. Let's discuss this there, because issues with caching service workers are a side-effect only.
https://bugzilla.mozilla.org/show_bug.cgi?id=1645614

Thanks.

Flags: needinfo?(jan)
QA Whiteboard: [qa-regression-triage]
You need to log in before you can comment on or make changes to this bug.