Triggering a click event from content script - chrome extension

后端 未结 3 900
小蘑菇
小蘑菇 2020-12-14 23:49

In my chrome extension\'s content script, I click on certain links/buttons on webpages from certain sites. To do that, I use following code in the content script (I embed jQ

3条回答
  •  星月不相逢
    2020-12-15 00:08

    content_script is sandboxed executed,see https://developer.chrome.com/extensions/content_scripts

    However, content scripts have some limitations. They cannot:

    • Use variables or functions defined by their extension's pages
    • Use variables or functions defined by web pages or by other content scripts

    $ in the content_script can't access $ on the webpage,but the events data stored inner $,so we could not trigger.

    // taken from jQuery#1.11.2 from line4571, trigger method
    ...
    
    // jQuery handler
    handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" );
    if ( handle ) {
        handle.apply( cur, data );
    }
    
    // Native handler
    handle = ontype && cur[ ontype ];
    

提交回复
热议问题