Implement chrome.tabs.executeScript

This commit is contained in:
Cheng Zhao 2016-05-28 16:41:12 +09:00
parent db94121360
commit 31628abadc
3 changed files with 49 additions and 1 deletions

View file

@ -1,3 +1,4 @@
const {ipcRenderer} = require('electron')
const {runInThisContext} = require('vm')
// Check whether pattern matches.
@ -19,7 +20,7 @@ const runContentScript = function (extensionId, url, code) {
lineOffset: 1,
displayErrors: true
})
compiledWrapper.call(this, chrome)
return compiledWrapper.call(this, chrome)
}
// Run injected scripts.
@ -41,6 +42,12 @@ const injectContentScript = function (script) {
}
}
// Handle the request of chrome.tabs.executeJavaScript.
ipcRenderer.on('CHROME_TABS_EXECUTESCRIPT', function (event, requestId, senderId, extensionId, url, code) {
const result = runContentScript.call(window, extensionId, url, code)
ipcRenderer.send('CHROME_TABS_EXECUTESCRIPT_RESULT', requestId, senderId, result)
})
// Read the renderer process preferences.
const preferences = process.getRenderProcessPreferences()
if (preferences) {