[英]How can i open the new tab with chrome extension?
I made a new tab with manifest v3, but the problem is that when I run the extension it opens a new tab, but when I press +(open new tab) it opens this tab, but I don't want to open a new tab with this url, I want to open the default google tab.我用清单 v3 创建了一个新选项卡,但问题是当我运行扩展时它会打开一个新选项卡,但是当我按 +(打开新选项卡)时它会打开此选项卡,但我不想打开一个新选项卡这个 url 标签,我想打开默认的谷歌标签。
Manifest.json清单.json
{
"name": "NAME",
"description": "newName",
"version": "1.0.1.0",
"manifest_version": 3,
"chrome_url_overrides": {
"newtab": "index.html"
},
"background": {
"service_worker": "./background.js"
},
"content_scripts": [
{
"js": [
"script.js"
],
"css": [
"style.css"
]
}
],
"permissions": [
"scripting",
"activeTab",
"tabs"
]
}
background.js背景.js
chrome.runtime.onMessage.addListener((msg, sender, response)=>{
if (msg.name === "message") {
//Send response
response({text: "This isaresponse..."});
}
});
chrome.tabs.create({url: './index.html', selected: true, active: true});
Have you tried not passing any url as it's an optional param and will default to the New Tab Page?您是否尝试过不传递任何 url 因为它是一个可选参数并且默认为新标签页?
See docs fro create method :请参阅创建方法的文档:
The URL to initially navigate the tab to.
最初将选项卡导航到的 URL。 Fully-qualified URLs must include a scheme (ie, 'http://www.google.com', not 'www.google.com').
完全限定的 URL 必须包含方案(即“http://www.google.com”,而不是“www.google.com”)。 Relative URLs are relative to the current page within the extension.
相对 URL 是相对于扩展中的当前页面的。 Defaults to the New Tab Page.
默认为新标签页。
The "chrome_url_overrides newtab" value in your manifest is overriding the default new tab.清单中的“chrome_url_overrides newtab”值覆盖了默认的新标签。 Remove that from your manifest.
从您的清单中删除它。 If you want to show a page with instructions once before using the extension use the "chrome.runtime.onInstalled" event listener to open a page on installation.
如果您想在使用扩展程序之前显示一次带有说明的页面,请使用“chrome.runtime.onInstalled”事件侦听器打开安装页面。 Or you could easily handle this with your own solution as well.
或者您也可以使用自己的解决方案轻松处理此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.