Ipc in renderer with sandbox: true, contextIsolation: true, nodeIntegration: false

Hi! How to organize communication between renderer with contextIsolation: true and main process?

As far as I understand it’s not possible to attach additional methods to the window object inside preload script in according to this pr https://github.com/electron/electron/pull/15738 and related issues.

However it works in this example https://github.com/carlosperate/electron-sandbox/blob/014014a35e439cfcb535cd35b7bd925f334bb35c/sandbox-extended/preload-extended.js#L55 but I suppose it uses old electron and this way is obsolete.

The only thing that seems to work is send messages through the window.postMessage, receive them in preload script with window.addEventListener("message") and redirect this message futher through the IPC to the main process.

What’s the best practice? Thanks.