Skip to content

fix: load locales without connect-src blob: and fall back to English - #69

Merged
alekswebnet merged 1 commit into
masterfrom
fix/locale-without-blob
Oct 30, 2026
Merged

alekswebnet merged 1 commit into
masterfrom
fix/locale-without-blob

Conversation

@alekswebnet

Copy link
Copy Markdown
Collaborator

Summary

Closes #68.

Setting locale made the element wrap PDF.js's locale map in a blob: URL, so a host page with a Content Security Policy had to allow connect-src blob:. And whenever the locale file itself couldn't be loaded (404, a CDN the CSP blocks, offline), PDF.js left every control without text, tooltip or accessible name instead of falling back to English.

The element now wraps pdfjsLib.fetchData between loading pdf.mjs and viewer.mjs; the viewer reads fetchData from pdfjsLib once, when it loads, and uses it only for its locale:

  • The locale map named by the application/l10n link is answered from memory, so no blob: (or data:) request is made. The link keeps a data: href so a viewer that doesn't use pdfjsLib.fetchData still finds a valid map.
  • A locale file that fails to load returns an empty file with a console.warn, and PDF.js falls back to its built-in English strings.
  • Every other URL passes through unchanged.

locale-src-template and the public API are unchanged; only private members changed in types/. Docs follow in missing-elements.github.io (Localization sentence on connect-src and a migration note for dropping blob:), to merge after the release.

Validation

  • pnpm test -- --run: 31 passed (Firefox). Two new tests mount the viewer in a frame with its own page CSP: German labels under connect-src 'self' with neither blob: nor data:, and the English fallback when the locale file's host is blocked. Both failed on master (title null, blank controls).
  • pnpm exec tsc clean, vite build and scripts/copy-worker.mjs OK, types/ regenerated.
  • Production dist/ served statically (no Vite) under a host CSP without blob:, in Chromium, Firefox and WebKit: German labels, 0 of 261 labelled controls unlabelled, no blob: violations; blocked or 404 .ftl → English with the warning; runtime switch de → fr works.
  • Consumer-style Vite 8 app built from pnpm pack output, vendored .ftl imported with ?url and its hashed asset URL passed to locale-src-template: same results in all three browsers.

Checklist

  • The change is focused and includes tests for behavior changes.
  • Relevant tests and the build pass locally.
  • Public API, behavior, or user-guidance documentation is updated where needed (docs repo PR).
  • Accessibility impact has been considered: the change restores the labels and accessible names of the toolbar controls when the locale file fails; no markup, keyboard or focus changes.
  • This pull request does not disclose a security vulnerability.

🤖 Generated with Claude Code

@alekswebnet
alekswebnet merged commit 3b499f7 into master Oct 30, 2026
6 checks passed
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.

[Bug]: Locale map is fetched from a blob: URL and a failed locale file blanks all controls

1 participant