我在使用tabs.executeScript向executeScript试用这个webextension-polyfill示例时,收到一条错误消息: Uncaught(in promise)无法加载文件:"browser-polyfill.js“
这是我引用的示例代码:
browser.tabs.executeScript({file:“browser-POLFILIT.JS”});https://github.com/mozilla/webextension-polyfill
在另一个示例中,我尝试在内容脚本中使用browser-polyfill,如下所示:
"content_scripts": [{
// ...
"js": [
"browser-polyfill.js",
"content.js"
]
}]我收到错误消息:无法为内容脚本加载javascript“browser-polyfill.js.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>我做错了什么?
发布于 2019-02-23 07:16:35
从同一教程中找到了一个令人满意的解决方案。
var browser = require("webextension-polyfill");这对我来说很有效!
https://stackoverflow.com/questions/54719661
复制相似问题