Skip to content

fix: polyfill pdf.js map upsert methods for engines before Firefox 144 - #1617

Open
WSHAPER wants to merge 1 commit into
nextcloud:masterfrom
WSHAPER:fix/esr140-legacy-pdfjs
Open

WSHAPER wants to merge 1 commit into
nextcloud:masterfrom
WSHAPER:fix/esr140-legacy-pdfjs

Conversation

@WSHAPER

@WSHAPER WSHAPER commented Nov 5, 2026 •

Copy link
Copy Markdown

Fixes #1616

The modern pdf.js build calls the Map and WeakMap upsert methods (getOrInsert, getOrInsertComputed) that Firefox ships from version 144 on, so the viewer failed to initialize on Firefox ESR 140, the current enterprise ESR release, which is part of the browser targets of @nextcloud/browserslist-config.

Instead of changing which pdf.js build is shipped, a small module now defines the four methods when the engine lacks them:

  • in the viewer page it is loaded as the first module script, before the pdf.js modules, covering every pdf.js context of the page,
  • the same source is prepended to the vendored worker file at build time, because the worker runs in its own context,
  • the scripting sandbox needs nothing: it evaluates an embedded source string inside its own QuickJS WASM engine.

The modern pdf.js artifacts themselves stay byte-identical to the upstream release, so the served pdf.js code, its security posture and its printing behavior are unchanged; on engines with native support the polyfill stays completely idle.

The suite covers the shim semantics, asserts the byte-identity of the untouched artifacts and the exact worker prepend, and fails if the vendored pdf.js ever calls a collection builtin that is neither polyfilled nor old enough for the supported browsers.

Testing: npm run test (39 passed), npm run lint, npm run stylelint, npm run build all green.

This change was prepared with AI assistance (opencode, zai/glm-5.3) and reviewed by the contributor.

@WSHAPER
WSHAPER requested a review from CarlSchwan November 5, 2026 12:51
The modern pdf.js build requires Map and WeakMap upsert methods
(getOrInsert and getOrInsertComputed) that Firefox ships from version
144 on, so the viewer failed to initialize on Firefox ESR 140, the
current enterprise ESR release, even though Firefox ESR is part of the
browser targets of @nextcloud/browserslist-config.

A small polyfill module now defines the four methods when missing. It
is loaded as the first module script in the viewer page, so every pdf.js
context of the page is covered, and the same source is prepended to the
vendored worker file at build time, as the worker runs in its own
context. The pdf.sandbox module needs no shim: it only feeds an embedded
source string to its own QuickJS engine. The modern pdf.js artifacts
themselves stay byte-identical to the upstream release, so nothing
changes for engines that ship the methods natively.

The test suite covers the shim semantics, the byte-identity of the
untouched artifacts, the worker prepend, and fails when the vendored
pdf.js calls a new collection builtin that is neither polyfilled nor old
enough for the supported browsers.

Fixes nextcloud#1616

Assisted-by: opencode (zai/glm-5.3)
Signed-off-by: WSHAPER <42714629+WSHAPER@users.noreply.github.com>
@WSHAPER
WSHAPER force-pushed the fix/esr140-legacy-pdfjs branch from 6680907 to 38f516f Compare November 5, 2026 13:37
@WSHAPER WSHAPER changed the title fix: serve the pdf.js legacy build for browsers without getOrInsertComputed fix: polyfill pdf.js map upsert methods for engines before Firefox 144 Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PDFs do not render in Firefox ESR 140, PDF.js modern build requires getOrInsertComputed (Firefox 144+)

1 participant