Skip to content

Commit

Permalink
Wrap pushState/replaceState calls in try/catch blocks (#38388)
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Aug 11, 2022
1 parent b2cc07c commit 83d345e
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/service/history-impl.js
Expand Up @@ -413,22 +413,30 @@ export class HistoryBindingNatural_ {
history.originalReplaceState || history.replaceState.bind(history);
pushState = (state, opt_title, opt_url) => {
this.unsupportedState_ = state;
this.origPushState_(
state,
opt_title,
// A bug in edge causes paths to become undefined if URL is
// undefined, filed here: https://goo.gl/KlImZu
opt_url || null
);
try {
this.origPushState_(
state,
opt_title,
// A bug in edge causes paths to become undefined if URL is
// undefined, filed here: https://goo.gl/KlImZu
opt_url || null
);
} catch (e) {
dev().error(TAG_, 'pushState failed: ' + e.message);
}
};
replaceState = (state, opt_title, opt_url) => {
this.unsupportedState_ = state;
// NOTE: check for `undefined` since IE11 and Edge
// unexpectedly coerces it into a `string`.
if (opt_url !== undefined) {
this.origReplaceState_(state, opt_title, opt_url);
} else {
this.origReplaceState_(state, opt_title);
try {
if (opt_url !== undefined) {
this.origReplaceState_(state, opt_title, opt_url);
} else {
this.origReplaceState_(state, opt_title);
}
} catch (e) {
dev().error(TAG_, 'replaceState failed: ' + e.message);
}
};
if (!history.originalPushState) {
Expand Down

0 comments on commit 83d345e

Please sign in to comment.