Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 23 additions & 21 deletions src/raven.js
Original file line number Diff line number Diff line change
Expand Up @@ -1272,8 +1272,12 @@ Raven.prototype = {
// borrowed from: https://github.com/angular/angular.js/pull/13945/files
var chrome = _window.chrome;
var isChromePackagedApp = chrome && chrome.app && chrome.app.runtime;
var hasPushState = !isChromePackagedApp && _window.history && history.pushState;
if (autoBreadcrumbs.location && hasPushState) {
var hasPushAndReplaceState =
!isChromePackagedApp &&
_window.history &&
history.pushState &&
history.replaceState;
if (autoBreadcrumbs.location && hasPushAndReplaceState) {
// TODO: remove onpopstate handler on uninstall()
var oldOnPopState = _window.onpopstate;
_window.onpopstate = function() {
Expand All @@ -1285,26 +1289,24 @@ Raven.prototype = {
}
};

fill(
history,
'pushState',
function(origPushState) {
// note history.pushState.length is 0; intentionally not declaring
// params to preserve 0 arity
return function(/* state, title, url */) {
var url = arguments.length > 2 ? arguments[2] : undefined;

// url argument is optional
if (url) {
// coerce to string (this is what pushState does)
self._captureUrlChange(self._lastHref, url + '');
}
var historyReplacementFunction = function(origHistFunction) {
// note history.pushState.length is 0; intentionally not declaring
// params to preserve 0 arity
return function(/* state, title, url */) {
var url = arguments.length > 2 ? arguments[2] : undefined;

return origPushState.apply(this, arguments);
};
},
wrappedBuiltIns
);
// url argument is optional
if (url) {
// coerce to string (this is what pushState does)
self._captureUrlChange(self._lastHref, url + '');
}

return origHistFunction.apply(this, arguments);
};
};

fill(history, 'pushState', historyReplacementFunction, wrappedBuiltIns);
fill(history, 'replaceState', historyReplacementFunction, wrappedBuiltIns);
}

if (autoBreadcrumbs.console && 'console' in _window && console.log) {
Expand Down
6 changes: 3 additions & 3 deletions test/integration/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ describe('integration', function() {
);
});

it('should record history.[pushState|back] changes as navigation breadcrumbs', function(
it('should record history.[pushState|replaceState] changes as navigation breadcrumbs', function(
done
) {
var iframe = this.iframe;
Expand All @@ -1205,9 +1205,9 @@ describe('integration', function() {

// can't call history.back() because it will change url of parent document
// (e.g. document running mocha) ... instead just "emulate" a back button
// press by calling replaceState + onpopstate manually
// press by calling replaceState
history.replaceState({}, '', '/bar?a=1#fragment');
window.onpopstate();

done();
},
function() {
Expand Down