0

I used this snippet of code in a extension, and instead of getting the website URL, I get something like

chrome.tabs.onUpdated.addListener( function (tabId, changeInfo, tab) {
  if (changeInfo.status == 'complete') {

   alert(window.location.href)

  }
})

"chrome-extension://obajdahcbingpephpedlikkklaijpcgm/_generated_background_page.html"

Is there a way to get the URL of the actual site instead of the extension URL?

  • This is answered here: https://stackoverflow.com/questions/1979583/how-can-i-get-the-url-of-the-current-tab-from-a-google-chrome-extension – Jan Cizmar Oct 27 '20 at 01:35

1 Answers1

0

in chrome extensions there are 2 kind of scripts ( background and injectable) this code will work only if you inject it using the background script, else you need to use this

chrome.tabs.query({active: true, lastFocusedWindow: 
true}, tabs => {
let url = tabs[0].url;
});
Zack Heisenberg
  • 499
  • 6
  • 12