Skip to content
Merged
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
12 changes: 1 addition & 11 deletions assets/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,9 @@ document.addEventListener(
true
);

// Track whether the initial load has completed so that minor post-load
// runtime errors don't replace the viewer with a crash screen.
let loaded = false;

void (async () => {
await window.PDFViewerApplication.initializedPromise;
await window.PDFViewerApplication.open(config);
loaded = true;
await window.PDFViewerApplication.pdfViewer.pagesPromise;
const [, hash] = config.url.split("#");
if (hash) {
window.PDFViewerApplication.pdfLinkService.setHash(
Expand All @@ -72,9 +66,7 @@ window.addEventListener("message", async (event) => {
window.PDFViewerApplication.pdfViewer.currentPageNumber;
switch (event.data.action) {
case "reload":
loaded = false;
await window.PDFViewerApplication.open(config);
loaded = true;
await window.PDFViewerApplication.pdfViewer.pagesPromise;
window.PDFViewerApplication.pdfViewer.currentPageNumber = Math.min(
currentPageNumber,
Expand All @@ -85,7 +77,5 @@ window.addEventListener("message", async (event) => {
});

window.addEventListener("error", (error) => {
if (!loaded) {
document.body.textContent = `An error occurred (${error.message}) while loading the file. Please open it again.`;
}
console.error(error);
});
Loading