Example #1
0
ipcMainUtils.handle('CHROME_TABS_SEND_MESSAGE', async function (event, tabId, extensionId, message) {
  const contents = webContents.fromId(tabId)
  if (!contents) {
    throw new Error(`Sending message to unknown tab ${tabId}`)
  }

  const senderTabId = isBackgroundPage(event.sender) ? null : event.sender.id

  return ipcMainUtils.invokeInWebContents(contents, true, `CHROME_RUNTIME_ONMESSAGE_${extensionId}`, senderTabId, message)
})
Example #2
0
ipcMainUtils.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extensionId, message) {
  if (isBackgroundPage(event.sender)) {
    throw new Error('chrome.runtime.sendMessage is not supported in background page')
  }

  const page = backgroundPages[extensionId]
  if (!page || page.webContents.isDestroyed()) {
    throw new Error(`Connect to unknown extension ${extensionId}`)
  }

  return ipcMainUtils.invokeInWebContents(page.webContents, true, `CHROME_RUNTIME_ONMESSAGE_${extensionId}`, event.sender.id, message)
})
Example #3
0
ipcMainUtils.handle('CHROME_TABS_EXECUTE_SCRIPT', async function (event, tabId, extensionId, details) {
  assertChromeExtension(event.sender, 'chrome.tabs.executeScript()')

  const contents = webContents.fromId(tabId)
  if (!contents) {
    throw new Error(`Sending message to unknown tab ${tabId}`)
  }

  let code, url
  if (details.file) {
    const manifest = manifestMap[extensionId]
    code = String(fs.readFileSync(path.join(manifest.srcDirectory, details.file)))
    url = `chrome-extension://${extensionId}${details.file}`
  } else {
    code = details.code
    url = `chrome-extension://${extensionId}/${String(Math.random()).substr(2, 8)}.js`
  }

  return ipcMainUtils.invokeInWebContents(contents, false, 'CHROME_TABS_EXECUTE_SCRIPT', extensionId, url, code)
})
Example #4
0
const executeJavaScript = (contents, code, hasUserGesture) => {
  return ipcMainUtils.invokeInWebContents(contents, false, 'ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', 'executeJavaScript', code, hasUserGesture)
}
Example #5
0
 WebContents.prototype[method] = function (...args) {
   ipcMainUtils.invokeInWebContents(this, false, 'ELECTRON_INTERNAL_RENDERER_WEB_FRAME_METHOD', method, ...args)
 }