Use ShareArrayBuffer from an electron app

1.4k views Asked by At

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,

2

There are 2 answers

4
Harunobu Oyama On

It can be enabled by adding the following line in background.js

app.commandLine.appendSwitch('enable-features','SharedArrayBuffer')

Reference

0
Gillespie On

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 });
    });