Skip to content

Instantly share code, notes, and snippets.

@javiersantos
Last active August 21, 2022 12:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javiersantos/c3e9ae2adba72e898f99 to your computer and use it in GitHub Desktop.
Save javiersantos/c3e9ae2adba72e898f99 to your computer and use it in GitHub Desktop.
Get the current URL of the selected Chrome tab. Useful for Chrome/Chromium extensions.
/*
* Get the current URL of the selected Chrome tab. Call to getCurrent
* By Javier Santos
* https://gist.github.com/javiersantos/c3e9ae2adba72e898f99
*/
var currentURL;
chrome.tabs.query({'active': true, 'windowId': chrome.windows.WINDOW_ID_CURRENT},
function(tabs){
getCurrentURL(tabs[0].url);
});
function getCurrentURL(tab){
currentURL = tab;
}
@abhayram04
Copy link

Its not working. This is not for the background.js right?

@httpshhnik
Copy link

It works just sometime. For example it does not work for zendesk.

@pguardiario
Copy link

Add "tabs" permission to the manifest

@JTorresConsulta
Copy link

Does not work in v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment