L
L
Leks K2018-08-06 22:01:00
JavaScript
Leks K, 2018-08-06 22:01:00

How to get new open tab link for extension in Google Chrome?

There is an extension for Google Chrome. it contains a script that is executed when a button is pressed in the installed extension in the browser. The script gets the current link of the page where the extension is running and prints the link to the console.

document.addEventListener('DOMContentLoaded', function() {
    var checkPageButton = document.getElementById('checkPage');
    checkPageButton.addEventListener('click', function() { 
    chrome.tabs.query({active:true},function(tabsArray) {
        var tab = tabsArray[0];
        var tabUrl = tab.url;
 console.log(tabUrl); 
});
    }, false);
}, false);

How to make the extension display the url of the new open tab in the browser and without pressing the button, but in the background?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question