I have created a chrome extension with a popup window. This popup window communicates with the content script (and visa versa). I do this with chrome.runtime.sendMessage.
Here is a snippet of my manifest file:
"background": {
"scripts": ["background.js"]
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"run_at": "document_start",
"js": ["content.js"]
}
],
This works fine, but there are situations when this doesn't work. For example:
- open a tab / page
- then if the page is loaded install the extension
Because the page was already loaded before the extension was installed, the content script was not injected. In this situation my extension does not work. After you reload the page everything works fine again.
But there might be another situation in which case an extension will break (but I'm not 100% sure)
1) open a tab /page
2) wait for an update of the extension
In this situation the content script was already injected before chrome updated the extension, so they are now of different versions and the extension might not work.
Although I'm not sure that the second situation will ever occur (I don't know how/when chrome updates extension), but the first one certainly does. How can we prevent this from happening and can the extension fix this?