I have an electron app. My client script (renderer) needs to access electron APIs, but this gave me a security warning, so I moved it into a preload script and disabled nodeIntegration. I was then receiving a warning about contextIsolation, so I enabled it. My preload script was previously attaching a function to window that the client could read as follows:
window.readClipboard = function(){
return clipboard.readText()
}
Unfortunately, context isolation meant that the client could no longer access this function. Is there a way to make this work with context isolation or should I disable it?
Extra Details
The warning message that made me try to turn on context isolation was the following:
Electron Deprecation Warning (contextIsolation default change) This window has context isolation disabled by default. In Electron 5.0.0, context isolation will be enabled by default. To prepare for this change, set {contextIsolation: false} in the webPreferences for this window, or ensure that this window does not rely on context isolation being disabled, and set {contextIsolation: true}.
In client.js I try accessing:
console.log("window.readClipboard", window.readClipboard)
With output:
window.readClipboard undefined
clipboardobject from the renderer process ? - 0.shrequire("electron").remote.clipboardfrom the renderer process ? - 0.sh