Display global page object from contentscript to popup in chrome extension

 ̄綄美尐妖づ 提交于 2019-12-23 23:12:11

问题


I have an object WIO on a webpage which i want to access in my chrome extension. I have followed this example and injected my script.js in the page using first method.

I can successfully read WIO object in script.js. But the problem is i can't access it in popup.html.

Any suggestions will be great appreciated.

Here is manifest.json

{
  "manifest_version": 2,
  "name": "Campaign Analyzer",
  "description": "Analyze campaign data",
  "version": "0.1",
  "icons": { "128": "icon_128.png" },
  "browser_action": {
    "default_popup": "popup.html"
  },
  "permissions": ["activeTab", "<all_urls>"],
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["jquery-3.4.1.min.js", "inject.js"]
    }
  ],
  "web_accessible_resources": ["script.js"]
}

inject.js

s.src = chrome.runtime.getURL("script.js");
s.onload = function() {
  this.remove();
};
(document.head || document.documentElement).appendChild(s);

script.js

setTimeout(function() {
  console.log(WIO.sessionInfo.context);
}, 6000);

来源:https://stackoverflow.com/questions/59392943/display-global-page-object-from-contentscript-to-popup-in-chrome-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!