RNPF
RNPF

Reputation: 261

Chrome extension JS does not run on back button

As per here.

I am currently developing a chrome extension. This extension is fairly simple, just adding some CSS and JS through a content script:

"content_scripts": [
    {
      "matches": ["https://www.youtube.com/*"], 
      "js": ["jquery-1.12.1.min.js","ducttape.js"],
      "css" : ["orangeisthenewred.css"]
    }

And it works great! On first load. However, if the user presses back to return to the page, all the JS stalwartly refuses to run, no matter what I do. Any ideas on how to get this running on a press of the back button?

Edit: This appears to be specific to the back button itself somehow, on further experimentation.

Upvotes: 1

Views: 443

Answers (1)

Tuan Ha
Tuan Ha

Reputation: 630

You can using chrome.tabs.onUpdated event to check when users back to the previous page. And if it happens, then you can inject your content script to the page by using chrome.tabs.executeScript method and your CSS file by using chrome.tabs.insertCSS method.

Upvotes: 1

Related Questions