user298519
user298519

Reputation: 1190

Making a chrome extension that replaces default tab, button to navigate to default Chrome tab not working

Since I'm replacing the default Chrome tab, I want to give the option for the user to go on a default Chrome tab instead. This is what I have in my html file...

<a href="chrome-search://local-ntp/local-ntp.html?dev=false" id="default-tab-text">Default tab</a>

This is my manifest.json

{
  "manifest_version": 2,

  "name": "Positab",
  "description": "This extension delivers positivity with every new tab.",
  "version": "1.0",

  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  },

  "chrome_url_overrides": {
    "newtab": "popup.html"
  },

  "permissions": [
    "activeTab",
    "tabs"
  ]
}

I'm getting this error:

Not allowed to load local resource: chrome-search://local-ntp/local-ntp.html?dev=false

How do I fix this?

Upvotes: 0

Views: 449

Answers (1)

acesmndr
acesmndr

Reputation: 8505

You can't redirect to that page in that way because it's not a proper location for link property to work thus it results in searching for that location in the extension itself resulting in that error. However you can add onclick handler to the link and update the current tab with the chrome.tabs.update method.

document.getElementById("default-tab-text").addEventListener("click", function(event){
    chrome.tabs.getCurrent(function(tab){
      chrome.tabs.update(tab.id, {
        url: "chrome-search://local-ntp/local-ntp.html?dev=false"
      });
    });
 });

Upvotes: 2

Related Questions