mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
feat: add support for content scripts 'all_frames' option (#17258)
* feat: add support for content scripts 'all_frames' option * merged content script tests 'all_frames' test now runs on all variants of sandbox/contentIsolation configurations :D
This commit is contained in:
committed by
Samuel Attard
parent
b7fc50b7ca
commit
8ee153dae1
@@ -345,7 +345,8 @@ const injectContentScripts = function (manifest) {
|
||||
matches: script.matches,
|
||||
js: script.js ? script.js.map(readArrayOfFiles) : [],
|
||||
css: script.css ? script.css.map(readArrayOfFiles) : [],
|
||||
runAt: script.run_at || 'document_idle'
|
||||
runAt: script.run_at || 'document_idle',
|
||||
allFrames: script.all_frames || false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ const runAllStylesheet = function (css: Array<Electron.InjectionBase>) {
|
||||
// Run injected scripts.
|
||||
// https://developer.chrome.com/extensions/content_scripts
|
||||
const injectContentScript = function (extensionId: string, script: Electron.ContentScript) {
|
||||
if (!process.isMainFrame && !script.allFrames) return
|
||||
if (!script.matches.some(matchesPattern)) return
|
||||
|
||||
if (script.js) {
|
||||
|
||||
@@ -85,9 +85,7 @@ switch (window.location.protocol) {
|
||||
windowSetup(ipcRendererInternal, guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen)
|
||||
|
||||
// Inject content scripts.
|
||||
if (process.isMainFrame) {
|
||||
require('@electron/internal/renderer/content-scripts-injector')(process.getRenderProcessPreferences)
|
||||
}
|
||||
require('@electron/internal/renderer/content-scripts-injector')(process.getRenderProcessPreferences)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user