Search code examples
javascriptgoogle-chromegoogle-chrome-extension

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.

Manifest.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

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});

Solution

  • The "chrome_url_overrides newtab" value in your manifest is overriding the default new tab. 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. Or you could easily handle this with your own solution as well.