Skip to content

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

Closed

Description

@brightsparc

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.

Activity

  1. victor-homyakov commented on Nov 10, 2011

    @victor-homyakov
    Contributor

    Do you have some example to play with it?

  2. brightsparc commented on Nov 10, 2011

    @brightsparc
    Author

    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>
  3. victor-homyakov commented on Nov 11, 2011

    @victor-homyakov
    Contributor

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

  4. added a commit that references this issue on Nov 11, 2011
  5. victor-homyakov commented on Nov 11, 2011

    @victor-homyakov
    Contributor

    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.

  6. added a commit that references this issue on Nov 11, 2011
  7. victor-homyakov commented on Nov 11, 2011

    @victor-homyakov
    Contributor

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

  8. victor-homyakov commented on Feb 21, 2012

    @victor-homyakov
    Contributor

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

  9. eriwen commented on Oct 7, 2014

    @eriwen
    Member

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions