Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/Using/Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,26 @@ BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
```


### Preload Script

If you require the use of a [preload script](https://www.electronjs.org/docs/latest/tutorial/tutorial-preload), you can specify the file path of the script when creating a new window like so:

```csharp
WebPreferences wp = new WebPreferences();
wp.Preload = "path/to/preload.js";
BrowserWindowOptions browserWindowOptions = new BrowserWindowOptions
{
WebPreferences = wp
};
```

> [!IMPORTANT]
> When using a preload script _AND_ running a Blazor app, the following lines must be added to the preload script:
> ```js
> global.process = undefined;
> global.module = undefined;
> ```


## 🚀 Next Steps

Expand Down
4 changes: 2 additions & 2 deletions src/ElectronNET.Host/api/browserWindows.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/ElectronNET.Host/api/browserWindows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export = (socket: Socket, app: Electron.App) => {
};
}

if (options.isRunningBlazor) {
options.webPreferences["preload"] = path.join(
if (options.isRunningBlazor && !options.webPreferences.preload) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not make sense as isRunningBlazor only exists for this.

The warning should be printed that a preload script will be ignored if isRunningBlazor is set. The option, which has been turned on explicitly, should always have preference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me, I'll update the note in the documentation to reflect this.

options.webPreferences.preload = path.join(
__dirname,
"..",
"scripts",
Expand Down