小编Ell*_*qen的帖子

扩展无法访问窗口对象中的自定义函数

当 Chrome 扩展程序尝试通过 chrome.executeScript 在 window 对象中获取自定义函数时,它什么也得不到。

例如:

标签 ID:150

标签js:

window.customfunc = function(){return 'yeap';}
Run Code Online (Sandbox Code Playgroud)

扩展的后台JS:

chrome.tabs.executeScript(150, { code: "console.log(window);" })
Run Code Online (Sandbox Code Playgroud)

清单.json:

{
   "background": {
      "scripts": [ "background.js" ]
   },
   "content_scripts": [ {
      "exclude_globs": [  ],
      "exclude_matches": [  ],
      "include_globs": [ "*://*/*" ],
      "js": [ "script.js" ],
      "matches": [ "http://*/*" ],
      "run_at": "document_idle"
   } ],
   "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
   "description": "Test",
   "manifest_version": 2,
   "name": "Workspace",
   "permissions": [ "unlimitedStorage", "notifications", "clipboardWrite", "notifications", "clipboardRead", "management", "tabs", "history", "cookies", "idle", "storage", …
Run Code Online (Sandbox Code Playgroud)

javascript google-chrome google-chrome-extension

3
推荐指数
1
解决办法
2172
查看次数