Files
electron/docs
Sam Maddock 3c4e6463fc feat: preload script URL filters (#54903)
* feat: preload script URL filters

* feat: reject an empty preload script matches array

An explicit `matches: []` meant "every URL", the same ambiguity webRequest
filters dropped in favor of `<all_urls>`. Registering one now throws and
points at `<all_urls>`; omitting `matches` still matches every URL, so
existing registrations are unaffected.

Also adds coverage that `<all_urls>` matches both an http page and
about:blank.

* docs: link preload URL filters to MDN match patterns

Matches the webRequest filter docs, which already link to MDN.

* test: extension protocol

* feat: add matchOriginAsFallback to preload script URL filters

A document whose URL has no origin of its own (about:, blob:, data:,
filesystem:) was only matched by its literal URL, so an about:blank popup
escaped its opener's excludeMatches and excludeGlobs.

With matchOriginAsFallback, frame preloads match such documents by the
origin they inherited from their creator, like match_origin_as_fallback
for content scripts.

* fix: reject an empty preload script includeGlobs array

An explicitly empty includeGlobs array converted to the same state as an
omitted one, so the preload ran for every URL instead of none. Reject it
at registration, as an empty matches array already is.

* test: use vitest assertions in preload URL filter specs

main dropped chai in #54439, so the chai-style assertions these specs
added no longer match the rest of the suite, and the dirty-chai call
forms (to.be.empty(), to.be.false()) are no longer available.

* fix: address review feedback on preload script URL filters

- Match a data: URL loaded with baseURLForDataURL by its base URL, which
  is the URL the document commits at.
- Never match when URL patterns were not parsed, instead of matching
  every URL.
- Explain a scheme separator mismatch in the invalid pattern error.
- Document custom scheme requirements, error page matching and opaque
  origins with matchOriginAsFallback.
- Add specs for baseURLForDataURL, subframes and redirects.

* docs: list preload script URL filter conditions

Break the URL filter description for ses.registerPreloadScript into
bullet lists, and note that in-page navigations do not rerun the
preload script.
2026-10-21 16:48:27 -04:00
..
2026-03-12 14:43:39 +01:00
2026-10-15 10:19:10 -04:00

Official Guides

Please make sure that you use the documents that match your Electron version. The version number should be a part of the page URL. If it's not, you are probably using the documentation of a development branch which may contain API changes that are not compatible with your Electron version. To view older versions of the documentation, you can browse by tag on GitHub by opening the "Switch branches/tags" dropdown and selecting the tag that matches your version.

FAQ

There are questions that are asked quite often. Check this out before creating an issue:

Guides and Tutorials

Getting started

Learning the basics

Advanced steps

Detailed Tutorials

These individual tutorials expand on topics discussed in the guide above.


API References

Custom Web Features:

Modules for the Main Process:

Modules for the Renderer Process (Web Page):

Modules for Both Processes:

Development

See development/README.md