How to open a new tab from a Firefox WebExtension as if the user clicked + to open a new tab
Asked Answered
S

1

6

I've tried the following:

chrome.browserAction.onClicked.addListener(function(tab) 
{ 
    chrome.tabs.create({
        url: "about:newtab"
    });         
});

Unfortunately, I can not open the new tab page about:newtab with tabs.create(). It throws a security error:

Security Error: Content at moz-extension://5cdd4429-f725-49c4-bdc1-547e1acc085b/ may not load or link to about:newtab.

How am I suppose to open about:newtab from a Firefox WebExtension?

Shorthand answered 9/5, 2016 at 18:58 Comment(7)
That's interesting, it seems like it should work. Did you try a url other then about:newtab? You might need to request permissions in the manifest.jsonDialectic
Thanks. Permission is "http://*/*", "https://*/*"Shorthand
I added <all_url> but it does not allow about:newtab and chrome://. Only about:blank is allowed. Google Chrome is less strict about this. Any advice?Shorthand
Try passing in to url parameter, it will probably open about:newtab. I'll ask some webext folk what perms you'll need for chrome://.Dialectic
Thanks Noitidart but I did not understand what is "try passing in to url parameter". Can you post a code?Shorthand
Oh typo, whoops, I mean this: chrome.tabs.create();Dialectic
Thanks mate but create does not work without passing a parameter.Shorthand
T
3

about:newtab is considered a privileged about page. You can not explicitly open it using tabs.create(). However, you can open a tab to display the default page for a new tab. Normally this default page will be about:newtab.

To open the default page for a new tab, you can pass an object to tabs.create() that does not contain a url property.

For example, to open a new tab in the current window at the index which would be used if the user clicked on the + icon to open a new tab, you could use the following:

chrome.tabs.create({});

To open a new tab at index=1 in the current window, you could do:

chrome.tabs.create({index: 1});

By default, the page that you will open is about:newtab. However, the user may have installed another extension that changes the page used for a new tab. If so, that page will be used.

Truffle answered 2/8, 2016 at 6:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.