Phantomjs: Event.popstate is fired on start any page

Created on 28 Aug 2014  路  8Comments  路  Source: ariya/phantomjs

var page = require('webpage').create();

page.onConsoleMessage = function(msg, lineNum, sourceId) {
    console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};

page.open('data:text/html,'+
  '<body><script>window.addEventListener("popstate", function () { console.log("Event popstate")}); </script></body>',
  function (status) {
    console.log(status);
});

In chorme and firefox is event is fired only when the url to accessed was placed in the history with history.pushState or history.replaceState

This behavior on phantomjs is the same presenting in some old versions of chrome

stale

Most helpful comment

@alex-voigt kind of annoying, but i attached the listener using a timeout (just to fix my tests 馃槮 )

setTimeout((function() {
  window.onpopstate = function(event) {
    return window.location.href = window.location.href;
  };
}), 1000);

All 8 comments

@ariya be fixed in 2.x? or not.

@geminiyellow Did you try it?

@ariya window.onpopstate is still firing on page load in phantomjs 2.1

same for me

@alex-voigt kind of annoying, but i attached the listener using a timeout (just to fix my tests 馃槮 )

setTimeout((function() {
  window.onpopstate = function(event) {
    return window.location.href = window.location.href;
  };
}), 1000);

I have the same problem. Really annoying. :(

Same problem here...

Due to our very limited maintenance capacity, we need to prioritize our development focus on other tasks. Therefore, this issue will be automatically closed (see #15395 for more details). In the future, if we see the need to attend to this issue again, then it will be reopened. Thank you for your contribution!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mdominado picture mdominado  路  3Comments

gustavohenke picture gustavohenke  路  4Comments

dhilipsiva picture dhilipsiva  路  4Comments

Sayalic0 picture Sayalic0  路  5Comments

yairza picture yairza  路  6Comments