However, there's two additional strategies, running inside an <iframe> (browser-window) or running a Worker inside an <iframe> (browser-worker). The reason to do this is that a Worker by itself cannot have a different CSP than the parent, but using a frame allows this. It also allows sandboxing in scenarios where workers are disabled but frames aren't.
It appears that, when an <iframe> is involved, the library fails. This is disappointing as I was recently working on a utility to encrypt files and showcase sandboxing that would like to have as wide compatibility as possible.
The error that I get, 'Timed out setting up sandbox', without anything else, would seem to indicate an error while setting things up, possibly preventing the iframe script from executing, although the debugger doesn't seem to show anything is amiss.
The following is a snippet that can be run in the console to test.
Code: Select all
// Strategy: iframe + Worker with 'just' iframe fallback
(async ()=>await (await (await import('https://esm.sh/@exact-realty/lot')).default('exports.foo="bar"'))('foo'))().then((r) => console.log('ok', r), (e) => console.error('err', e));
// Result: error
Code: Select all
// Strategy: bare
(async ()=>await (await (await import('https://esm.sh/@exact-realty/lot/bare')).default('exports.foo="bar"'))('foo'))().then((r) => console.log('ok', r), (e) => console.error('err', e));
// Result: ok
Code: Select all
// Strategy: Worker
(async ()=>await (await (await import('https://esm.sh/@exact-realty/lot/worker')).default('exports.foo="bar"'))('foo'))().then((r) => console.log('ok', r), (e) => console.error('err', e));
// Result: ok
Code: Select all
// Strategy: iframe + Worker
(async ()=>await (await (await import('https://esm.sh/@exact-realty/lot/browser-worker')).default('exports.foo="bar"'))('foo'))().then((r) => console.log('ok', r), (e) => console.error('err', e));
// Result: error
Code: Select all
// Strategy: iframe
(async ()=>await (await (await import('https://esm.sh/@exact-realty/lot/browser-window')).default('exports.foo="bar"'))('foo'))().then((r) => console.log('ok', r), (e) => console.error('err', e));
// Result: error
All of the snippets work well on Firefox. I can also provide an example site that's broken because of this, although the snippets above should be enough to reproduce the issue. I'm happy to help providing more information and testing.