最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to enable sharedArrayBuffer in chrome without cross-origin isolation - Stack Overflow

programmeradmin3浏览0评论

I have this experiment which I only run on my local machine: I load an external webpage from, for example 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 mand 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!

I have this experiment which I only run on my local machine: I load an external webpage from, for example https://example. 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 mand 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!

Share Improve this question asked Dec 27, 2021 at 15:39 Jeanluca ScaljeriJeanluca Scaljeri 29.2k66 gold badges235 silver badges382 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 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!

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

There are lots of mand 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.

  • See @ https://peter.sh/experiments/chromium-mand-line-switches/

If you're looking a specific mand 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.

发布评论

评论列表(0)

  1. 暂无评论