javascriptgoogle-chromepuppeteerwebassemblysharedarraybuffer

How to enable sharedArrayBuffer in chrome without cross-origin isolation


I have this experiment which I only run on my local machine: I load an external webpage from, for example https://example.com and the with puppeteer I inject a javascript file which is served from http://localhost:5000.

So far there are no issues. But, this injected javascript file loads a WebAssembly file and then I get the following error

Uncaught (in promise) ReferenceError: SharedArrayBuffer is not defined
....

And indeed, SharedArrayBuffer is not defined (Chrome v96) with the result that my code is not working at all (It used to work though). So my question is, how can I solve this error?

Reading more about this, it seems that you can add two headers

   res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
   res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');

which I did for both files without much success. Maybe this will not work given that the page is from a different domain than the injected js and WASM files.

But maybe there is an other solution possible. Here is my command to start chrome

      client.browser = await puppeteer.launch({
        headless: false,
        devtools: true,
        defaultViewport: null,
        executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome',
        args: [
            '--debug-devtools',
            '--no-sandbox',
            '--disable-setuid-sandbox',
            '--disable-web-security',
            '--allow-running-insecure-content',
            '--disable-notifications',
            '--window-size=1920,1080'
        ]
        //slowMo: 500
    });

I know chrome has too many options, so maybe there is an option for this SharedArrayBuffer issue as well?

Hope someone knows how this works and can help me, Thnx a lot!


Solution

  • In this thread someone suggested to start chrome as follows

    $> chrome --enable-features=SharedArrayBuffer 
    

    meaning I can add --enable-features=SharedArrayBuffer to my puppeteer config!