refactor: simplify content script injection (#18532)
This commit is contained in:
parent
f80601da16
commit
ed5fb4a720
17 changed files with 63 additions and 407 deletions
|
@ -2,7 +2,6 @@
|
|||
|
||||
const { app, webContents, BrowserWindow } = require('electron')
|
||||
const { getAllWebContents } = process.electronBinding('web_contents')
|
||||
const renderProcessPreferences = process.electronBinding('render_process_preferences').forAllWebContents()
|
||||
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils')
|
||||
|
||||
const { Buffer } = require('buffer')
|
||||
|
@ -313,6 +312,10 @@ ipcMainUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', async function (event, tabId,
|
|||
return ipcMainUtils.invokeInWebContents(contents, false, 'CHROME_TABS_EXECUTE_SCRIPT', extensionId, url, code)
|
||||
})
|
||||
|
||||
ipcMainUtils.handle('CHROME_GET_CONTENT_SCRIPTS', async (event) => {
|
||||
return Object.values(contentScripts)
|
||||
})
|
||||
|
||||
// Transfer the content scripts to renderer.
|
||||
const contentScripts = {}
|
||||
|
||||
|
@ -341,7 +344,7 @@ const injectContentScripts = function (manifest) {
|
|||
extensionId: manifest.extensionId,
|
||||
contentScripts: manifest.content_scripts.map(contentScriptToEntry)
|
||||
}
|
||||
contentScripts[manifest.name] = renderProcessPreferences.addEntry(entry)
|
||||
contentScripts[manifest.name] = entry
|
||||
} catch (e) {
|
||||
console.error('Failed to read content scripts', e)
|
||||
}
|
||||
|
@ -350,7 +353,6 @@ const injectContentScripts = function (manifest) {
|
|||
const removeContentScripts = function (manifest) {
|
||||
if (!contentScripts[manifest.name]) return
|
||||
|
||||
renderProcessPreferences.removeEntry(contentScripts[manifest.name])
|
||||
delete contentScripts[manifest.name]
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue