Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Capture call stack outside of "window.onbeforeunload" for chrome #32

Closed
brightsparc opened this Issue Nov 10, 2011 · 7 comments

Comments

3 participants

Hi,

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?

Cheers,
Julian.

Contributor

victor-homyakov commented Nov 10, 2011

Do you have some example to play with it?

See below for some JS that can be added to any page, and alerts the stack trace on unload

<script type="text/javascript" src="stacktrace-0.3.js"></script>
<script type="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)
       var trace = printStackTrace();
       alert('window.onbeforeunload\nSTACKTRACE: ' + trace.join('\n;'));

      var msg = 'Do you want to stop window unload?';

      // For IE and Firefox prior to version 4
      if (e) {
        e.returnValue = msg;
      }

      // For Safari
      return msg;
    };

</script>
Contributor

victor-homyakov commented Nov 11, 2011

I'll look into this issue. Already found one error in findFunctionName from your test case :)

victor-homyakov added a commit that referenced this issue Nov 11, 2011

Contributor

victor-homyakov commented 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 &amp; 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.

Contributor

victor-homyakov commented Nov 11, 2011

@brightsparc: look at test#32.html - it is based on your example, play with it in Chrome

Contributor

victor-homyakov commented Feb 21, 2012

@brightsparc: do you have looked at the test page?

@eriwen eriwen removed the waffle:ready label Oct 7, 2014

Owner

eriwen commented Oct 7, 2014

Closing due to lack of activity. If this is still a problem after we release v1.0 please open another issue.

@eriwen eriwen closed this Oct 7, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment