Implement chrome.tabs.executeScript
This commit is contained in:
parent
db94121360
commit
31628abadc
3 changed files with 49 additions and 1 deletions
|
@ -116,6 +116,35 @@ ipcMain.on('CHROME_PORT_POSTMESSAGE', function (event, webContentsId, portId, me
|
|||
contents.sendToAll(`CHROME_PORT_ONMESSAGE_${portId}`, message)
|
||||
})
|
||||
|
||||
ipcMain.on('CHROME_TABS_EXECUTESCRIPT', function (event, requestId, webContentsId, hostname, details) {
|
||||
const contents = webContents.fromId(webContentsId)
|
||||
if (!contents) {
|
||||
console.error(`Sending message to unkown webContentsId ${webContentsId}`)
|
||||
return
|
||||
}
|
||||
|
||||
let code, url
|
||||
if (details.file) {
|
||||
code = String(fs.readFileSync(path.join(manifest.srcDirectory, details.file)))
|
||||
url = `chrome-extension://${hostname}/${details.file}`
|
||||
} else {
|
||||
code = details.code
|
||||
url = `chrome-extension://${hostname}/${String(Math.random()).substr(2, 8)}.js`
|
||||
}
|
||||
|
||||
contents.send('CHROME_TABS_EXECUTESCRIPT', requestId, event.sender.id, hostname, url, code)
|
||||
})
|
||||
|
||||
ipcMain.on(`CHROME_TABS_EXECUTESCRIPT_RESULT`, (event, requestId, webContentsId, result) => {
|
||||
const contents = webContents.fromId(webContentsId)
|
||||
if (!contents) {
|
||||
console.error(`Sending message to unkown webContentsId ${webContentsId}`)
|
||||
return
|
||||
}
|
||||
|
||||
contents.send(`CHROME_TABS_EXECUTESCRIPT_RESULT_${requestId}`, result)
|
||||
})
|
||||
|
||||
// Transfer the content scripts to renderer.
|
||||
const contentScripts = {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue