gpt4 book ai didi

javascript - Chrome 打包应用程序 : Open Website in New Tab

转载 作者:行者123 更新时间:2023-12-02 14:46:53 36 4
gpt4 key购买 nike

我正在更新我的一个 Chrome 应用程序以仅启动 Web 应用程序(为什么?我没有时间继续更新 Chrome 应用程序,单独更新桌面应用程序以供离线使用)

这是 list 的开头...

"app": {
"background": {
"scripts": [ "background.js" ]
}
},

我只是希望它现在打开网站的新选项卡,而不是启动打包的应用程序。所以我尝试了以下...

"app": {
"launch": {
"web_url": "http://stackoverflow.com/"
}
},

发生错误:无法处理您的项目。

请在 list 中指定应用程序部分的背景小节。

"app": {
"launch": {
"web_url": "http://stackoverflow.com/"
},
"background": {
"scripts": [ "background.js" ]
}
},

发生错误:无法处理您的项目。

打包应用程序和托管应用程序的应用程序规范不兼容。请参阅舱单规范。 list 不能在应用程序对象内包含启动对象。

因此,我决定坚持使用后台脚本,并尝试以这种方式创建一个新选项卡。

背景.js

chrome.app.runtime.onLaunched.addListener(function(launchData) {
chrome.app.window.create(
'index.html',
{
id: 'mainWindow',
innerBounds: {
'width': 800,
'height': 600
}
}
);
});

index.html

<script>
var a = document.createElement("a")
a.href = "http://stackoverflow.com/"
a.target = "_blank"
document.body.appendChild(a)
a.click()
</script>

我终于能够成功添加一个新选项卡...

chrome.app.runtime.onLaunched.addListener(function(launchData) {
window.open("http://stackoverflow.com/")
})

在我的background.js脚本中。

但是出现以下错误...

enter image description here

我点击了"Learn More"按钮,但这也给了我同样的“噢,啪!”页面

有谁知道为什么我无法在 Chrome 打包应用程序中打开新选项卡?

我该如何在 Chrome 打包应用程序中打开新选项卡?

最佳答案

使用 chrome.browser.openTab({ url: ""}, callback)"browser" 权限。

https://developer.chrome.com/apps/browser#method-openTab

关于javascript - Chrome 打包应用程序 : Open Website in New Tab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36526684/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com