Last active
August 21, 2022 12:34
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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; | |
} |
It works just sometime. For example it does not work for zendesk.
chrome.tabs.getCurrent(tab => tab.url)
https://developer.chrome.com/docs/extensions/reference/tabs/#method-getCurrent
https://developer.chrome.com/docs/extensions/reference/tabs/#type-Tab
Add "tabs" permission to the manifest
Does not work in v3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Its not working. This is not for the background.js right?