refactor: simplify content script injection (#18532)
This commit is contained in:
parent
f80601da16
commit
ed5fb4a720
17 changed files with 63 additions and 407 deletions
|
@ -108,15 +108,17 @@ ipcRendererUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', function (
|
|||
return runContentScript.call(window, extensionId, url, code)
|
||||
})
|
||||
|
||||
module.exports = (getRenderProcessPreferences: typeof process.getRenderProcessPreferences) => {
|
||||
// Read the renderer process preferences.
|
||||
const preferences = getRenderProcessPreferences()
|
||||
if (preferences) {
|
||||
for (const pref of preferences) {
|
||||
if (pref.contentScripts) {
|
||||
for (const script of pref.contentScripts) {
|
||||
injectContentScript(pref.extensionId, script)
|
||||
}
|
||||
type ContentScriptEntry = {
|
||||
extensionId: string;
|
||||
contentScripts: Electron.ContentScript[];
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
const entries = ipcRendererUtils.invokeSync<ContentScriptEntry[]>('CHROME_GET_CONTENT_SCRIPTS')
|
||||
for (const entry of entries) {
|
||||
if (entry.contentScripts) {
|
||||
for (const script of entry.contentScripts) {
|
||||
injectContentScript(entry.extensionId, script)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue