0

I am trying to find the active tabs across all windows, actual query and action is more detailed but this demonstrates the basic problem

chrome.tabs.query({active: true}, function (tabs) { console.log(tabs); });

It seems that with Chrome and Firefox we can use that api with either activeTab or tab permission, only limitations on the search items such as url. The chrome.tabs or browser.tabs docs only seem to indicate tab permission for some parts.

When using only activeTab permission MS Edge throws error, Chrome gives the result Adding tabs permission and I can get the results in MS Edge

Is this a deliberate difference, or a bug, or doing something else incorrect? Trying to ask for minimal permissions as Mozilla and Google required validation of usage with permissions with wide access.

similar to, but not the same as Why browser.tabs.query is not working in Edge Extension ?

Greg Domjan
  • 13,943
  • 6
  • 43
  • 59
  • Which error are you meeting, can you post the detailed error message? Also, you could create a sample to reproduce the problem. From the [official document](https://learn.microsoft.com/en-us/microsoft-edge/extensions-chromium/getting-started/part2-content-scripts#updated-strategy-to-display-image-at-the-top-of-the-browser-tab), it seems that we could find the active tab using this script `chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {}`. – Zhi Lv Jun 08 '20 at 09:02
  • @ZhiLv-MSFT Colour me confused, I just tried to get the error again for you, removing tab permission reloading and even restarting and didn't get the error any more, instead I'm getting the expected result. On either of Version 83 or Version 85.0.531.1 also tested across 2 hosts including where we first had the issue. No idea what is going on here, but it seems to be on our end I guess. – Greg Domjan Jun 09 '20 at 10:00

1 Answers1

0

first of all, you have to add 'tabs' permission to your manifest file like this

"permissions": [
    "tabs"
]

and next use this code

  let queryOptions = {
        active: true,
        currentWindow: true
    };

  chrome.tabs.query(queryOptions,function (tabs){
    alert(tabs[0].url)
    });

after that just remove the old extension and load new files in your extensions then observe the permission section in extension details it's should be changed and check it out.

Vali.Pay
  • 364
  • 1
  • 4
  • 16