Unable to disable WebSecurity (or set any web preferences) #413

Closed
opened 2026-01-29 16:38:58 +00:00 by claunia · 6 comments
Owner

Originally created by @ddaspit on GitHub (Nov 29, 2019).

Originally assigned to: @GregorBiswanger on GitHub.

  • Version: 5.30.1
  • Target: Windows

When you create a browser window with WebSecurity set to false, it doesn't work. This seems to occur, because in browserWindows.ts, the createBrowserWindow handler only performs a shallow merge when merging the options parameter in order to set nodeIntegration to true. This results in the entire webPreferences object being overwritten.

Steps to Reproduce:
This can be reproduced using the Electron.NET music player sample app.

  1. Start the music player app.
  2. Play a music file.
  3. Nothing happens. An error appears in the console.
Originally created by @ddaspit on GitHub (Nov 29, 2019). Originally assigned to: @GregorBiswanger on GitHub. <!-- Please search existing issues to avoid creating duplicates. --> <!-- Which version of Electron.NET CLI and API are you using? --> <!-- Please always try to use latest version before report. --> * **Version**: 5.30.1 <!-- Which version of .NET Core and Node.js are you using (if applicable)? --> <!-- What target are you building for? --> * **Target**: Windows <!-- Enter your issue details below this comment. --> <!-- If you want, you can donate to increase issue priority (https://donorbox.org/electron-net) --> When you create a browser window with `WebSecurity` set to `false`, it doesn't work. This seems to occur, because in `browserWindows.ts`, the `createBrowserWindow` handler only performs a shallow merge when merging the `options` parameter in order to set `nodeIntegration` to `true`. This results in the entire `webPreferences` object being overwritten. Steps to Reproduce: This can be reproduced using the [Electron.NET music player sample app](https://github.com/ElectronNET/electron.net-musicplayer-sample). 1. Start the music player app. 2. Play a music file. 3. Nothing happens. An error appears in the console.
claunia added the bug label 2026-01-29 16:38:58 +00:00
Author
Owner

@GregorBiswanger commented on GitHub (Dec 3, 2019):

The music player app is still based on an old Electron.NET version. I have to update this somehow. I tried a new example with the current Electron.NET 7.30.2 version and it worked without problems. I have access to files and can play them.

I used the same code snippets from:
http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core/

@GregorBiswanger commented on GitHub (Dec 3, 2019): The music player app is still based on an old Electron.NET version. I have to update this somehow. I tried a new example with the current Electron.NET 7.30.2 version and it worked without problems. I have access to files and can play them. I used the same code snippets from: http://www.cross-platform-blog.com/electron.net/electron.net-musicplayer-app-with-asp.net-core/
Author
Owner

@ddaspit commented on GitHub (Dec 4, 2019):

I forked the music player sample app and updated it to 7.30.2. The master branch demonstrates the issue. When I click the play button, it does not play and I receive the following error in the console:

(index):1 Not allowed to load local resource: file:///C:/Users/user/Music/music.mp3
(index):1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.

When I paste the file URL directly into Chrome, it plays correctly.

@ddaspit commented on GitHub (Dec 4, 2019): I forked the [music player sample app](https://github.com/ddaspit/electron.net-musicplayer-sample) and updated it to 7.30.2. The master branch demonstrates the issue. When I click the play button, it does not play and I receive the following error in the console: ``` (index):1 Not allowed to load local resource: file:///C:/Users/user/Music/music.mp3 (index):1 Uncaught (in promise) DOMException: Failed to load because no supported source was found. ``` When I paste the file URL directly into Chrome, it plays correctly.
Author
Owner

@jlcool commented on GitHub (Feb 4, 2020):

Is there any progress on this issue

@jlcool commented on GitHub (Feb 4, 2020): Is there any progress on this issue
Author
Owner

@duncanawoods commented on GitHub (Feb 6, 2020):

This is also a problem for me. I've just had to rewrite a bunch of things to serve up local files via the http server as a work-around which shouldn't be necessary.

Possibly related to this?

https://github.com/electron/electron/issues/19846

@duncanawoods commented on GitHub (Feb 6, 2020): This is also a problem for me. I've just had to rewrite a bunch of things to serve up local files via the http server as a work-around which shouldn't be necessary. Possibly related to this? https://github.com/electron/electron/issues/19846
Author
Owner

@syedadeel2 commented on GitHub (Mar 2, 2020):

That is correct!! if I set the nodeIntegration = false its works

WebPreferences = new WebPreferences { WebSecurity = false, AllowRunningInsecureContent = true, ExperimentalCanvasFeatures=true, ScrollBounce=true, NodeIntegration = false }

@syedadeel2 commented on GitHub (Mar 2, 2020): That is correct!! if I set the nodeIntegration = false its works ` WebPreferences = new WebPreferences { WebSecurity = false, AllowRunningInsecureContent = true, ExperimentalCanvasFeatures=true, ScrollBounce=true, NodeIntegration = false }`
Author
Owner

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

Works with the new Electron.NET 8.31.1.

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

No dependencies set.

Reference: starred/Electron.NET#413