After extensive searching I discovered Rob's answer: that "webstore cannot be scripted by extensions".

I only want to extract the URL and pass it to the extension. Is there no way to achieve this? Could I query all opened tabs from background script, and keep the active tab URL in a variable accessible to extension?

1 Answers

miyagisan On

I ended up implementing background script that saves currently active tab URL in a variable that I access from within a popup.js because webstore doesn't allow us to run content scripts there. chrome.extension.getBackgroundPage() inside popup.js only worked when I used var currentUrl.

var currentUrl;
var activeTabId;

    function (tabId, changeInfo, tab) {
        if (changeInfo.status === "complete") {
            chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
                let activeTab = tabs[0];
                currentUrl = activeTab.url;
                activeTabId =;
                if(currentUrl.includes("")) {
                } else {
                console.log("page loaded: ", currentUrl);

chrome.tabs.onActivated.addListener(function (object) {
        activeTabId = object.tabId;
        chrome.tabs.get(activeTabId, function(tab){
            currentUrl = tab.url;
            if(tab.url.includes("")) {
            } else {
            console.log("loaded tab selected: ", tab.url);