我正在构建一个 Chrome 扩展,它使用针对特定 Web 域定制的 JavaScript 库。这是对该库的限制,只能从该特定域调用(实际上是许可证问题)。
我想将该 js 库加载到我的 Chrome 扩展中,但该扩展给出了内容安全策略错误,因为要使用的库来自 HTTP(不是 HTTPS)URL。我在 StackOverflow 中搜索了此内容,我看到的唯一选项是本地加载该文件或通过消息传递加载该文件。
有人可以告诉我在 my 中应该有什么代码background.js以及content.js在 my 中添加什么权限吗manifest.json?
获取该 js 库的网站是,例如http://library.com/js/xy.js。我知道应该还有其他东西,比如 content.js 中的一些代码。如何从该域加载代码?
清单.json:
{
"manifest_version": 2,
"name": "abc",
"version": "0.2",
"description": "abc",
"content_security_policy": "script-src 'self'; object-src 'self'",
"browser_action": {
"default_icon": "MM_logo_2009.png",
"default_popup": "tab/popup.html"
},
"background": {
"scripts": ["event.js"],
"persistent": false
},
"permissions": [
"http://library.com/js/xy.js",
"bookmarks",
"tabs",
"storage",
"http://*/*",
"https://*/*"
]
}
Run Code Online (Sandbox Code Playgroud)
事件.js:
var xhr = new XMLHttpRequest();
xhr.open("GET", …Run Code Online (Sandbox Code Playgroud) html javascript xmlhttprequest message-passing google-chrome-extension