Extensão do Chrome Obtenha URL da guia atual
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
console.log(tabs[0].url);
});
flexflower
chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
console.log(tabs[0].url);
});
chrome.tabs.query({active: true, lastFocusedWindow: true}, tabs => {
let url = tabs[0].url;
// use `url` here inside the callback because it's asynchronous!
});
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
// {active: true, currentWindow: true}: current tab of the active window
// tabs parameter is an array holding objects providing access to url
const activeTab = tabs[0];
const activeTabId = activeTab.id;
const activeTabURL = activeTab.url;
// do whatever you want with the above values
});
// the following should be added to manifest.json for chrome extension
"permissions": [
"tabs"
]