Home > Blockchain >  How to enable sharedArrayBuffer in chrome without cross-origin isolation
How to enable sharedArrayBuffer in chrome without cross-origin isolation

Time:12-28

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!

CodePudding user response:

Peter Beverloo made an extensive list of Chromium command line switches on his blog a while back.

There are lots of command lines which can be used with the Google Chrome browser. Some change behavior of features, others are for debugging or experimenting. This page lists the available switches including their conditions and descriptions. Last automated update occurred on 2020-08-12.

If you're looking a specific command it will be there, give it a shot. Tho I'm pretty sure cross-origin restrictions were implemented specifically to prevent what you're trying to do.

CodePudding user response:

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!

  • Related