ElectronNET.API.Entities.WebPreferences.ContextIsolation [DefaultValue(true)] #498

Closed
opened 2026-01-29 16:41:09 +00:00 by claunia · 1 comment
Owner

Originally created by @freosc on GitHub (May 21, 2020).

Originally assigned to: @GregorBiswanger on GitHub.

I tested using Electron.net API and CLI 8.31.2
ElectronJS lists the WebPreferences.ContextIsolation default value as false ([https://www.electronjs.org/docs/api/browser-window]).

ElectronNet API decorates the WebPreferences.ContextIsolation property with [DefaultValue(true)] which results in not setting this value in WindowManager.CreateWindowAsync when serializing "options" to a Json object.

This is my ElectronBootstrap code:

BrowserWindowOptions options = new BrowserWindowOptions() {
                Kiosk = true,
                AutoHideMenuBar = true,
                TitleBarStyle = TitleBarStyle.hidden,
                WebPreferences = new WebPreferences {
                    NodeIntegration = false,
                    ContextIsolation = true, // protect against prototype pollution
                    Preload = System.IO.Path.Join(AppDomain.CurrentDomain.BaseDirectory, "preload.js") 
                }
            };

doing so, results in this error in the browser:

init.ts:207 Error: contextBridge API can only be used when contextIsolation is enabled
at checkContextIsolationEnabled (context-bridge.ts:7)
at Object.exposeInMainWorld (context-bridge.ts:12)

When I remove the [DefaultValue(true)] decorator of the ContextIsolation property in the ElectronNet.Api, it seems to work as expected.

Originally created by @freosc on GitHub (May 21, 2020). Originally assigned to: @GregorBiswanger on GitHub. I tested using Electron.net API and CLI 8.31.2 ElectronJS lists the WebPreferences.ContextIsolation default value as false ([https://www.electronjs.org/docs/api/browser-window]). ElectronNet API decorates the WebPreferences.ContextIsolation property with [DefaultValue(true)] which results in not setting this value in WindowManager.CreateWindowAsync when serializing "options" to a Json object. This is my ElectronBootstrap code: ``` BrowserWindowOptions options = new BrowserWindowOptions() { Kiosk = true, AutoHideMenuBar = true, TitleBarStyle = TitleBarStyle.hidden, WebPreferences = new WebPreferences { NodeIntegration = false, ContextIsolation = true, // protect against prototype pollution Preload = System.IO.Path.Join(AppDomain.CurrentDomain.BaseDirectory, "preload.js") } }; ``` doing so, results in this error in the browser: > init.ts:207 Error: contextBridge API can only be used when contextIsolation is enabled > at checkContextIsolationEnabled (context-bridge.ts:7) > at Object.exposeInMainWorld (context-bridge.ts:12) When I remove the [DefaultValue(true)] decorator of the ContextIsolation property in the ElectronNet.Api, it seems to work as expected.
claunia added the bug label 2026-01-29 16:41:09 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (May 21, 2020):

Fixed with the Electron.NET 8.31.3

@GregorBiswanger commented on GitHub (May 21, 2020): Fixed with the Electron.NET 8.31.3
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/Electron.NET#498