Skip to content

Load workers via blob workaround

Latest
Compare
Choose a tag to compare
@Birch-san Birch-san released this 09 Jan 00:40
· 1 commit to main since this release

If (for example on codepen) you're having trouble instantiating web workers across origins, try this workaround:

import Box2DFactory from 'box2d3-wasm';
const box2d = await Box2DFactory({
  loadWorkerViaBlob: true
});

it will load the js cross-origin, create a blob URL for it, then instantiate the blob same-origin. this may help you work around the lack of COOP/COEP response headers, provided you can at least retrieve the asset cross-origin (which CDNs are likely to support).