EventListener no longer works

Recently Chrome version 85.x started giving errors with the following code lines in Sub Main:

 window.applicationCache.removeEventListener("error", NSB.oncache, False)
 window.applicationCache.addEventListener("error", CacheErrorHandler, False)

The error reads: “Uncaught TypeError: Cannot read property ‘addEventListener’ of undefined.”

Removing the two lines of code and fixes the errors. Note this is happening in the Chrome browser running in Windows 10. When using IE, Edge or Firefox there are no errors. Testing with app Hello World.

Thanks John

applicationCache has been deprecated by Chrome (and probably by other browsers, sooner or later). It’s the old style of caching apps for offline use. It’s been replaced by PWAs, which are automatically created by AppStudio.

You should remove these lines of code.

PWA can be turned on or off in the project properties. I believe it defaults to PWA on, but you might want to check the project as it sounds like you converted it from an older version and not sure what the PWA setting may be.

PWA is On.

Since it appears you were trying to “capture” the “reload” event, may I suggest you read this post:: Modifying PWA.js code - #10 by GaryGorsline, but read the entire post from the beginning,

One other note: PWA with Start in Desktop Browser - doesn’t really work. See this post:
8.0.0.3 Start in Desktop Browser PWA issue Also, that event, depending on the connection speed can be as much as 30 seconds after app startup. 5 seconds on LTE is not unusual.

And as @ghenne will tell you: PWA is new and is not really a fully accepted standard. Apple doesn’t even say it’s supported.

Thanks for the info. The addEventListener two lines were from a long time ago, so don’t really need them now. Just found it interesting that not all browsers work the same.

Anyway, I am already using onPWAReload(). Works quite well, but is tricky to implement. When the app is started and there is an update, the onPWAReload() event is called. Usually, on a desktop this happens within a few seconds so the user doesn’t get too far into the app before this happens. But because it can take much longer on other devices, the onPWARecload will make sure data, settings, game scores, etc. that could be lost on a restart, are saved right away. A new form appears showing “Updating…” with progressive dots a lot like the manifest appcache used to show, and the the app restarts. The app also stores restart points for this forced restart, which is not absolutely necessary, to begin the app close to where it left off. I think I could prevent a restart but don’t find this necessary at this time.

I like being in control of this quite necessary updating when PWA web apps are created.

Thanks, John

John, I like your thoughts.

Since it can take up to 30 seconds (and I saw once on 3G it took 42 seconds), I took a different philosophy:

If the event doesn’t occur during the start up sequence, which is a 3 second delay for the splash screen to show, plus all the resources loaded, etc., then I do not do the reload, but rather give the user a menu option from the main menu to do the reload when they are ready. If they don’t do the reload, the next start up will put it in place, so they get the newest at some point, and the menu option persists till performed or app start up.

I still have issues with the start in desktop browser. It seems I have to be in inspector and do a clear cache and hard reload to be sure I got the latest from AS IDE, or close the IDE, or close chrome.

Gary:

I took the code you originally posted on this, that’s what I’m using now, but did not code to not restart on program update. I like your menu idea better since I don’t have to worry about interrupting the user with a forced update, and inserting other code to insure data is saved or synced. In some apps I don’t have a menu, just navigation buttons, but I think I can work a restart in there somehow that is in a safe place and is gentle. Most of my apps are for remote data collection and syncing to their server. Interrupting them in the middle of concentrated work is not a good thing to do.

Thanks, John

John, Glad the idea helped. My app is the same, data collection to the server. Gary