Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions extension/lib/streams-firefox-fix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// ©️ 2016 - present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
// Firefox content-script sandbox workaround.
//
// In the Firefox content-script isolated world, `ReadableStream`/`TransformStream` are Xray
// wrappers of the page's native implementations. Constructing them with a source object from
// the sandbox realm throws `Permission denied to access property "autoAllocateChunkSize"`
// (https://bugzilla.mozilla.org/show_bug.cgi?id=1757836), which broke openpgp.js's compressed
// packet (zip/zlib) decompression with `MalformedPacketError: Parsing CompressedDataPacket failed`.
//
// This script must run BEFORE the web-streams-polyfill script (both loaded before /lib/openpgp.js):
// 1. It hides the native CompressionStream/DecompressionStream globals so that openpgp.js
// (loaded next) selects its bundled fflate JS fallback instead of
// `stream.pipeThrough(native DecompressionStream)`, which fails the web-streams-polyfill's
// brand checks.
// 2. The web-streams-polyfill script then installs its own same-realm ReadableStream/
// WritableStream/TransformStream implementations on the sandbox global, so all stream objects
// created by openpgp.js and web-stream-tools live in a single realm and work as expected.
if (typeof globalThis.CompressionStream !== 'undefined') {
globalThis.CompressionStream = undefined;
}
if (typeof globalThis.DecompressionStream !== 'undefined') {
globalThis.DecompressionStream = undefined;
}
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@
"linkifyjs": "4.3.3",
"node-forge": "1.4.0",
"squire-rte": "2.4.8",
"sweetalert2": "11.26.25"
"sweetalert2": "11.26.25",
"web-streams-polyfill": "3.3.3"
},
"scripts": {
"build": "npm run symlink-core && node ./scripts/build.js",
Expand Down
3 changes: 3 additions & 0 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ const copyDependencies = async () => {
// Reference: https://github.com/mozilla/pdf.js/issues/18006#issuecomment-2078739672
['pdfjs-dist/legacy/build/pdf.min.mjs', 'lib/pdf.min.mjs'],
['pdfjs-dist/legacy/build/pdf.worker.min.mjs', 'lib/pdf.worker.min.mjs'],
// polyfill Web Streams in the Firefox content-script sandbox, see
// https://bugzilla.mozilla.org/show_bug.cgi?id=1757836
['web-streams-polyfill/dist/polyfill.min.js', 'lib/web-streams-polyfill.min.js'],
['bootstrap/dist/js/bootstrap.min.js', 'lib/bootstrap/bootstrap.min.js'],
['bootstrap/dist/css/bootstrap.min.css', 'lib/bootstrap/bootstrap.min.css'],
];
Expand Down
9 changes: 9 additions & 0 deletions tooling/build-types-and-manifests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ addManifest('firefox-consumer', manifest => {
strict_min_version: '112.0', // eslint-disable-line @typescript-eslint/naming-convention
},
};
// Web Streams are broken in the Firefox content-script sandbox (Permission denied to access
// property "autoAllocateChunkSize" - https://bugzilla.mozilla.org/show_bug.cgi?id=1757836).
// Load the streams-fix shim + web-streams-polyfill BEFORE openpgp.js, so that stream objects
// created by openpgp.js / web-stream-tools live in a single (sandbox) realm.
// This is only needed in the content script: extension pages and the service worker are
// privileged and keep using the native implementations.
for (const csDef of manifest.content_scripts ?? []) {
csDef.js = ['/lib/streams-firefox-fix.js', '/lib/web-streams-polyfill.min.js', ...(csDef.js ?? [])];
}
manifest.background = {
type: 'module',
scripts: ['/js/service_worker/background.js'],
Expand Down
Loading