Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PDFHistory] Move the IE11 pushState/replaceState work-around to src/shared/compatibility.js (PR 10461 follow-up) #11318

Merged
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
23 changes: 23 additions & 0 deletions src/shared/compatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ globalScope._pdfjsCompatibilityChecked = true;
const { isNodeJS, } = require('./is_node');

const hasDOM = typeof window === 'object' && typeof document === 'object';
const userAgent =
(typeof navigator !== 'undefined' && navigator.userAgent) || '';
const isIE = /Trident/.test(userAgent);

// Support: Node.js
(function checkNodeBtoa() {
Expand Down Expand Up @@ -112,6 +115,26 @@ const hasDOM = typeof window === 'object' && typeof document === 'object';
};
})();

// Provides support for window.history.{pushState, replaceState}, with the
// `url` parameter set to `undefined`, without breaking the document URL.
// Support: IE
(function checkWindowHistoryPushStateReplaceState() {
if (!hasDOM || !isIE) {
return;
}
const OriginalPushState = window.history.pushState;
const OriginalReplaceState = window.history.replaceState;

window.history.pushState = function(state, title, url) {
const args = (url === undefined ? [state, title] : [state, title, url]);
OriginalPushState.apply(this, args);
};
window.history.replaceState = function(state, title, url) {
const args = (url === undefined ? [state, title] : [state, title, url]);
OriginalReplaceState.apply(this, args);
};
})();

// Provides support for String.prototype.startsWith in legacy browsers.
// Support: IE, Chrome<41
(function checkStringStartsWith() {
Expand Down
12 changes: 2 additions & 10 deletions web/pdf_history.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,10 @@ class PDFHistory {
}
}
if (shouldReplace) {
if (newUrl) {
window.history.replaceState(newState, '', newUrl);
} else {
window.history.replaceState(newState, '');
}
window.history.replaceState(newState, '', newUrl);
} else {
this._maxUid = this._uid;
if (newUrl) {
window.history.pushState(newState, '', newUrl);
} else {
window.history.pushState(newState, '');
}
window.history.pushState(newState, '', newUrl);
}

if (typeof PDFJSDev !== 'undefined' && PDFJSDev.test('CHROME') &&
Expand Down