balmjs / template-electron

An Electron project for desktop apps

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is balm compatible with electron context isolation?

grctest opened this issue · comments

commented

I'm trying to use balmjs in an electron app, following the best practices implementing context isolation:
https://www.electronjs.org/docs/latest/tutorial/security#3-enable-context-isolation

I see that this template has browserwindow web preferences 'nodeIntegration' set to true: https://github.com/balmjs/template-electron/blob/master/templates/app/desktop/main.js#L16

Since this template isn't following the electron security best practices, is that a known limitation of the balm ui?

My electron browserwindow is configured as so:

webPreferences: {
            nodeIntegration: false,
            contextIsolation: true,
            enableRemoteModule: false,
            preload: path.join(__dirname, "preload.js"),
}

Which results in an error like the following:

external commonjs "balm-ui":1 Uncaught ReferenceError: require is not defined
    at balm-ui (external commonjs "balm-ui":1:1)
    at __webpack_require__ (bootstrap:19:1)

I'm going to try adding the individual balm js/css files instead of the whole BalmUI in the vue createapp, will report back with results.

Hi @grctest , thanks for your issue.

If used in server-side rendering, BalmUI plus's ui-editor component may indeed have some issues due to internal references to quill, 8.x is fine, 10.x should be a bit problematic.

But I have tested the ui-button and ui-editor components in vue 2 + BalmUI 8.x and vue 3 + BalmUI 10.x projects respectively, and for the time being, I have not reproduced the problem you describe, could you please show me your specific code? Maybe we can work it out together.

commented

I'm not using server side rendering, but rather am implementing a context isolated & node integration disabled electron desktop application using balm-ui and vue3.

Here's my renderer webpack: https://github.com/beetapp/beeteos/blob/reintroduce/build/webpack.renderer.config.js

I seem to have had some luck with just adding packages to the nodeExternals allowlist, however that stopped helping with error messages when adding electron threw node path/fs errors, doesn't seem to be the right solution.

I feel that perhaps the issue lies in webpack misconfiguration? Does anything stand out in the linked webpack config to you?

Thanks for helping out :)

commented

I've just successfully gotten past the webpack hurdle I had encountered, I added multiple packages to the nodeExternals allowlist and also sorted out some other issues to do with context isolation. Thanks for responding and pointing me in the right direction