Open-source AI browser agent for Chrome and Firefox (monorepo) ðŸ§
pdfjs-dist (vendored)
Mozilla PDF.js, used by src/agent/pdf-tools.js to extract text from
PDFs the user is viewing in Firefox. Firefox's built-in PDF viewer is
itself a privileged page that our content scripts can't inject into,
so instead of scraping the viewer's DOM we fetch the PDF binary and
parse it with pdfjs in the background page.
Source
- Package:
pdfjs-distv5.7.284 - Upstream files:
build/pdf.mjs+build/pdf.worker.mjs(the modern build), byte-identical to the npm package - Origin: https://github.com/mozilla/pdf.js
- Upstream license: Apache-2.0 (see
LICENSEin this folder)
Files we add
compat.mjs: feature-detected polyfills for the few recent JavaScript methods the modern build calls without a fallback (Map/WeakMapgetOrInsertComputed,Math.sumPrecise,Uint8Arraybase64/hex,Response.prototype.bytes). Each one is installed only when the browser lacks it.index.mjs: page entry point. Loadscompat.mjs, then re-exportspdf.mjs.worker.mjs: worker entry point. Loadscompat.mjs, then re-exportspdf.worker.mjs, so the PDF.js worker gets the same polyfills.
Why the modern build
The legacy build bundles core-js, including old Internet Explorer fallbacks
(an ActiveX/iframe document.write path) that Chrome Web Store review rejects
as obfuscated code. The modern build contains no core-js at all. With
compat.mjs, PDF reading works on Chrome 128+ and Firefox 140+.
How it's loaded
pdf-tools.js does a lazy dynamic import on the first PDF read:
const pdfjs = await import(browser.runtime.getURL('vendor/pdfjs/index.mjs'));
The worker URL is resolved the same way:
pdfjs.GlobalWorkerOptions.workerSrc =
browser.runtime.getURL('vendor/pdfjs/worker.mjs');
The PDF.js entry points and modules are listed in manifest.json's
web_accessible_resources so browser.runtime.getURL returns a fetchable URL.
Updating
npm pack pdfjs-dist@latest(in any scratch directory).tar xzf pdfjs-dist-*.tgz package/build/pdf.mjs package/build/pdf.worker.mjs package/LICENSE- Move them over
pdf.mjs,pdf.worker.mjs,LICENSEhere. - Do not edit the upstream files. If the new version calls another recent
built-in without a fallback, add a feature-detected polyfill to
compat.mjsinstead. - Update the version line at the top of this README.
- Smoke-test by opening a real PDF tab in the loaded extension and
running a
read_pdffrom the side panel.
Keep parity with src/chrome/vendor/pdfjs/ — both extensions ship the
same pdfjs files. Don't try to bundle pdfjs through any build step;
the project ships extension source as-is.