How to get error message on a HTML5 Application Cache Error event?
Asked Answered
C

2

6

During the caching of my offline webapp I receive a totally valid error which is displayed in the browser console like this:

Application Cache Error event: Manifest changed during update, scheduling retry

I can add a Listener to be informed that an error has occured.

window.applicationCache.addEventListener('error', function(e){
  //handle error here
}, false);

How can I get the error detail, in this case "Manifest changed during update, scheduling retry"?

Crosshatch answered 20/11, 2012 at 15:2 Comment(0)
B
1

You must use window.onerror. The callback can have three parameters:

Error message (string)
Url where error was raised (string)
Line number where error was raised (number)

check this for more information: https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers.onerror

Blotchy answered 12/9, 2013 at 14:30 Comment(0)
B
1

Still a valid issue today. In my example, my error log does not return anything. I am using IE11.

<html xmlns="http://www.w3.org/1999/xhtml" manifest="icozum.appcache">

onChecking events fires but then onError with cache status = 0 which is nocached.

 window.applicationCache.onchecking = function (e) {
       var doc = document.getElementById("cachestatus");
       if (doc != null) {
            doc.innerHTML += "Checking the cache.\n";
       }
 }

Then onError

window.applicationCache.onerror = function (e) {
    var doc = document.getElementById("cachestatus");
    if (doc != null) {
         doc.innerHTML += "Cache error occurred." + applicationCache.status.toString() + "\n";
         console.log(e);
         console.log("test");
     }
 }

The output on the screen is

Checking the cache. Cache error occurred.0

There is no detail info about the error in onError event handler. I got the real error by pressing the F12. Here is the screen shot. Is there any way to capture this much detail in onError event handler.

enter image description here

And finally I figured out the problem. The error is not due to missing file. The app cache file does exist, however in windows , visual studio (2013)/IIS does not recognize the extension .appcache. The following section needs to be added to the web.config file.

<system.webServer>
  <staticContent>
    <mimeMap fileExtension=".appcache" mimeType="text/cache-manifest"/>
  </staticContent>
</system.webServer>
Boggle answered 8/8, 2015 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.