我在我的chrome扩展项目中包含了Jabra javascript库。
https://github.com/gnaudio/jabra-browser-integration/blob/master/README.md
该库与需要与Windows pc上安装的客户端一起安装的chrome扩展进行通信。
如果我运行任何github工具;例如https://gnaudio.github.io/jabra-browser-integration/release/test/,我可以很方便地看到事件。
如果我创建了一个小型应用程序并将其托管在Apache上,那么我可以毫无问题地访问API并查看事件。
当我在chrome扩展程序中运行该应用程序时,无法看到chrome扩展程序,并建议我安装它。
https://chrome.google.com/webstore/detail/jabra-browser-integration/okpeabepajdgiepelmhkfhkjlhhmofma
在我的chrome扩展应用程序中,我尝试从Web主机上添加javascript api库:<script src="https://example.com/jabra_research/jabra.browser.integration-2.0.js"></script>
也请参阅我的清单文件:
{
"name": "Jabra",
"manifest_version": 2,
"version": "0.3.9.2",
"author": "Joe Bloggs",
"description": "Get Jabra Headset Info",
"background": {
"page": "background.html",
"persistent": true
},
"browser_action": {
"default_icon": {
"19": "ext_icons/icon_19.png",
"38": "ext_icons/icon_38.png"
}
},
"icons": {
"16": "ext_icons/icon_16.png",
"48": "ext_icons/icon_48.png",
"128": "ext_icons/icon_128.png"
},
"options_page": "config.html",
"permissions": [
"activeTab",
"alarms",
"background",
"tabs",
"system.cpu",
"contextMenus",
"unlimitedStorage",
"storage",
"notifications",
"cookies",
"*://*/*",
"<all_urls>",
"http://*/",
"https://*/",
"management"
],
"content_security_policy": "script-src 'self' https://example.com/jabra_research/jabra.browser.integration-2.0.js; object-src 'self' https://example.com/jabra_research/jabra.browser.integration-2.0.js",
"web_accessible_resources": [
"*"
]
}
我的background.html文件包括API文件。几乎就像background.html运行时一样,它与普通的chrome浏览器选项卡不同。
有什么可以推荐的吗?
我在API的第1080行上注意到“仅在https托管下才有效”。我怀疑这与它有关。
KR, 艾登
答案 0 :(得分:0)
尝试将脚本放入扩展的本地文件夹结构(如脚本文件夹)中,以便它随工具一起提供,然后更新清单以将其作为后台脚本包括在内,以便脚本中的功能可用于后台页面和功能...
"web_accessible_resources": [
"*"
],
"background": {
"scripts": [ "scripts/jquery-3.3.1.js", "scripts/jabra.browser.integration-2.0.js"],
"persistent": true
}
}
或从内容脚本中注入脚本,将其注入到背景html页面的头部...
//load scripts, 2 shown for usage clarification...
var scripts = ["jabra_research/jabra.browser.integration-2.0.js"];
function load_latest_script() {
for (index = 0; index < scripts.length; ++index) {
var script = document.createElement('script');
//where my_url is your domain...
script.src = my_url + scripts[index]
script.type = 'text/javascript';
var done = false;
//if all scripts are loaded then load stuff
if (index == scripts.length-1) {
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
done = true;
//call a function in panel.js
load_stuff();
}
};
}
document.getElementsByTagName("head")[0].appendChild(script);
}
}
load_latest_script();