0

I have a problem with well known chrome extension issue - 'Uncaught Error: Extension context invalidated.'. Of course I saw the post 'Chrome extension content script re-injection after upgrade or install'. I'm trying to implement the solution but with some problems with onDisconnect part:

port = chrome.runtime.connect();
port.onDisconnect.addListener(reconnectToExtension);

The problem is that onDisconnect is triggered not only when user, for example, reload extension (from extension dashboard), but also when he reloads the tab with f5. I can't, for example, use window.location.reload when extension is disconnected to clean content_script DOM, because each reloads the tab will execute onDisconnect again. Is it a proper behavior?

Btw all 'solution' context_script code is working like infinite loop connectToExtension -> reconnectToExtension.

Unfortunately, I can't show the code. The code based on angular (background part) and typical js (content script part).

Przemo
  • 477
  • 1
  • 7
  • 16
  • See [Chrome extension: How to remove orphaned script after chrom extension update](https://stackoverflow.com/a/57471345) – wOxxOm Sep 24 '20 at 11:41
  • Note that content scripts run in the web page as an additional JavaScript environment (isolated) so reloading or navigating the page will terminate all its scripts and content scripts as well. – wOxxOm Sep 24 '20 at 11:44

0 Answers0