How do I know when a page fails to load?
When there's a server error, and I get the gray window that sayd "Google Chrome fails to load this page..." or "this page in not available" ?
I want to add my extension an option of auto refresh after 10 seconds. I work with some web-app that sometimes the server fails to load for some reason, and a refresh just brings it back to life.
So I'm looking for auto-refresh in this case.
Thanks in advance!
You may want to take a look at the chrome.webRequest.onErrorOccurred.addListener(function details){} listener. Per the documentation, errors that are triggered by any event before the completion of a request will fire the onErrorOccurred method. The details will contain information about the error, but in your case it sounds like any triggered error should cause a refresh, so perhaps something like this (completely untested, more theoretical :) ):
chrome.webRequest.onErrorOccurred.addListener(function details){
chrome.tabs.reload(details.tabId);
}
Related
I am not sure whether its a usual behavior or not, but, on [WKWebView goBack] navigates to previous page from the Back-Forward list. but, in my case on very first back action, it does not calls didFinishNavigation delegate method.
So, if it's usual behavior then how to detects that page loading is completed after back the action.
Are you seeing this on a specific iOS version? Im seeing this too, only and error is being thrown and the page just stops loading, hence didFinish... not being called.
I've only started seeing this since 13.4 (or 13.4.1)
--- EDIT ---
I do have a workaround.
This appears to happen more often on slower networks and when the user interacts before a page is fully loaded. Normally if a user taps back before the page they visited finished loading then a "Cancelled" error is thrown.
What seems to be happening now is, if the page they are returning to never finished loading at the point they left, then the error is thrown again, but this time referencing the page they are returning to. and more importantly the web view is no longer loading at this point.
what we have done is monitor this and check to see if the page is not loading, and if it isn't, reload it. This seems to work and while not ideal, its buying us some time to investigate a proper fix.
In addition, I put a retry limit on this and we show an error with a reload button after the third attempt, though in practice we've never seen it go beyond the first reload attempt.
The fact that the error is thrown almost instantaneously means the reload adds no perceivable delay for the user.
I even see this on the simulator. Navigate to google.com, click privacy, then goBack and while the page loads normally, navigation reports a failure with error:
Error Domain=NSURLErrorDomain Code=-999 "(null)" UserInfo={NSErrorFailingURLStringKey=https://www.google.com/, NSErrorFailingURLKey=https://www.google.com/, _WKRecoveryAttempterErrorKey=<WKReloadFrameErrorRecoveryAttempter: 0x600003904e40>}
What you need to do is capture this with the didFailNavigation: delegate method and handle it gracefully (if you see a consistent error like the above you can even treat it exactly the same as success).
I have a Xpage that takes too long to load. So the client ask me to do a loading indicator.
I searched and found XSP.startAjaxLoading(), that I put in onClientLoad event of the Custom Control.
But now I don't know where should I put XSP.endAjaxLoading() to make the loading screen go away.
I'tried to use in afterRenderResponse and beforeRenderResponse: view.postScript("XSP.endAjaxLoading()"), since this comand is CSJS, but it doesn't work.
Thanks in advance.
I think you want to put it in the onComplete event. That can be difficult to find. You typically need to use the outline control to find it.
I have a video demo on NotesIn9 that has an example on this.
http://www.notesin9.com/2016/02/19/notesin9-188-adding-a-please-wait-to-xpages/?unique=http%3A//www.notesin9.com/2016/02/19/notesin9-188-adding-a-please-wait-to-xpages/
Your attempt (view.postscript) works only with full/partial updates and does not work for page loading.
You have used onClientLoad - which is executed when your page is finished with loading. I guess you get ajax animation after a while and it won't stop.
You should make preload screen - very simple XPage which starts animation and does not care to turn it off. In onClientLoad event redirect to your slow XPage. That will discard the animation.
I'd highly recommend using the Standby Dialog XSnippet https://openntf.org/XSnippets.nsf/snippet.xsp?id=standby-dialog-custom-control. I use it as a standard in all XPages applications.
I used this answer as solution: https://stackoverflow.com/a/35481981/5339322
I've saw it a few days ago, what made me think twice is that using this i should know what is doing my XPages to delay. I ran some tests and discovered what, and it was a call to a method in the afterRestoreView event, then I migrated it to onClientLoad event and used the solution in the answer above cited.
But I'm afraid that I have to keep an eye on it, so if someone adds some code that delays in one of the another events of XPages I have to move it again, of course, if it's possible, if it's not, I'll figure it out something diferent.
Thanks for all the answers ans comments.
I inject my content script using filtered events instead of manifest content-scripts match rules.
When I navigate to a target page, content script doesn't run always, but only sometimes. When it fails to run I refresh the page (sometimes more than once), untill the content script starts.
For simplicity, I don't want to put the code I know is working. onDOMContentLoaded is not always firing when the filter meets the condition.
var filtro = {'url': [
{hostSuffix: 'somedomain.com', pathPrefix: '/search'},
{hostSuffix: 'somedomain.org', pathPrefix: '/search'}
]};
chrome.webNavigation.onDOMContentLoaded.addListener(listener, filter);
chrome.webNavigation.onErrorOcurred.addListener (listener, filter);
So I added onErrorOcurred, to fire when the page fails to load. But I still missing something, because it doesn't execute every time (but it executes on refreshing the page).
As many other pages, this one trows a lot of error messages to console. I imagine some of these may prevent onDOMContentLoaded to fire, but I think it should fire onErrorOcurred. Am I missing some event?
It happens to me in many different extensions and pages when using filtered events.
Thank you very much.
I am currently have this message handler line:
MESSAGE_HANDLER(`WM_SETREDRAW`, onSetRedraw)
I would like to know, is there any window message (eg: WM_???) that is connected/related to 'when a website has finish loading inside IE' ?
So I can use it to replace the above WM_SETREDRAW. I want to do something like, when the IE finish loaded a website, it call onSetRedraw.
If no one answers, go Gogoling for an application "spy" tool, which will tell you which messages your program receives. Make a one line app which one launches the browser and spy on that.
Alternatively, what API are you using to launch the browser? Look at it's return value.
Btw, I strongly suspect that you will only get a message when the browser is launched, not every time it loads a new page (or even the first page).
You may not be able to do what you want very easily. A possibility might be to search for the window by title bar, get it's handle, walk its control list until you get to the status bar and check its text in a loop until it is done.
A further possibility, if this is only for yourself, woudl be to get an open source browser which uses the MSIE rendering engine and make a one line change at "the right place in the code" to send a message to your app every time a new page is loaded.
I want a confirmation window on click of a browser back button. If I press yes then the previous page will get load ortherwise I will remain in the same page?
Any suggestion is highly appreciated.. But please be on track.. my question is straight forward
thx in advance..
Why do you want to do that?
You can prevent them from leaving the page by using Javascript, but if you can't use that, it's not possible to do anything about it.
Generally you should use the unload event in the body (in jQuery for instance, just add
jQuery(window).unload(function(evt){
if(!confirm('Do you really want to leave')){
evt.preventDefault();
}});
Prototype have something similar, and for pure Javascript, I guess that it still depends on the browser you're using, but window.unload = function(evt){return false;} might work.
Don't remember the correct syntax for it though.
but I do not know if you can limit that for only the back or if it will trigger for all the unloads (like clicking on a link, closing the browser etc.)
If you want to stop them because they might have unsaved data in a form, then that is ok. If you want to stop them from going back for another reason than that, I think you should rethink why.
Generally if using the back button can cause issues you already have bigger problems.
What you probably want to do is check that you do things like this:
Use POST for all requests that alter data
Use nonce's (unique ID's) to enure forms don't get submitted twice
I use noscript for this very reason. I insist on having control of my browser not the site that I am visiting. I only allow scripts for certain sites. For any site that disables my back button,I don't allow it to run scripts.