xhr.onreadystatechange = function() {
if(this.readyState == this.HEADERS_RECEIVED) {
chrome.tabs.create({
url: "chrome-extension://kgllckjehjabihppilipeagjojdmlfch/options.html"
});
}
我发现应该有效。我也尝试过同样的url: "options.html"
。但是当代码运行时,我得到
未捕获的类型错误:无法读取未定义的属性“创建”
在 XMLHttpRequest.xhr.onreadystatechange (myscript.js:70)
您正在尝试在内容脚本中使用 chrome.tabs.create 。此 API 仅适用于后台脚本。相反,使用 window.open 从内容脚本中创建新选项卡。
// Regular webpage; works
window.open("https://google.com");
// Privileged URL; is redirected to about:blank
window.open("chrome-extension://kgllckjehjabihppilipeagjojdmlfch/options.html");
对于选项页面,这确实not可以工作,因为它使用 chrome-extension 协议,而 Firefox 不支持使用 window.open。
这是我打开选项页面的方式背景 script:
chrome.runtime.openOptionsPage();
如果您需要在内容脚本,使用消息传递:https://developer.chrome.com/apps/messaging https://developer.chrome.com/apps/messaging
Example:
背景.js
chrome.runtime.onMessage.addListener(function(message) {
switch (message.action) {
case "openOptionsPage":
openOptionsPage();
break;
default:
break;
}
});
function openOptionsPage(){
chrome.runtime.openOptionsPage();
}
内容脚本.js
chrome.runtime.sendMessage({"action": "openOptionsPage"});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)