4

My Extension's content script interacts with every open tab.

When I update my Extension any existing tabs will have the old content script and my Extension will not function.

I have tried putting an alert on the page asking users to refresh (triggered by catching an error), which is confusing to users. This answer (chrome extension API for refreshing the page) shows how to refresh all open tabs...and if placed in background.js in the onInstalled listener (reason === "update") we can force all open tabs to refresh. But this feels invasive and alarming to the user.

What is the best practice?

11teenth
  • 1,853
  • 1
  • 15
  • 28
  • See [Chrome extension content script re-injection after upgrade or install](//stackoverflow.com/q/10994324) – wOxxOm Aug 22 '18 at 15:14
  • Thank you so very much @wOxxOm. I dug into that link and found Google Group discussions...nothing very satisfactory. I tried injecting (re-injecting) my content script, but the old one seemed to still be there (throwing errors) and also my jQuery stuff, which runs fine when content script is added by manifest, throw errors ("$ is not defined"). Seems like a really large gap and negative experience for users when an EXT is updated... – 11teenth Aug 22 '18 at 21:07
  • See https://groups.google.com/a/chromium.org/forum/?utm_medium=email&utm_source=footer#!msg/chromium-extensions/QLC4gNlYjbA/5hz5lEswDwAJ for an old discussion...that doesn't seem to have gone anywhere. – 11teenth Aug 22 '18 at 21:26
  • You can simply unregister the old listeners, see [Stylus](https://github.com/openstyles/stylus/blob/master/content/install-hook-usercss.js) (orphanCheck function). As for jQuery, I think you need to inject all content scripts. – wOxxOm Aug 23 '18 at 04:10
  • You are awesome. I had forgotten that I was injecting jQuery...or wasn't even that aware of what I was doing months ago when I added that line to my manifest. Many thanks for your help. – 11teenth Aug 23 '18 at 16:36

0 Answers0