'Chrome extension - Query tabs belongs to my extension without using the "tabs" permission [duplicate]

If I wanted to query all the open tabs which belongs to my extension, I can do it like this:

chrome.tabs.query({
    url: 'chrome-extension://' + chrome.runtime.id + '/*',
}, function (tabs) {
    //do something here with the tabs...
});

But, this needs me to add in the manifest.json the tabs permission, which is a broad permission I don't want to use!

I thought about the chrome.extension.getViews() method:

let tabs = chrome.extension.getViews({
    type: 'tab'
});
console.log('tabs:', tabs);

But, this returns an array of the JavaScript 'window' objects, it doesn't have the browser tab IDs.

So, I can't make use of it in scenarios where I need the tab id, for instance:

chrome.tabs.update(tabId);

Is there a way I can get the open tabs belongs to my extension without using the tabs permission?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source