Skip to content

docs(webpack): document sandboxed preload default for Forge 7.x#261

Merged
erickzhao merged 2 commits into
v6from
docs/webpack-preload-sandbox-3659
Jul 2, 2026
Merged

docs(webpack): document sandboxed preload default for Forge 7.x#261
erickzhao merged 2 commits into
v6from
docs/webpack-preload-sandbox-3659

Conversation

@claude

@claude claude Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Requested by Samuel Attard · Slack thread

Fixes electron/forge#3659.

Before / After

Before: The Webpack Plugin page showed how to attach a preload script to an entry point and how to consume the *_PRELOAD_WEBPACK_ENTRY global, but said nothing about how preload scripts are compiled. A reader upgrading from Forge 6 to 7 whose preload used require or other Node.js APIs would find it silently broken with no explanation, and no guidance on how to fix it.

After: The page gains a dedicated "Preload scripts" section that tells the reader:

  • Since Electron 20 (and by default in Forge 7.x), preload scripts are sandboxed — the plugin compiles them with the sandboxedPreload webpack target, so require, process, and Node core modules are unavailable, and the recommended pattern is contextBridge.
  • This is a behavior change from Forge 6, called out with a warning hint for upgraders.
  • How to opt back into full Node.js access when needed: either set nodeIntegration: true on the window entry point (switching the preload to the electronPreload target), or declare a standalone preload-only entry point with its own nodeIntegration: true.
  • How the preload global is named for a preload-only entry point (<NAME>_PRELOAD_WEBPACK_ENTRY), with a worked example matching what users hit in the issue.

How

I confirmed current 7.x behavior against packages/plugin/webpack in electron/forge: WebpackConfig.ts derives the preload target as (entry.nodeIntegration ?? rendererOptions.nodeIntegration) ? 'electronPreload' : 'sandboxedPreload', and Config.ts defines nodeIntegration on the base entry-point interface (not on the preload object) plus a WebpackPluginEntryPointPreloadOnly type. The new section documents exactly this. Docs-only change to config/plugins/webpack.md; electron-markdownlint and lint-roller-markdown-standard both pass locally.


Generated by Claude Code

claude added 2 commits July 1, 2026 05:59
Preload scripts are compiled with the sandboxedPreload webpack target by
default (Electron 20+ / Forge 7.x), which removes Node.js access. Add a
"Preload scripts" section explaining this behavior change from 6.x and how
to opt into full Node.js access via nodeIntegration or a preload-only entry
point.

Fixes electron/forge#3659

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8emyk2ZfnUyZyQpfRBmYc
The "You have two options" line only presented one clearly-headed option;
the preload-only entry point was buried in a paragraph under the first
option's heading. Split into two numbered subsections: (1) nodeIntegration
on the window entry point, and (2) a preload-only entry point.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J8emyk2ZfnUyZyQpfRBmYc
@MarshallOfSound MarshallOfSound marked this pull request as ready for review July 1, 2026 06:32
@erickzhao erickzhao merged commit ab9a522 into v6 Jul 2, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Documentation for Webpack preload Scripts Is Not Correct

3 participants