violentmonkey / violentmonkey

Violentmonkey provides userscripts support for browsers. It works on browsers with WebExtensions support.
https://violentmonkey.github.io/
MIT License
5.95k stars 486 forks source link

[BUG] Scripts with @run-at document-end won't run at all in Mercury browser on some pages #2232

Closed sonofevil closed 2 hours ago

sonofevil commented 3 hours ago

I just migrated from Waterfox to Mercury browser, and some of my scripts, which used to run fine in Waterfox no longer execute in Mercury. Specifically it seems to be all of scripts that are set to run at document-end. The same happens with document-idle. Scripts with document-start or document-body do seem to run, but some of my scripts don't work correctly with these options.

Sequence of actions:

  1. Install Mercury browser
  2. Install Violentmonkey in Mercury
  3. Install userscript with @run-at document-end
  4. Attempt to run userscript on a page

Problem: The userscript seemingly never runs.

Expected result: The userscript runs.

Devtools console contents: nothing related to the script or Violentmonkey

Environment:

sonofevil commented 2 hours ago

Closing for now because there are some additional troubleshooting steps I want to try.

tophf commented 2 hours ago

Works for me, but I tried it in Windows.

sonofevil commented 2 hours ago

It seems that it actually works on some pages but not others.

Example script:

// ==UserScript==
// @name        test script
// @namespace   http://github.com
// @description does nothing
// @author      sonofevil
// @include     *
// @version     1
// @grant       none
// @run-at      document-end
// ==/UserScript==

undefined;

Doesn't work on: https://www.metal-archives.com/albums/Metallica/Ride_the_Lightning/544 Works on: https://github.com/

Again, it does work on both pages in Waterfox.

(You can tell from whether the script is greyed out in the Violentmonkey drop-down menu or not.)

tophf commented 2 hours ago

Works for me on any site. Note that scripts only run when the page is created, so it won't happen on SPA sites that fake navigation by changing the URL and patching the DOM of an existing page. On those sites you can match the entire domain of the site (so it includes all possible paths) and then use MutationObserver or another API to detect changes.

tophf commented 2 hours ago

Another common problem in Firefox is that it doesn't grant site permissions to extensions by default anymore and you need to do it explicitly in about:addons or in the toolbar menu for the extension.

sonofevil commented 2 hours ago

Works for me on any site. Note that scripts only run when the page is created, so it won't happen on SPA sites that fake navigation by changing the URL and patching the DOM of an existing page. On those sites you can match the entire domain of the site (so it includes all possible paths) and then use MutationObserver or another API to detect changes.

It doesn't work even if the page is fully reloaded (ctrl+f5) so it can't be fake navigation.

Another common problem in Firefox is that it doesn't grant site permissions to extensions by default anymore and you need to do it explicitly in about:addons or in the toolbar menu for the extension.

Site permissions are fully granted.

sonofevil commented 2 hours ago

Apparently it was somehow broken due to another script missing include resources.

It wasn't missing those resources in Waterfox, hence it worked there.

tophf commented 2 hours ago

Was there a message from Violentmonkey about missing resources in console?

sonofevil commented 2 hours ago

Was there a message from Violentmonkey about missing resources in console?

No, there wasn't, strangely enough. I only found out because when I disabled and re-enabled Violentmonkey, I got a push notification about those scripts missing resources.

sonofevil commented 2 hours ago

Nevermind, I found it. These log entries only appear if there are missing required resources in the script:

Missing required resources. Please re-save or reinstall these script(s):
#14: Search Metal Archives entry on Bandcamp [index.js:1:141214](moz-extension://3d2a99db-4173-4f91-b6a1-4c98e3d1435c/background/index.js)
    Ei moz-extension://3d2a99db-4173-4f91-b6a1-4c98e3d1435c/background/index.js:1
    Li moz-extension://3d2a99db-4173-4f91-b6a1-4c98e3d1435c/background/index.js:1

Error: e is undefined

Still not sure why this breaks document-end, but if it's a bug I think it needs a new issue cos it has nothing to do with Mercury.