Skip to content

Commit

Permalink
Merge pull request #16630 from Rob--W/crx-url-hash-init
Browse files Browse the repository at this point in the history
Correct recognition of fragments at document load
  • Loading branch information
timvandermeij authored Jul 8, 2023
2 parents 1567d02 + f2753d6 commit 42edc4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion extensions/chromium/pdfHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ limitations under the License.
var VIEWER_URL = chrome.extension.getURL("content/web/viewer.html");

function getViewerURL(pdf_url) {
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url);
// |pdf_url| may contain a fragment such as "#page=2". That should be passed
// as a fragment to the viewer, not encoded in pdf_url.
var hash = "";
var i = pdf_url.indexOf("#");
if (i > 0) {
hash = pdf_url.slice(i);
pdf_url = pdf_url.slice(0, i);
}
return VIEWER_URL + "?file=" + encodeURIComponent(pdf_url) + hash;
}

/**
Expand Down
3 changes: 3 additions & 0 deletions web/chromecom.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("CHROME")) {
}

AppOptions.set("defaultUrl", defaultUrl);
// Ensure that PDFViewerApplication.initialBookmark reflects the current hash,
// in case the URL rewrite above results in a different hash.
PDFViewerApplication.initialBookmark = location.hash.slice(1);
})();

const ChromeCom = {
Expand Down

0 comments on commit 42edc4d

Please sign in to comment.