简体   繁体   中英

Accessing custom page callbacks within chrome extension

I am trying to write a chrome extension which would add event handlers to the page. The problem is that events are not standard and are triggered by the external javascript (jquery) running on the page. Solving this with content-scripts seems not possible since they are executing in a separate environment and can only access the DOM of the page but not the JS. What other options do I have here?

Update:

Problem here is that page is not aware of the content-script or the whole extension. Example: JS in a page triggers events, say 'someCustomEvent' on document and defines handlers for that event. So when the page is loaded, inside JS console I could do this:

$(document).data('events');

and will list all those custom defined events. Doing the same in the content-script results in only those events that content-script defines.

I am looking for a way to catch all those custom events in a content-script or how to execute extension's js in the same environment with the page js.

Catching custom events isn't a problem for content scripts (if it is an actual event, not simulation). In fact custom events is a recommended way of communicating between content scripts and a page. You can check out some examples here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM