You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Capture call stack outside of "window.onbeforeunload" for chrome #32
I am trying to use this library to capture the origin of a change to window.location and have had some success for FF and IE, but chrome doesn't seem to preserve the source of the originating window.location change.
Any ideas on how to achieve this, or another work around to get the same result?
See below for some JS that can be added to any page, and alerts the stack trace on unload
<scripttype="text/javascript"src="stacktrace-0.3.js"></script><scripttype="text/javascript">window.onload=function(){alert("window.onload");}window.onbeforeunload=function(e){e=e||window.event;// capture stack trace (NOTE: FF captures full stack, IE captures stack but doesn't include 'onbeforeunload' function in stack, CHROME doesn't show stack)vartrace=printStackTrace();alert('window.onbeforeunload\nSTACKTRACE: '+trace.join('\n;'));varmsg='Do you want to stop window unload?';// For IE and Firefox prior to version 4if(e){e.returnValue=msg;}// For Safarireturnmsg;};</script>
In short words: it works, but alert isn't displayed in Chrome.
As you can see at http://code.google.com/p/chromium/issues/list?can=1&q=onbeforeunload+alert (replace & in URL with & - I lost this mini-quest and don't know how to insert this URL properly) there is one or more bugs with alert/prompt/confirm called from onbeforeunload handler, so current Chrome silently ignores any alert() in onbeforeunload. There is a couple of similar questions on stackoverflow.
So you can collect stack trace information, find something useful from event passed into handler, but you can't show this information in alert. Alternatively you can show it in HTML markup on the page (maybe with help of LightBox or other popup) or send to server via AJAX request or store in LocalStorage etc.
Activity
victor-homyakov commentedon Nov 10, 2011
Do you have some example to play with it?
brightsparc commentedon Nov 10, 2011
See below for some JS that can be added to any page, and alerts the stack trace on unload
victor-homyakov commentedon Nov 11, 2011
I'll look into this issue. Already found one error in findFunctionName from your test case :)
Test page for issue #32
victor-homyakov commentedon Nov 11, 2011
In short words: it works, but alert isn't displayed in Chrome.
As you can see at http://code.google.com/p/chromium/issues/list?can=1&q=onbeforeunload+alert (replace & in URL with & - I lost this mini-quest and don't know how to insert this URL properly) there is one or more bugs with alert/prompt/confirm called from onbeforeunload handler, so current Chrome silently ignores any alert() in onbeforeunload. There is a couple of similar questions on stackoverflow.
So you can collect stack trace information, find something useful from event passed into handler, but you can't show this information in alert. Alternatively you can show it in HTML markup on the page (maybe with help of LightBox or other popup) or send to server via AJAX request or store in LocalStorage etc.
Test page for issue #32 working in Chrome
victor-homyakov commentedon Nov 11, 2011
@brightsparc: look at test/issues/32.html - it is based on your example, play with it in Chrome
victor-homyakov commentedon Feb 21, 2012
@brightsparc: do you have looked at the test page?
eriwen commentedon Oct 7, 2014
Closing due to lack of activity. If this is still a problem after we release v1.0 please open another issue.