uazo / bromite-buildtools

my build machine for bromite development
GNU General Public License v3.0
331 stars 10 forks source link

[UserScripts] Script is running too early #220

Closed w4tchdoge closed 1 year ago

w4tchdoge commented 1 year ago

I have a userscript that uses jQuery which runs on a page that I know to have jQuery loaded, however the script does not work. When I use chrome://inspect/#devices and USB debugging to view the console of the webpage I have loaded on the bromite-buildtools app on my Android device I see the following error:

image

and when I look in the sources tab, I see that the line is highlighted with an error:

image

However, when I run typeof jQuery in the console it returns 'function' as opposed to the 'undefined' that it would return if jQuery was not present, and when I run jQuery.fn.jquery to get the version number it returns '1.9.0' which I know to be the version that the webpage loads.

I have checked to make sure that the webpage on my Android devices loads jQuery by using the aforementioned chrome://inspect/#devices, inspecting the webpage, and checking the network tab (IMG).I have attempted to remedy this by including // @run-at document-idle in the userscript metadata block but to no avail.

I would like to know whether this is a bug, a limitation of this fork of chromium, or me doing something incorrectly that is causing the userscript to not function. Any help or information that you can provide is much appreciated.

uazo commented 1 year ago

if you publish the contents of your userscript I can check

w4tchdoge commented 1 year ago

if you publish the contents of your userscript I can check

I have published the userscript I had attempted to use on my device to a Gist. If you wish to see the original unmodified userscript it is available on Greasy Fork, which is where I had initially found it.

uazo commented 1 year ago

checked and the error is corrected. userscripts in bromite are isolated from the page context: window.jQuery (and $()) are defined in the context of the page, but not of the userscript. you must find an alternative method that does not use resources allocated by the main page (try with 'document-end') or include jquery in your userscript