From 42f9c01cbe0c9317e254aaaaa598509950fb0267 Mon Sep 17 00:00:00 2001
From: Claude
Date: Tue, 24 Nov 2026 11:40:27 +0000
Subject: [PATCH 1/2] Open PDFs a little faster: get the PDF reader ready early
and keep one (v54)
The PDF reader (PDF.js and its 1.4 MB worker) now loads while the start
screen is up, one reader is shared by every PDF the tab opens (Open again,
adding a notebook page), and the PDF's fingerprint is worked out while the
PDF opens instead of before.
Co-Authored-By: Claude Opus 5.5
---
CHANGELOG.md | 1 +
app/index.html | 4 ++--
app/libs.js | 19 +++++++++++++++++++
app/main.js | 15 ++++++++++-----
app/report/index.html | 2 +-
app/sw.js | 14 +++++++-------
app/version.json | 2 +-
index.html | 2 +-
overlay/ink_overlay.html | 2 +-
9 files changed, 43 insertions(+), 18 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1ba726e..f983cd9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,7 @@
## Unreleased
+- **PDFs open a little faster** (v54, PDF app). The PDF reader now gets ready while the start screen is up, instead of when you pick a file, and one reader is kept for every PDF you open, so Open again and adding a notebook page no longer start a new one each time. Checking which PDF it is (to find its ink) now happens while the PDF opens, not before.
- **Laser pointer sound** (v53, PDF app and HTML overlay). Turning on the laser pointer now plays a short, quiet, low laser sound, so it is clear what just happened. Turning it off is silent.
- **Laser pointer** (v52, PDF app and HTML overlay). Tap the pen or highlighter color you already have selected, and its ring turns black, red, black. What you draw now stays for two seconds after you lift the pen, then fades away by itself. It is never saved, printed or added to Undo. Tap the color again, or pick another color or tool, to go back to writing. Your palm still erases.
- **Blue toolbar and pink eraser** (v51, PDF app and HTML overlay). The toolbar, its menus, Settings, the Timer and the Chapters / Find panel are now dark navy with light sky-blue buttons and black text, instead of black and yellow, to match the boat icon. The Eraser button is eraser pink. A selected tool has a white ring. Pen, highlighter and cover colors are unchanged.
diff --git a/app/index.html b/app/index.html
index c939fa2..151f2df 100644
--- a/app/index.html
+++ b/app/index.html
@@ -5,7 +5,7 @@
OverBoard PDF
-
+
@@ -47,7 +47,7 @@
Open again
Your PDF and your ink stay in this browser on this computer. Nothing is uploaded.
Have a Word file? In Word, choose File → Save as PDF, then drop the PDF here.
Have an HTML worksheet? Drop it here to get a _board.html copy you can write on.
- About OverBoard · Board not working? · v53
diff --git a/app/libs.js b/app/libs.js
index c6388ce..5c2d091 100644
--- a/app/libs.js
+++ b/app/libs.js
@@ -23,6 +23,25 @@ export function loadPdfjs() {
return pdfjsPromise;
}
+/* One PDF reader for every PDF this tab opens. Starting one means loading and starting the 1.4 MB
+ pdf.worker file, so sharing it makes opening a PDF, Open again, and adding a notebook page faster.
+ Closing a PDF doesn't stop it (PDF.js only stops readers it made itself). */
+let worker = null;
+export function pdfWorker(lib) {
+ if (!worker || worker.destroyed) worker = new lib.PDFWorker({ name: 'overboard' });
+ return worker;
+}
+export function dropPdfWorker() { // after a PDF failed to open: the next one gets a fresh reader, in case this one broke
+ if (worker) { try { worker.destroy(); } catch (e) { /* already gone */ } }
+ worker = null;
+}
+
+/* get PDF.js and its reader ready while the start screen is up, so the first PDF opens sooner */
+export function warmPdfjs() {
+ const go = () => loadPdfjs().then(pdfWorker, () => {});
+ if (window.requestIdleCallback) requestIdleCallback(go, { timeout: 3000 }); else setTimeout(go, 500);
+}
+
let pdflibPromise = null;
export function loadPdfLib() { // only needed for exporting and "Save ink into PDF", so it loads on first use
if (!pdflibPromise) {
diff --git a/app/main.js b/app/main.js
index ad0d1bc..f8071de 100644
--- a/app/main.js
+++ b/app/main.js
@@ -3,7 +3,7 @@
import { obLangs, obLang, obT, obTranslate } from '../shared/strings.js';
import { showLaser, makeTimer, paletteColors, setPalette, fitTools, makePopMenu, historyKey, hlInk, makeHlMenu, holdRepeat, confirmTap, flashBtn, makePeriodPicker, makeSettings, loadPeriods, startPen, remapPeriods, makeSelect, makeTyping } from '../shared/ink-core.js';
-import { loadPdfjs, PDFJS_CMAPS_URL, PDFJS_FONTS_URL } from './libs.js';
+import { loadPdfjs, pdfWorker, dropPdfWorker, warmPdfjs, PDFJS_CMAPS_URL, PDFJS_FONTS_URL } from './libs.js';
import { Viewer } from './viewer.js';
import { Ink, PT_PER_UNIT } from './ink.js';
import { Finder } from './find.js';
@@ -310,16 +310,19 @@ async function openFile(file, handlePromise) {
drop.textContent = tr('opening', { f: file.name });
try {
if (doc) await closeDoc(false);
+ const libP = loadPdfjs(); // usually ready already (warmPdfjs); if not, it loads while the file is read
const buf = await file.arrayBuffer();
const base = findBase(new Uint8Array(buf)); // a PDF OverBoard saved ink into: the original bytes come first
- let hash = await store.hashBytes(new Uint8Array(buf, 0, base));
- const lib = await loadPdfjs();
- const task = lib.getDocument({ data: new Uint8Array(buf), ...PDF_OPTS });
+ const hashP = store.hashBytes(new Uint8Array(buf, 0, base)); // copies the bytes now, so the PDF can open meanwhile
+ const lib = await libP;
+ const task = lib.getDocument({ data: new Uint8Array(buf), worker: pdfWorker(lib), ...PDF_OPTS }); // hands the bytes to the reader
task.onPassword = (give, reason) => {
const pw = prompt(reason === 2 ? 'Wrong password. Try again:' : 'This PDF has a password:');
if (pw === null) task.destroy(); else give(pw);
};
+ hashP.catch(() => {}); // (if the PDF fails first, that's the error to show)
const pdf = await task.promise;
+ let hash = await hashP;
// a blank notebook OverBoard made: its ink is kept under the notebook's ID, which stays the same as pages are added
// a picture OverBoard turned into a PDF: its ink is kept under the picture's ID (app/image.js)
let nb = null, im = null;
@@ -362,6 +365,7 @@ async function openFile(file, handlePromise) {
} catch (e) {
console.error(e);
doc = null; D = null;
+ if (!e || e.name !== 'PasswordException') dropPdfWorker();
document.body.classList.add('start'); bar.hidden = true; addPageEl.hidden = true;
showError(e && e.name === 'PasswordException' ? tr('err_password') :
e && /fetch|import|module/i.test(String(e.message)) ? tr('err_pdf_reader') :
@@ -858,7 +862,7 @@ async function changePages(change, at, by, show, msg) {
try {
const bytes = await change(new Uint8Array(await baseBlob().arrayBuffer()));
const lib = await loadPdfjs();
- const pdf = await lib.getDocument({ data: bytes.slice(), ...PDF_OPTS }).promise;
+ const pdf = await lib.getDocument({ data: bytes.slice(), worker: pdfWorker(lib), ...PDF_OPTS }).promise;
if (doc !== d) { pdf.destroy(); return; } // closed in the meantime
const old = d.pdf;
d.file = new File([bytes], d.name, { type: 'application/pdf' });
@@ -999,6 +1003,7 @@ $('#ob-inkfile').addEventListener('change', (e) => { const f = e.target.files[0]
/* ---------- start ---------- */
translateAll(); refresh(); renderRecent();
+warmPdfjs();
setupOffline(openFile);
(() => { // reopen the PDF after a reload; typing or clicking the address shows the start screen
const nav = performance.getEntriesByType && performance.getEntriesByType('navigation')[0];
diff --git a/app/report/index.html b/app/report/index.html
index fd2f1e4..e664a2d 100644
--- a/app/report/index.html
+++ b/app/report/index.html
@@ -98,7 +98,7 @@
Is OverBoard not working on your board?
If something doesn't work the way the page asks, that's fine. That's exactly what I need to know. Just keep going.
Nothing is sent until you press Send at the very end, and you'll see everything first. No worksheets, PDFs or ink are ever included.