{"action":"created","issue":{"url":"https://api.github.com/repos/google/closure-library/issues/681","repository_url":"https://api.github.com/repos/google/closure-library","labels_url":"https://api.github.com/repos/google/closure-library/issues/681/labels{/name}","comments_url":"https://api.github.com/repos/google/closure-library/issues/681/comments","events_url":"https://api.github.com/repos/google/closure-library/issues/681/events","html_url":"https://github.com/google/closure-library/issues/681","id":142494508,"number":681,"title":"Make Html5History ignore initial navigation event on page load in Safari","user":{"login":"metametadata","id":4689913,"avatar_url":"https://avatars.githubusercontent.com/u/4689913?v=3","gravatar_id":"","url":"https://api.github.com/users/metametadata","html_url":"https://github.com/metametadata","followers_url":"https://api.github.com/users/metametadata/followers","following_url":"https://api.github.com/users/metametadata/following{/other_user}","gists_url":"https://api.github.com/users/metametadata/gists{/gist_id}","starred_url":"https://api.github.com/users/metametadata/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/metametadata/subscriptions","organizations_url":"https://api.github.com/users/metametadata/orgs","repos_url":"https://api.github.com/users/metametadata/repos","events_url":"https://api.github.com/users/metametadata/events{/privacy}","received_events_url":"https://api.github.com/users/metametadata/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/google/closure-library/labels/P3%20-%20PRs%20Only","name":"P3 - PRs Only","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-21T22:56:18Z","updated_at":"2016-04-11T21:40:59Z","closed_at":null,"body":"__Actual__\r\nSafari fires popstate event on initial page load. So the Html5History event callback is triggered twice leading to potential issues. \r\n\r\n__Expected__\r\nIt would be great if Closure lib ignored Safari's initial event to make Html5History work the same as in Chrome and FF: on page load navigation event should be triggered only once - on Html5History instance's setEnabled(true).\r\n\r\n__Environment__\r\nReproduced in Safari 9, using ClojureScript 1.8.34 which includes:\r\n\r\n[com.google.javascript/closure-compiler \"v20151216\"]\r\n[org.clojure/google-closure-library \"0.0-20151016-61277aea\"]\r\n  [org.clojure/google-closure-library-third-party \"0.0-20151016-61277aea\"]\r\n\r\n__Workarounds__\r\nIn a meantime, it looks like users have to implement workarounds, e.g.:\r\n\r\n1) https://github.com/circleci/frontend/blob/2064f2a6fb3b883d2a965913352cdd46bd197a40/src-cljs/frontend/history.cljs#L53\r\n\r\n2) use goog.History instead of goog.history.Html5History.\r\n\r\n3) http://anmonteiro.com/2015/09/solving-closure-librarys-html5history-double-event-dispatch/ (NOTE: unfortunately this approach breaks the Back button, proof: http://v.gd/apribase_safari_issue)\r\n\r\n__Example__\r\n\r\n```html\r\n<html>\r\n<head>\r\n    <script src=\"../closure-library/closure/goog/base.js\"></script>\r\n    <script>\r\n        goog.require('goog.history.Html5History');\r\n        goog.require('goog.debug.DivConsole');\r\n        goog.require('goog.dom');\r\n        goog.require('goog.events');\r\n        goog.require('goog.history.EventType');\r\n        goog.require('goog.log');\r\n        goog.require('goog.object');\r\n        goog.require('goog.string');\r\n    </script>\r\n</head>\r\n<body>\r\n<fieldset class=\"goog-debug-panel\">\r\n    <legend>Event Log</legend>\r\n    <div id=\"log\"></div>\r\n</fieldset>\r\n\r\n<script>\r\n  var logger = goog.log.getLogger('demo');\r\n  var logconsole = new goog.debug.DivConsole(goog.dom.getElement('log'));\r\n  logconsole.setCapturing(true);\r\n\r\n  var events = goog.object.getValues(goog.history.EventType);\r\n  goog.log.info(logger, 'Listening for: ' + events.join(', ') + '.');\r\n\r\n  var h = new goog.history.Html5History();\r\n  goog.events.listen(h, events, function(e) {\r\n    goog.log.info(logger, goog.string.subs('dispatched: %s (token=\"%s\", isNavigation=%s)',\r\n        e.type, e.token, e.isNavigation));\r\n  });\r\n\r\n  h.setEnabled(true);\r\n</script>\r\n</body>\r\n</html>\r\n```\r\n\r\nOpening this file in Chrome 49 shows log:\r\n```\r\n[  0.012s] [demo] Listening for: navigate.\r\n[  0.017s] [demo] dispatched: navigate (token=\"\", isNavigation=false)\r\n```\r\n\r\nIn Safari 9:\r\n```\r\n[  0.006s] [demo] Listening for: navigate.\r\n[  0.008s] [demo] dispatched: navigate (token=\"\", isNavigation=false)\r\n[  0.009s] [demo] dispatched: navigate (token=\"\", isNavigation=true)\r\n```"},"comment":{"url":"https://api.github.com/repos/google/closure-library/issues/comments/208574544","html_url":"https://github.com/google/closure-library/issues/681#issuecomment-208574544","issue_url":"https://api.github.com/repos/google/closure-library/issues/681","id":208574544,"user":{"login":"shicks","id":143899,"avatar_url":"https://avatars.githubusercontent.com/u/143899?v=3","gravatar_id":"","url":"https://api.github.com/users/shicks","html_url":"https://github.com/shicks","followers_url":"https://api.github.com/users/shicks/followers","following_url":"https://api.github.com/users/shicks/following{/other_user}","gists_url":"https://api.github.com/users/shicks/gists{/gist_id}","starred_url":"https://api.github.com/users/shicks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shicks/subscriptions","organizations_url":"https://api.github.com/users/shicks/orgs","repos_url":"https://api.github.com/users/shicks/repos","events_url":"https://api.github.com/users/shicks/events{/privacy}","received_events_url":"https://api.github.com/users/shicks/received_events","type":"User","site_admin":false},"created_at":"2016-04-11T21:40:59Z","updated_at":"2016-04-11T21:40:59Z","body":"I'm not clear on what the solution should be.  As I understand it, goog.Html5History should probably be preferred over goog.History, so workaround #2 is out.  And as you point out, simply unlistening popstate (as the other two solutions seem to be doing, though admittedly I don't really grok ClojureScript) doesn't solve the problem because it breaks the Back button.\r\n\r\nIf you could provide more details (or even better, a patch), then we could look into it further.  Perhaps a workaround would be to detect and swallow a duplicate event in `onHistoryEvent_`?  But I'm not familiar enough with the circumstances to suggest how that might be detected.  Is this bug also present in older versions of Safari, or only 9?  (What about future versions? is it just an incompatibility with the spec? does the spec say anything about whether the browser should fire this popstate event or not?)"}}