javascript - Triggering a click event from content script - chrome extension -
in chrome extension's content script, click on links/buttons on webpages sites. that, use following code in content script (i embed jquery in content script):
$(css_selector).trigger("click") this works on sites.
however, on sites delta.com, match.com, , paypal.com, way of triggering click on elements not work. on delta.com, following exception thrown when attempt triggering in content script:
error: attempt made reference node in context not exist. error: notfounderror: dom exception 8 strange thing is, if open javascript consoleon delta.com, include jquery , attempt same click triggering code snippet, works.
on match.com , paypal.com, triggering not work in content script , there no error. cannot trigger "click" event through javascript console way did on delta.com.
if manually use mouse click, works fine on 3 sites. hence tried simulate using mousedown(), mouseup(), did not work either.
this seems issue because javascripts sites hijacking , ignoring events. tried read code these sites see happening there code.
does have idea happening here , how fix it?
due browser extension sand-boxing, , basic jquery functionality, cannot trigger non-jquery click event trigger or click.
you can call raw dom element click method, act if element clicked mouse. use [0] access dom element:
$(css_selector)[0].click(); although seldom need to, can trigger matching buttons using same code in each. this in each dom element quite simple:
$(css_selector).each(function(){ this.click(); });
Comments
Post a Comment