Repository navigation
fix: load locales without connect-src blob: and fall back to English - #69
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #68.
Setting
localemade the element wrap PDF.js's locale map in ablob:URL, so a host page with a Content Security Policy had to allowconnect-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.fetchDatabetween loadingpdf.mjsandviewer.mjs; the viewer readsfetchDatafrompdfjsLibonce, when it loads, and uses it only for its locale:application/l10nlink is answered from memory, so noblob:(ordata:) request is made. The link keeps adata:href so a viewer that doesn't usepdfjsLib.fetchDatastill finds a valid map.console.warn, and PDF.js falls back to its built-in English strings.locale-src-templateand the public API are unchanged; only private members changed intypes/. Docs follow inmissing-elements.github.io(Localization sentence onconnect-srcand a migration note for droppingblob:), 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 underconnect-src 'self'with neitherblob:nordata:, and the English fallback when the locale file's host is blocked. Both failed onmaster(titlenull, blank controls).pnpm exec tscclean,vite buildandscripts/copy-worker.mjsOK,types/regenerated.dist/served statically (no Vite) under a host CSP withoutblob:, in Chromium, Firefox and WebKit: German labels, 0 of 261 labelled controls unlabelled, noblob:violations; blocked or 404.ftl→ English with the warning; runtime switch de → fr works.pnpm packoutput, vendored.ftlimported with?urland its hashed asset URL passed tolocale-src-template: same results in all three browsers.Checklist
🤖 Generated with Claude Code