d9120
d9120

Reputation: 511

Chrome extension content script issues when extension is disabled

When I disable the extension that I am developing, the content that I injected remains on the page (and things get messy since the JavaScript is no longer hiding the content). Is there a way that I can recognize the event and reload the page when it is disabled?

Upvotes: 0

Views: 209

Answers (2)

Zig Mandel
Zig Mandel

Reputation: 19864

Yes its possible to detect the situation, thou i think its fine if the user needs to refresh manually uppon uninstall/disable. One way is to regularly message your extension from the injected script to check if its still alive. I do this for an extension of mine to detect when chrome updated it, which has similar consequences as the old version of the background script goes away without notice and the content script is left orphan.

Upvotes: 2

Devlin
Devlin

Reputation: 21

Unfortunately, I don't think there is - somewhat by design. Extensions are intended to run on top of web pages, and the web page shouldn't typically modify its behavior for extensions. This abstraction, though, results in web pages being unaware of an extension's running state.

If you are the one disabling the extension, you could make a "clean up" method which refreshes all pages on which the extension is running, but you'd have to manually trigger that prior to disabling it.

Upvotes: 0

Related Questions