sathishkumar
sathishkumar

Reputation: 1816

click event at document level in chrome extensions

I have a page where i need to auto fill a form.But that page contains jquery slider, jquery dropdown. The submit button contains validation of the form.

But i can't access the page's jquery object. Also i tried to execute jquery and jquery ui through manifest file.but it wont change real jquery object of a page.

(Chrome exetention javascript is executing in seperate context)

Is it possible to trigger click at perticular position (eg: X : 20px, Y : 50px) of document in chrome extention.

Upvotes: 0

Views: 56

Answers (1)

gkalpak
gkalpak

Reputation: 48211

Instead of triggering a click event, I believe it better suits your purpose to access the jQuery object directly.

As you correctly mentioned, content scripts are executed in a sandboxed environment.
Still, you can access the web-pages JS context through the shared DOM. All you need to do is add a script node including the necessary code, e.g.:

var script = document.createElement("script");
script.type = "text/javascript";
script.textContent =
        "// Accessing the web-page's JS contex\n" +
        "$(\"#myElem\").doSomething();";

document.body.appendChild(script);
script.parentNode.removeChild(script);

There is, also, this very detailed answer, describing the various JS injection methods (including bonus tips and tricks).

Upvotes: 1

Related Questions