jquery works in the console while not when saved and run on page load.
there is security limit in greasemonkey 4 so you cannot access variable but only the element in the document.As solution,you can @require
a jquery on the script head so it can use jquery of itself instead of document's variable,or stringify the script and inject it into the document so it can use anything in the document.In another way just use Tampermonkey or Violentmonkey instead of greasemonkey 4 and the code will work without change
Thanks. This is the first time I've posted here. Is there something to click or mark that indicates this post was helpful or solved my issue?
jquery works in the console while not when saved and run on page load.
I am running a greasemonkey javascript. jquery works fine when I copy and paste into the console. jquery does not work when I use greasemonkey to run the javascript when the page loads. I am using jquery, $(). jquery is coming back as unfound. I tried to define $, but didn't help. See comment in code. I trimmed the js down. I'm runnning with this page: https://discussions.apple.com/thread/250050666
macos 10.10.5 waterfox 56.2.6 a clone of Firefox. Supports legacy Firefox plugins. greasemonkey 3.17
my script: It delays for 10 seconds. Tries three different query commands. For some reason, $("body"); is not being found. While document.querySelector("body"); and document.querySelectorAll("body"); are being found. I defined $() as shown in a comment, but this didn't change the result. If I copy and run the script from the console $() works.
How do I get jquery to work?
the results.
` ==++> setup. Mon Dec 31 2018 18:48:17 GMT-0500 (EST)
adding locationChangeButton event listner
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
https://www.apple.com/search-services/suggestions/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). (unknown)
Use of Mutation Events is deprecated. Use MutationObserver instead. index.js:8:30800
======> Lets begin. delay completed <======
---> locationChangeButtonHandler is observed.
document.readyState is complete
Trying querySelectorAll
using querySelectorAll
Trying jquery
No jquery. Error is** "$ is not defined" **
Trying querySelector
using querySelector
In stopWatchDogButton 5
watchdog is inactive : 5
end of locationChangeButtonHandler
stopping. watchdog1 is 5
In stopWatchDogButton 5
watchdog is inactive : 5`
`
`