HTML 5 Application Cache catch events in Chrome - html

I've created a website using HTML 5 offline Application Cache and it works well in most cases, but for some users it fails. In Chrome, when the application is being cached, the progress is displayed for each file and also error messages if something goes wrong, like:
Application Cache Checking event
Application Cache Downloading event
...
Application Cache Progress event (7 of 521) http://localhost/HTML5App/js/main.js
...
Application Cache Error event: Failed to commit new cache to storage, would exceed quota.
I've added event listeners to window.applicationCache (error, noupdate, obsolete, etc.), but there is no information stored on the nature of the error.
Is there a way to access this information from the web site using JavaScript ?
I would like to determine somehow which file caused the error or what kind of error occurred.

I believe that the spec doesn't mention that the exact cause of the exception should be included in the error. Currently the console is your only friend.
To wit, your current error "exceed quota" is due to the fact that Chrome currently limits the storage to 5MB. You can work around this by creating an app package that requests unlimited_Storage via the permission model. See http://code.google.com/chrome/apps/docs/developers_guide.html#live for more details.
If you want specific error messages on the "onerror" handler raise a bug on http://crbug.com/new

Related

WebAssembly crash info in window.onerror()

I am trying to collect crash logs for my WebAssembly application. It's built with emscripten, everything is served from the same domain, testing in Chrome. In the developer console I see a proper error with stack trace when a crash occurs, I'd like to capture this and send it to a server.
Instead I am only getting "Script error." passed to window.onerror() and the fifth parameter is null. This is supposed to happen when violating the same-origin policy (linked question is only about javascript, does not talk about this WebAssembly-specific problem.) Errors occurring in the .js file don't have this problem, only webassembly runtime errors.
I added the crossorigin attribute to the .js file generated by emscripten. The site is running in secure context, the Response object passed to WebAssembly.instantiateStreaming() (in the emscripten-generated .js file) has "basic" as its .type, so as I understand it has no restrictions on what can be done with it. "Access-Control-Allow-Origin" header is set to "*".
For some weird reason I managed to get the full error with stack trace exactly once, so it is apparently possible, but seemingly doing everything the same way I can't get it to work again.
How can this be solved?
instantiateStreaming is promised based so maybe try window.addEventListener('unhandledrejection')?

WinInet FtpOpenFile timeout

I have an app that regularly uploads file using WinInet's FTP functions. It's been running for years but started failing on 4/1/2021. It fails opening a file using FtpOpenFile with a status of 12002 Internet Timeout. The call looks like this..
hiOpenFile = FtpOpenFile(
hiSiteConnect,
"TEMP.htm",
GENERIC_WRITE,
FTP_TRANSFER_TYPE_ASCII,
NULL
);
The file does get created on the server.
I'm wondering what the time out value for this function is and if there is anyway to change it?
I kept getting 12002 Internet Timeout with both FtpOpenFile and FtpGetFile but both work now after adding the INTERNET_FLAG_PASSIVE flag to my InternetConnect call.
Regarding timeouts, normally you would use INTERNET_OPTION_CONNECT_TIMEOUT,INTERNET_OPTION_RECEIVE_TIMEOUT, or INTERNET_OPTION_SEND_TIMEOUT with InternetSetOption. See here for details on the option flags: https://learn.microsoft.com/en-us/windows/win32/wininet/option-flags
However, due to a very old MS bug, setting the timeout as above simply has no effect whatsoever. There is a workaround to reduce the timeout but not to increase. It is done by creating a new worker thread and waiting for it. See here for the article:
https://mskb.pkisolutions.com/kb/224318

Handle FileNotFoundException thrown by ImageResizer.AzureReader2 (BlobNotFound)

I'm running an MVC app on Azure. I use the AzureReader2 plugin. It's been working fine for years.
But when this hits missing images, it throws FileNotFoundException exception and this apparently breaks down user authentication, causing user to be redirected to login page.
Is there a way to prevent this? How can I catch and handle this exception for the URL API?
I am considering the Image404 plugin. But I am not sure it works with AzureReader2 plugin (?)
Exception handling would be best for me as I could take some other actions.
Thanks
You can see the Image404 plugin source code on GitHub. There is a Config.Current.Pipeline.ImageMissing event that it handles - you can plug into the same event to do your own logic.
It should work fine with AzureReader2.
Note that most likely your 404 page is set to require authentication, which is why it is redirecting.

