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:
Samuel Maddock
2019-03-08 18:53:25 -05:00
committed by Samuel Attard
parent b7fc50b7ca
commit 8ee153dae1
11 changed files with 196 additions and 45 deletions

View File

@@ -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
}
}

View File

@@ -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) {

View File

@@ -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)
}
}