Skip to content

Instantly share code, notes, and snippets.

@herrernst
Last active February 3, 2017 05:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save herrernst/cbeef772c8f6c3a2b266c0af2bfab3b9 to your computer and use it in GitHub Desktop.
Save herrernst/cbeef772c8f6c3a2b266c0af2bfab3b9 to your computer and use it in GitHub Desktop.
Browser behavior on computer standby

Windows 10, Ethernet DHCP

IE11

offline/online events: yes

expired timers: fire immediately

active timers: fire on time

Firefox 50

offline/online events: yes

expired timers: fire immediately (setInterval is fired twice!)

active timers: fire on time

EventSource: CLOSED with "error" event, not auto-reconnecting

Chrome 55

offline/online events: yes

expired timers: fire immediately (setInterval keeps reference to start, so next fire is earlier)

active timers: fire on time

EventSource: CLOSED without event, see bug https://bugs.chromium.org/p/chromium/issues/detail?id=225654, not auto-reconnecting

Windows 7, Ethernet static IP address

Firefox, Chrome, IE as on Windows 10 EventSource not tested

MS Edge

offline/online events: yes

expired timers: fire immediately (setInterval keeps reference to start, so next fire is earlier)

active timers: fire on time

visibility changes to hidden and back to visible

macOS Sierra, WiFi DHCP

Safari 10

offline/online events: never

expired timers: fire delayed (timeout is active computer time)

active timers: fire delayed (timeout is active computer time)

visibility changes to hidden and back to visible

Firefox 50

offline/online events: sometimes

expired timers: fire delayed (timeout is active computer time)

active timers: fire delayed (timeout is active computer time)

Chrome 55

offline/online events: sometimes

expired timers: fire delayed (timeout is active computer time)

active timers: fire delayed (timeout is active computer time)

visibility changes to hidden and back to visible

macOS El Capitan, WiFi DHCP

PowerNap: Portable wakes every two hours when plugged in

Safari 10

offline/online events: yes (also on PowerNap)

expired timers: fire immediately?

active timers:

visibility changes to hidden and back to visible

EventSource: OPEN, but not receiving updates (TODO: file bug)

Firefox 50

offline/online events: yes (also on PowerNap)

expired timers: fire immediately?

active timers:

EventSource: CLOSED with "error" event, not auto-reconnecting

Chrome 56

offline/online events: yes (also on PowerNap)

expired timers: fire immediately?

active timers:

visibility changes to hidden and back to visible

EventSource: CLOSED without event, see bug https://bugs.chromium.org/p/chromium/issues/detail?id=225654, not auto-reconnecting

iOS 10

locked on browser and tab foreground

expired timers: fire delayed (timeout is active computer time)

active timers: fire delayed (timeout is active computer time)

visibility changes to hidden and back to visible

unlocked, browser tab in background

expired timers: fire immediately when became visible (are queued?), interval is started fresh

active timers: fire on time

Android 6 (Chrome 55)

locked on browser and tab foreground

expired timers: fire delayed (timeout is active computer time)

active timers: fire delayed (timeout is active computer time)

visibility changes to hidden and back to visible

unlocked, browser tab in background

timers: fire on time (like if in foreground)

/* utility function */
function bodyLog(msg, parent) {
var div = document.createElement("div");
div.textContent = (new Date()).toLocaleTimeString() + ": " + msg;
(parent || document.querySelector("#events")).appendChild(div);
}
/* window and document events */
["pagehide", "pageshow", "online", "offline", "beforeunload", "unload" /* , "focus", "blur" */].forEach(function (evName) {
addEventListener(evName, function (e) {
bodyLog(e.type)
})
});
document.addEventListener("visibilitychange", function (evt) {
bodyLog("visibility changed to " + document.visibilityState);
});
/* timers */
var INTERVAL = 60*1000;
setInterval(function () {
bodyLog("setInterval", document.querySelector("#interval"));
}, INTERVAL);
setTimeout(function timeoutFn() {
bodyLog("setTimeout", document.querySelector("#timeout"));
setTimeout(timeoutFn, INTERVAL);
}, INTERVAL);
/* eventsource */
var eventSource = new EventSource("https://sse.now.sh/");
eventSource.onopen = eventSource.onclose = eventSource.onerror = function (e) { bodyLog(e.type + ", state: " + eventSource.readyState, document.querySelector("#eventsource")); }
eventSource.onmessage = function (e) { bodyLog("eventSource unnamed event: " + e.data, document.querySelector("#eventsource")); }
<!doctype html>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.log {
font-family: monospace;
min-height: 10em;
}
</style>
<body>
<script src="main.js"></script>
<h2>events</h2>
<div id="events" class="log"></div>
<h2>setInterval 60 secs</h2>
<div id="interval" class="log"></div>
<h2>setTimeout 60 secs recursive</h2>
<div id="timeout" class="log"></div>
<h2>eventSource</h2>
<div id="eventsource" class="log"></div>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment