Thank you noitidart! Sorry it took so long to reply back, but I wanted to read your code, research, absorb more info and test, test, test… lol
What was your “bad” experience with onInstalled? My first concern was that I see conflicting version compatibility numbers. onInstalled states v52 support and onInstalledReason states v45 support. I am VERY concerned about browser backward compatibility (WebExtension support). I didn’t even test these. It seemed to me a waste of time…
I decided to follow your suggestion and use the storage.local method.
I am now using your isSemVer in my addon (with your copyright intact of course). Thank you very much for sharing! I did make a few changes to the code you posted though. First of all, “nub.self.version” is nonexistent. I’m guessing it is addon specific? I just replaced that with cur_version.
Secondly, using “await” in the promise makes me anxious. I see that support for await starts at v52 and Chrome v55. So, at first I changed that to using “mem_lastversion.then”. Then I found that older version of chrome didn’t like it. So I changed to using a callback function instead.
Which brings me to the difference between chrome.storage.local and browser.storage.local. As I stated, I found that FF v52 supports “chrome” and “browser”. Chrome (in my testing) does not support “browser”. So, I made the change to use chrome.storage.local instead.
Of course, I created a background script and used messaging to open the new tab with my html pages (one for install and one for update).
So… Here is what I ended up with that is backward compatible with Chrome (tested in v44), Opera (tested in v36) and works in latest FF Aurora v52.
Background js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var n="", a=request.update;
if(a=="update"){n="EnhancedUpdated.html";}
else if(a=="install"){n="EnhancedInstalled.html";}
// "Downgrade" is ignored for now.
if(n){chrome.tabs.create({url:n});}
});
Code at bottom of content script:
/*!
* isSemVer - v0.1 - 9/05/2010
* http://benalman.com/
* http://semver.org/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
var isSemVer= GET CODE FROM GITHUB IN PREVIOUS POST
var cur_version = chrome.runtime.getManifest().version;
chrome.storage.local.get("lastversion", function(res){
var n="", last=res.lastversion;
if (!last) {n="install";}
else if (last !== cur_version) {
if (isSemVer(cur_version, '>' + last)) {
n="update";
} else {n="downgrade";}
}
if(n){
chrome.runtime.sendMessage({update: n});
chrome.storage.local.set({lastversion: cur_version});
}
});
Through testing, this seems to be working perfectly…
I am still concerned about the use of “chrome” instead of “browser”. I am curious as to why FF is using “browser” instead. Will “chrome” support be dropped in favor of “browser”? Am I missing something basic here?
noitidart (or anyone else), do you see anything to be concerned about or have any comments or insight into my code strategy? Thank you once again for helping!