-
-
Couldn't load subscription status.
- Fork 736
Update WebPreferences's ContextIsolation default value to true #785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thanks for your PR! Have you checked whether the IPC communication is still working afterwards?
Not yet. Watching the "Contributing Getting Started" video as we speak.
Will update once I do 👍🏻
@GregorBiswanger I compiled it on my side, with the default value now being set to true, but I still get that error for some reason. Any idea what could be the cause?
We changed the default value to true in the past. Electron already has it set to false for security reasons. However, we need it for the internal communication of our .NET API to the native Electron API. So I thought you found a solution with your PR.
Without an error message, I can't help you as to what your problem might be.
These are the WebPrefrences I'm using:
WebPreferences = new WebPreferences() { ContextIsolation = true, EnableRemoteModule = true, NodeIntegration = true, Preload = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "js", "utils.js"), }
And this is the error I'm receiving:
node:electron/js2c/renderer_init:2 Unable to load preload script: C:\Users\[username]\[path-to-project]\obj\Host\bin\wwwroot\js\utils.js
(anonymous) @ node:electron/js2c/renderer_init:2
node:electron/js2c/renderer_init:2 Error: contextBridge API can only be used when contextIsolation is enabled
at checkContextIsolationEnabled (node:electron/js2c/renderer_init:2:5653)
at Object.exposeInMainWorld (node:electron/js2c/renderer_init:2:5764)
at Object.<anonymous> (C:\Users\[username]\[path-to-project]\obj\Host\bin\wwwroot\js\utils.js:441:15)
at Object.<anonymous> (C:\Users\[username]\[path-to-project]\obj\Host\bin\wwwroot\js\utils.js:457:3)
at Module._compile (node:internal/modules/cjs/loader:1174:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1229:10)
at Module.load (node:internal/modules/cjs/loader:1044:32)
at Module._load (node:internal/modules/cjs/loader:885:12)
at f._load (node:electron/js2c/asar_bundle:2:13330)
at o._load (node:electron/js2c/renderer_init:2:3109)
Also, they did change the default value to true now. See the link I posted in the original comment.
Maybe I need to remove <PackageReference Include="ElectronNET.API" Version="23.6.1" /> from the [project-name].csproj file? Or perhaps replace it with something local?
@GregorBiswanger any idea?
I've encountered the following error: "Error: contextBridge API can only be used when contextIsolation is enabled", even though I did enable
ContextIsolation.In #411, the same issue was reported, and the problem was traced down to the fact that the default value of
ContextIsolationwas set to the wrong value, which made that attribute un-editable.I then found out that the default value of
ContextIsolationwas changed from false to true since Electron 12, as noted here, so I fixed it.