How to handle "Unexpected EOF at target" error from API calls?

I'm creating a Forge application which needs to get version information from a BIM 360 hub. Sometimes it works, but sometimes (usually after the code has already been run once this session) I get the following error:
Exception thrown: 'Autodesk.Forge.Client.ApiException' in mscorlib.dll
Additional information: Error calling GetItem: {
"fault":{
"faultstring":"Unexpected EOF at target",
"detail": {
"errorcode":"messaging.adaptors.http.flow.UnexpectedEOFAtTarget"
}
}
}
The above error will be thrown from a call to an api, such as one of these:
dynamic item = await itemApi.GetItemAsync(projectId, itemId);
dynamic folder = await folderApi.GetFolderAsync(projectId, folderId);
var folders = await projectApi.GetProjectTopFoldersAsync(hubId, projectId);
Where the apis are initialized as follows:
ItemsApi itemApi = new ItemsApi();
itemApi.Configuration.AccessToken = Credentials.TokenInternal;
The Ids (such as 'projectId', 'itemId', etc.) don't seem to be any different when this error is thrown and when it isn't, so I'm not sure what is causing the error.
I based my application on the .Net version of this tutorial: http://learnforge.autodesk.io/#/datamanagement/hubs/net
But I adapted it so I can retrieve multiple nodes asynchronously (for example, all of the nodes a user has access to) without changing the jstree. I did this to allow extracting information in the background without disrupting the user's workflow. The main change I made was to add another Route on the server side that calls "GetTreeNodeAsync" (from the tutorial) asynchronously on the root of the tree and then calls it on each of the returned children, then each of their children, and so on. The function waits until all of the nodes are processed using Task.WhenAll, then returns data from each of the nodes to the client;
This means that there could be many api calls running asynchronously, and there might be duplicate api calls if a node was already opened in the jstree and then it's information is requested for the background extraction, or if the background extraction happens more than once. This seems to be when the error is most likely to happen.
I was wondering if anyone else has encountered this error, and if you know what I can do to avoid it, or how to recover when it is caught. Currently, after this error occurs, it seems that every other api call will throw this error as well, and the only way I've found to fix it is to rerun the code (I use Visual Studio so I just rerun the server and client, and my browser launches automatically)
Those are sporadic errors from our apigee router due to latency issues in the authorization process that we are currently looking into internally.
When they occur please cease all your upcoming requests, wait for a few minutes and retry again. Take a look at stuff like this or this to help you out.
And our existing reports calling out similar errors seem to point to concurrency as one of the factors leading up to the issue so you might also want to limit your concurrent requests and see if that mitigate the issue.

Appcache and custom error pages

I've been working on an Spring MVC application that has custom error pages, these pages return a generic error message and the stack trace as an HTML comment. I'm currently developing the offline funcitonalities of this application using HTML5's Appcache. My manifest is something like this:
CACHE MANIFEST
CACHE:
... my explicit entries (not relevant) ...
FALLBACK:
... some fallback entries (not relevant) ...
<!-- This next line is relevant --!>
/ pageNotFoundOffline.html
SETTINGS:
prefer-online
Which is supposed to serve a previously cached 404 page when the user can't connect to the server, the problem is that it also serves this 404 page when an error occurs, thus rendering completely useless the custom error page already implemented in the application.
Why i want to do this? i want that whenever a user tries to access any page on my application and the request fails with a 404 (either because the is no available internet connection or because the servers are down), that user is informed that the request failed and he or she is being redirected to our offline functionalities, also i want to inform the user when he or she succesfully reached our servers but an internal error occurred (through the custom error page).
Is there a workaroud for this problem?, what i would like to accomplish is the cached 404 page to be served only when there is a 404 exception and the custom error page returned by the server to be displayed when there was an internal error.
I'm afraid that it is not possible with appcache - the fallback intercepts all server errors. The specification for appcache says: "If this results in a redirect to a resource with another origin (indicative of a captive portal), or a 4xx or 5xx status code or equivalent, or if there were network errors (but not if the user canceled the download), then instead get, from the cache, the resource of the fallback entry corresponding to the fallback namespace f. Abort these steps."
If you can use the more modern way of doing things, Service Workers, I would recommend using that, as that will let you do what you want.