Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use ShareArrayBuffer from an electron app

We have an electron app which uses ShareArrayBuffer. It was written with a very old version of electron. When we updated the electron version in order to use SIMD instructions in WASM, it started showing an error saying ShareArrayBuffer is not defined. It seems it is due to the security update in Chromeum and ShareArrayBuffer is available iff Cross Origin Isolation is set.

Google shows some articiles explaining how to enable Cross Origin Isolation on web-pages, but I have not found any article that explains how to do that on an electron app. Does anyone have a pointer to the info or an idea to try?

Thank you,

like image 794
Harunobu Oyama Avatar asked Aug 29 '26 15:08

Harunobu Oyama


1 Answers

As of December 2022, this is the only thing that worked for me:

    browserWindow = new BrowserWindow({...});

    // Enable SharedArrayBuffer
    browserWindow.webContents.session.webRequest.onHeadersReceived((details, callback) => {
        details.responseHeaders['Cross-Origin-Opener-Policy'] = ['same-origin'];
        details.responseHeaders['Cross-Origin-Embedder-Policy'] = ['require-corp'];
        callback({ responseHeaders: details.responseHeaders });
    });
like image 74
Gillespie Avatar answered Sep 03 '26 20:09

Gillespie



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!