mirror of
https://github.com/electron/electron.git
synced 2026-10-29 04:04:54 +08:00
* 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.
1.7 KiB
1.7 KiB
PreloadScript Object
typestring - Context type where the preload script will be executed. Possible values includeframeorservice-worker.idstring - Unique ID of preload script.filePathstring - Path of the script file. Must be an absolute path.matchesstring[] (optional) - Match patterns for URLs the script runs in. A custom protocol can be used if its scheme is registered asstandardwithprotocol.registerSchemesAsPrivileged. To filter documents served from a non-standard scheme, useincludeGlobsorexcludeGlobs, which match against the whole URL. If omitted, the script runs for all URLs not excluded by other filters.excludeMatchesstring[] (optional) - Match patterns for URLs the script will not run in.includeGlobsstring[] (optional) - Glob patterns applied aftermatches. A URL must also match one of these globs.*matches any sequence of characters and?matches any single character.excludeGlobsstring[] (optional) - Glob patterns for URLs the script will not run in.matchOriginAsFallbackboolean (optional) - Whether a document whose URL has no origin of its own (about:,blob:,data:orfilesystem:) is matched by the origin of the frame that created it instead of by its URL. This includes documents with an opaque origin, such as adata:frame or a sandboxed<iframe srcdoc>. For example, anabout:blankpopup opened byhttps://example.com/pageis matched ashttps://example.com/. When set, every pattern inmatchesmust have a path of/*. Only applies toframecontexts. Default isfalse.