N
N
nt mk2020-07-24 21:37:36
JavaScript
nt mk, 2020-07-24 21:37:36

Optimal solution to restart content script after changing url?

There is dynamic content in one tab, the google chrome extension does what it needs on the first run, when I go to another tab and return, the added elements disappear, which is obvious.
The content script fires when I reload the page, F5 .

I read that you can track URL changes in background.js
. when i switch tabs it changes tab=0, tab=1, tab=2 in url etc. The page itself does not reload when switching tabs.

So here's how to restart contentScript.js when you return to the tab.

I dug up a cloud of solutions, a lot of errors. It is not possible to debug the extension, the site is not mine.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nt mk, 2020-07-24
@neeremeevan

chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
    if (info.url === myReloadURL) {
        chrome.tabs.remove(tabId);
        chrome.runtime.reload();
    }
});

It's not bad either, just reboots the wrong thing.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question