Creating a tab from inside a devtools extension returns successfully with a tab id of -1

51 Views Asked by At

I'm working on a devtools extension. Inside the JS code of a devtools panel I'm trying to create a tab; the tabs.create function returns successfully but the new tab id is -1 and, of course, no new tab is created.

This is my permissions member in manifest v3:

"permissions": ["storage", "declarativeNetRequest", "tabs"]

Here's my code:

chrome.tabs.create({ url: 'https://google.com' }, function(tab) {
    if (tab) {
        // This code runs. Tab should be created and tab.id 
        // should be a positive integer but instead -1 is shown on the console.
        console.log('Created tab with ID: ' + tab.id);
    } else {
        console.error('Failed to create tab');
    }
  });

I've tried running the same code on the extension's service worker file, with exactly the same results.

Any help will be much appreciated, thanks!

0

There are 0 best solutions below