I am working on a multiplayer chess game as a Facebook app.
If one player leaves the game by closing the browser the other player should get a notification. So if one player closes the Browser, a unlink function should be called to unlink the player. This works fine with onunload outside Facebook.
The problem is, that the Facebook apps are loaded in iframes and the onunload event doesn't work there.
So I need a way to call a function inside an iframe when a user is closing the browser.
This is probably not the answer you are looking for but "logging off" on unload will never work reliably. For an extreme example, consider the case where the browser crashes or is killed via the Windows task manager. So you better implement an additional mechanism to detect whether a user left. Typically this is done by sending a request to the server periodically. If this request isn't received for a significant time (meaning something that cannot be caused by a slow connection or other hiccups) you unlink the user.
That said, I tested Firefox 4 and MSIE 8 and both correctly fire unload event on the frame if the tab or the browser is closed. Chrome 12 doesn't do that, that's probably the browser you have been testing with. I consider it a Chrome bug.
Related
I'm working on a Ruby on Rails application with Action Cable. Watching the logs, I've noticed that when I put my phone to sleep that the WebSocket is closed automatically, so further updates are not received. However, on wake (directly to the page, or opening the browser again and giving the tab focus) the connection is immediately re-established.
I want to refresh the page at this moment so that it's up-to-date. The "focus" event is not useful, as it will trigger whenever desktop users bounce between windows or tabs.
What event can I use to reload the page on wake? Something must be available, as Action Cable is reconnecting (though I realize it may be using the focus event as well and simply checking if a connection exists or not).
How can we detect through PHP or maybe in node.js or other languages if a web page crashed (without the browser EXITing) so that when a user press the "reload" button on the "Aw Snap" page in chrome certain specific content inside the page can be shown in this particular case (crash case).
In a crash without EXIT, a browser shows per example in Google Chrome the famous "Aw, Snap!" page.
I don't want to know how to capture if the user refreshed the page or the page reloaded which can be known quite easily with different methods [one example see this PHP this code which can detect if users refreshed the page on major desktop/mobile browsers except IE unfortunately this code does not capture a crash event and the fact that user might request again the same page after a crash.
I tried using "register_shutdown_function", and some other maneuvers using connection PHP functions like "connection_aborted" etc... but with no success. I figure out a sloppy way through the use of session variables but probably there are better clever manoeuvres.
Any help or suggestion would be greatly appreciated. Any solution in nodejs will be also welcomed.
web brower crash because too many process from your browser to PC of Client.
this crash can't detected by php because PHP server scripting. and you have question.., why not use JS for detect crash of browser?, because JS created just for controller website,. if you force to checked that use ajax, node, etc you can't do that, why? because the problem comes suddenly
and detected crash browser from php is impossible.
I'm using a web framework where everything gets passed through a websocket. New / updated DOM elements are shipped over to the browser, events get shipped back to the server. Works great. Except when the websocket gets closed.
This happens...
when using desktop/mobile Safari's browser navigation buttons are used to leave & come back to the page
on mobile Safari after a timeout when switching to a different app, tab or screen locking
when the WiFi goes down etc.
After that the user simply sees a normal looking page, but everything is obviously dead as no more updates happen and no more events get relayed to the server. I'd like to simply refresh the page in that case. Either everything goes back to normal or the user sees a connection error in case of no network etc.
I tried poking around in the framework's code, adding "window.location.reload(true);" to the "onclose" handler for the websocket kinda does the trick. My state is 100% on the server, so reloading the page will just fix things.
Assuming I can't modify / fix the web framework I'm using, and it doesn't have any onConnectionLost client-side event, what's my best option to detect this scenario and reload the page? Are there any events like 'onPageDisplayedButNotProperlyReloaded', 'onPageVisibleButHasBecomeStaleInTheMeantime', 'onWebSocketsClosed' for me to use? Can I just open some dummy websocket and reload the page when it gets closed or something? Any other good way to detect this?
Thanks!
I'm having an issue where closing my Chrome App too quickly after completing a stage corrupts the save data. This is because it's in the middle of saving some data.
Is there any way to keep the Chrome App open for a few seconds after the user presses close or alt+f4? Or another solution that maybe has a popup telling the user that the app is saving and will close automatically?
You can use the chrome.runtime.onSuspend.addListener( function ) method to specify some code to run when the user quits the app. As stated in the chrome documentation, any code running or triggered in the background/event page will keep the program alive for a short time to allow these processes to end. Remember to register this event listener method in your background/event page before the user has a chance to quit.
Additional information here:
https://developer.chrome.com/extensions/runtime#event-onSuspend
I am working on an extension for Chrome that utilizes a native messaging host. My background.js registers a listener immediately to process all onBeforeRequest events (i.e., all requests) and pass them on to the native helper application. This is all well and good when a page is visited after Chrome has started up, but when I click a URL that launches Chrome, my listener does not fire.
Here is the basic structure of the listener at the top of my background.js:
chrome.webRequest.onBeforeRequest.addListener(function (details) {
alert('forwarding request!');
chrome.runtime.sendNativeMessage('<extension name>', { url: details.url });
}, { urls: ['http://*', 'https://*'] }, ['blocking']);
Obviously, there are conditions in place that determine whether to pass off the request and block it in Chrome, but they are not relevant here. Even without the sendNativeMessage bit, I cannot produce an alert for the URL that is clicked to launch an instance of Chrome.
Any clever ways to register this listener before the first request at startup goes through?
You can try giving your extension the background permission:
Makes Chrome start up early and and shut down late, so that apps and extensions can have a longer life.
When any installed hosted app, packaged app, or extension has "background" permission, Chrome runs (invisibly) as soon as the user logs into their computer—before the user launches Chrome. The "background" permission also makes Chrome continue running (even after its last window is closed) until the user explicitly quits Chrome.
This way the Chrome process and extensions will be loaded before you click any URL. The user can still circumvent this by explicitly killing the Chrome process.
As a side note, keep in mind that the response from your onBeforeRequest listener needs to be synchronous if you want to block a request, so you can't base the decision to block on the response from a native messaging host.
One way to solve the problem is to use the chrome.declarativeWebRequest API to declaratively register a webRequest listener. The disadvantage of this API is that it is only available to Chrome users on the beta and dev channel at the moment, and less flexible than the webRequest API (the rules are declarative, so you cannot make runtime decisions about request handling that are not supported by the DWR API).
Another way to work around the problem is to use chrome.tabs.query to find tabs that had been opened before the extension was launched.