How to enable sharedArrayBuffer in chrome without cross-origin isolation
Asked Answered
L

2

4

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!

Lais answered 27/12, 2021 at 15:39 Comment(0)
L
5

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!

Lais answered 27/12, 2021 at 17:6 Comment(2)
This doesn't work for me on MacOs, maybe because it's no longer an experimental feature. Maybe I'd haver better luck on Linux Mint.Alliteration
doesn't work for me tooPals
B
1

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.

Barclay answered 27/12, 2021 at 16:28 Comment(1)
I think that most of the things like this are ok as long as they are only on your local machine (localhost). I just found this option --enable-features=SharedArrayBuffer which solves the issue! Thnx!Lais

© 2022 - 2024 — McMap. All rights reserved.