Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
Yuvix25 wants to merge1 commit intoElectronNET:main
base:main
Choose a base branch
Loading
fromYuvix25:main

Conversation

Yuvix25
Copy link
Contributor

I've encountered the following error: "Error: contextBridge API can only be used when contextIsolation is enabled", even though I did enableContextIsolation.

In#411, the same issue was reported, and the problem was traced down to the fact that the default value ofContextIsolation was set to the wrong value, which made that attribute un-editable.

I then found out that the default value ofContextIsolation was changed from false to true since Electron 12, as notedhere, so I fixed it.

@GregorBiswanger
Copy link
Member

Thanks for your PR! Have you checked whether the IPC communication is still working afterwards?

@Yuvix25
Copy link
ContributorAuthor

Not yet. Watching the "Contributing Getting Started" video as we speak.
Will update once I do 👍🏻

GregorBiswanger reacted with heart emoji

@Yuvix25
Copy link
ContributorAuthor

@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?

@GregorBiswanger
Copy link
Member

We changed the default value totrue in the past. Electron already has it set tofalse 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.

@Yuvix25
Copy link
ContributorAuthor

Yuvix25 commentedJun 20, 2023
edited
Loading

These are theWebPrefrences I'm using:

WebPreferences=newWebPreferences(){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:2node: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 totrue now. See the link I posted in the original comment.

@Yuvix25
Copy link
ContributorAuthor

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?

@Yuvix25
Copy link
ContributorAuthor

@GregorBiswanger any idea?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Yuvix25@GregorBiswanger

[8]ページ先頭

©2009-2025 Movatter.jp