Get current URL with Chrome extension

I'm trying to write a Chrome extension that will display the URL of the page the user is on and send it to the server for a response.

So far I have tried to use chrome.tabs.getCurrent(), but I get uncaught TypeError in the getCurrent object.

Is there an easy way to do this?

+3
source share
3 answers

You get an error because getCurrent returns the script tab, not the selected tab.

You should probably use getSelected as indicated by serg

0
source

Any reason you don't want to use getSelected()?

chrome.tabs.getSelected(windowId, function(tab) {
    alert("current:"+tab.url);
});
+3
source

getSelected . :

    chrome.tabs.query({active: true}, function(tab) {
        // Do stuff here
    }
+1

Source: https://habr.com/ru/post/1758514/


All Articles