Communicate between isolated worlds (extension js and webpage js) on chrome extension

后端 未结 1 1710
半阙折子戏
半阙折子戏 2021-01-03 15:46

As you may know, js files on chrome extensions and pages cannot directly access each other and they run on isolated worlds.

However, I want to access some of the fun

相关标签:
1条回答
  • 2021-01-03 16:13

    Assuming you know the tab ID of the page whose function you want to call, you can use chrome.tabs.update(tabId, {url: 'javascript:functionNameHere()'}); from your extension page. This works because javascript: URLs are mapped to script execution in the main (i.e. page, not isolated) world.

    0 讨论(0)
提交回复
热议问题