Skip to content

Commit 34f456e

Browse files
authored
Fix pushState exception when run inside Chrome Apps (fixes #601) (#621)
1 parent 0abe7b8 commit 34f456e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/raven.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,13 @@ Raven.prototype = {
889889
}
890890

891891
// record navigation (URL) changes
892-
if ('history' in window && history.pushState) {
892+
// NOTE: in Chrome App environment, touching history.pushState, *even inside
893+
// a try/catch block*, will cause Chrome to output an error to console.error
894+
// borrowed from: https://github.com/angular/angular.js/pull/13945/files
895+
var chrome = window.chrome;
896+
var isChromePackagedApp = chrome && chrome.app && chrome.app.runtime;
897+
var hasPushState = !isChromePackagedApp && window.history && history.pushState;
898+
if (hasPushState) {
893899
// TODO: remove onpopstate handler on uninstall()
894900
var oldOnPopState = window.onpopstate;
895901
window.onpopstate = function () {

0 commit comments

Comments
 (0)