Gernot Raudner
2018-09-20 14:26:31 UTC
i'm currently struggling a bit with different browser behaviour on
location.href. chrome for example finishes executing the current stack and
only then redirects, others redirect immediately (and sometimes even still
execute the code).
so here's the code i'm testing:
window.onbeforeunload = () => console.log('1: beforeunload');
function redir(page) { setTimeout(() => console.log('5: deferred log'), 0);
location.href = page; console.log('2: redirected!'); }
function doRedir() { redir('index.jsp?p=0'); console.log('3: further down
the stack'); }
doRedir(); console.log('4: something');
results for firefox:
1: beforeunload debugger eval code:1:31
Navigated to http://localhost:8080/ajax/index.jsp?p=0
2: redirected! debugger eval code:2:99
3: further down the stack debugger eval code:3:46
4: something debugger eval code:4:12
undefined
5: deferred log
results for chrome:
2: redirected!
VM96090:3 3: further down the stack
VM96090:4 4: something
undefined
VM96090:1 1: beforeunload
VM96090:2 5: deferred log
Navigated to http://localhost:8080/ajax/index.jsp?p=0
so, imagine i don't know who or what triggered the redirect, or when it was
triggered (no control over that code) - there's a lot that can happen
between the call to location.href and the actual navigation in chrome, not
so in firefox. imagine that my page is in some specific state when
location.href is called, and i want to send back information about that
state during onbeforeunload, this page state can change a lot in chrome
during this "blackbox time".
can anyone think of a way how i could determine at which point i have to
store the page state, so that i know what i have to send during
beforeunload? i already tried it with proxies or getters/setters onto the
location object but that simply doesn't work as it's not configurable. i
even tried a few hacks (e.g. check location.href immediately after setting
it - doesn't work since it's still the old value at this point in time).
location.href. chrome for example finishes executing the current stack and
only then redirects, others redirect immediately (and sometimes even still
execute the code).
so here's the code i'm testing:
window.onbeforeunload = () => console.log('1: beforeunload');
function redir(page) { setTimeout(() => console.log('5: deferred log'), 0);
location.href = page; console.log('2: redirected!'); }
function doRedir() { redir('index.jsp?p=0'); console.log('3: further down
the stack'); }
doRedir(); console.log('4: something');
results for firefox:
1: beforeunload debugger eval code:1:31
Navigated to http://localhost:8080/ajax/index.jsp?p=0
2: redirected! debugger eval code:2:99
3: further down the stack debugger eval code:3:46
4: something debugger eval code:4:12
undefined
5: deferred log
results for chrome:
2: redirected!
VM96090:3 3: further down the stack
VM96090:4 4: something
undefined
VM96090:1 1: beforeunload
VM96090:2 5: deferred log
Navigated to http://localhost:8080/ajax/index.jsp?p=0
so, imagine i don't know who or what triggered the redirect, or when it was
triggered (no control over that code) - there's a lot that can happen
between the call to location.href and the actual navigation in chrome, not
so in firefox. imagine that my page is in some specific state when
location.href is called, and i want to send back information about that
state during onbeforeunload, this page state can change a lot in chrome
during this "blackbox time".
can anyone think of a way how i could determine at which point i have to
store the page state, so that i know what i have to send during
beforeunload? i already tried it with proxies or getters/setters onto the
location object but that simply doesn't work as it's not configurable. i
even tried a few hacks (e.g. check location.href immediately after setting
it - doesn't work since it's still the old value at this point in time).
--
--
Chromium Discussion mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss
---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+***@chromium.org.
--
Chromium Discussion mailing list: chromium-***@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-discuss
---
You received this message because you are subscribed to the Google Groups "Chromium-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-discuss+***@chromium.org.