I'll try to explain as briefly as possible.
I developed a Chrome extension and I have problems with some of the functionalities.
The problem I'm having is I need to trigger some events on the website the extension has access to but some scripts that work on the console, don't work the same way if executed from my content js of the Chrome extension (even if I use my own version of jQuery that I can add to my extension if needed).
Example:
If I execute window.$
or jQuery on the console it returns ƒ (a,b){return new n.fn.init(a,b)}
. If I run that on my script, even if I wait until everything is loaded, even if I set a wait of 10 seconds before checking to make sure everything is loaded, it tells me that "$ is undefined" when I don't have jQuery on my Chrome extension.
Also, console.log(window.$.fn)
executed from the console returns Object [jquery: "1.12.4", selector: "", constructor: ƒ, toArray: ƒ, get: ƒ, …]
but if I run that from my content script having jQuery activated returns Object [jquery: "3.5.0", constructor: ƒ, toArray: ƒ, get: ƒ, pushStack: ƒ, …]
since I have that version installed on the extension.
I need to do this (which works from the console but not from the content script of the extension):
$("#id").val(123).val());
$("#id").trigger('keyup');
I've also tried the native .dispatchEvent()
way of doing this but nothing happens, it returns true
when executed but nothing happens.
That's why I'm asking: Is there a way to access the page's jQuery instance from an external file (in this case my content.js
script of the chrome extension)?
I can change the DOM but that's not enough, even if I change the value of the inputs of the form for some reason the page doesn't recognize the change. The only working way I've found is triggering manually the keyup
event after changing the value with jQuery, but only works if I do it from the console.
Any clue?