无法加载文件:“ browser-polyfill.js”

时间:2019-02-16 03:34:49

标签: google-chrome-extension firefox-webextensions webextension-polyfill

我正在尝试使用webstension-polyfill示例使用tabs.executeScript执行脚本,但收到错误消息: 未捕获(已承诺)无法加载文件:“ browser-polyfill.js”

这是我指的示例代码:
browser.tabs.executeScript({file:“ browser-polyfill.js”}); https://github.com/mozilla/webextension-polyfill

在其他示例中,我尝试在内容脚本中使用browser-polyfill,也是如此:

"content_scripts": [{
// ...
"js": [
  "browser-polyfill.js",
  "content.js"
]
}]

我收到错误消息:无法为内容脚本加载javascript“ browser-polyfill.js”。无法加载清单

尽管它在后台脚本中也可以在弹出HTML中使用。

这是我的清单文件

{
  "name": "Dummy",
  "author": "UI Team at Dummy",
  "version": "1.0.0",
  "manifest_version": 2,
  "description": "Vera browser extension",
  "permissions": [
    "storage",
    "webRequest",
    "tabs",
    "webRequestBlocking",
    "storage",
    "*://*/*",
    "declarativeContent"
  ],
  "browser_action": {
    "default_popup": "popup.html",
    "default_icon": {
      "16": "images/extension_icon16.png",
      "32": "images/extension_icon32.png"
    }
  },
  "background": {
    "scripts": ["background-proprietary.js", "background.js"]
  },
  "content_scripts": [

    {
      "matches": ["https://*.box.com/*"],
      "js": ["content-script-box.js"],
      "all_frames": true
    },
    {
      "matches": ["https://*/*"],
      "include_globs": ["*DummyExtensionFlow=1*"],
      "js": ["browser-polyfill.js","config-sharepoint.js"],
      "all_frames": true
    }
  ],
  "icons": {
    "16": "images/extension_icon16.png",
    "32": "images/extension_icon32.png",
    "48": "images/extension_icon48.png",
    "128": "images/extension_icon128.png"
  },
  "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}

这是我的弹出html文件,该文件正在使用webextension polyfill

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link rel="stylesheet" href="./popup.css">
  <title>Document</title>
</head>
<body>
  <div id="root"></div>
  <script type="application/javascript" src="browser-polyfill.js"></script>
  <script type="text/javascript" src="./popup.js"></script>
</body>
</html>

我在做什么错了?

1 个答案:

答案 0 :(得分:0)

在同一教程中找到了令人满意的解决方案。

var browser = require("webextension-polyfill");

这对我有用!