0

I have an extension that will work only on a given url and I'm using the declarativeContent api to achieve this. When the extension icon is clicked a new popup window that will hold the popup.html will be opened.

I need a way to get the url of the tab that have opened the popup from the popup.js file, I've with chrome.tabs.query but I will get always undefined. Is there a better way?

      chrome.tabs.query({ 
        active: true, 
        lastFocusedWindow: true, 
        url: 'https://example.com/*' }, (tab) =>{
        console.log(tab) // undefined
      })

miko
  • 109
  • 2
  • 9
  • I don't believe you can get that value. See reference [here](https://stackoverflow.com/a/6553378/3838600). – ermalsh Sep 15 '20 at 17:17
  • Simply remove `url: 'https://example.com/*'` and open the correct devtools: the popup is a separate window so it has its own devtools. Right-click inside the popup, then click "inspect". – wOxxOm Sep 15 '20 at 17:25
  • @wOxxOm I already inspect the correct devtool, the problem is that by removing the url I will get all the tabs active and I need only the tab url who enable the extension, not all the tabs – miko Sep 15 '20 at 17:55
  • @MadeInAlb this is not what I'm looking for, I'm developing a chrome extension and it's having is own api to achive my scope – miko Sep 15 '20 at 17:56
  • @miko, no, there is only one active tab in a window. Active means currently focused tab. P.S. `tab` is actually always an array, even if empty, it can never be `undefined`, so your description is either misleading or there's a bug in Chrome. – wOxxOm Sep 15 '20 at 18:53
  • for undefined I was refering to the array that will be empty. Anyway, the problem is that I will get as active tabs the popup window opened by the extension and the tab that have the interested url. – miko Sep 16 '20 at 08:46

0 Answers0