delete backgroundPages[manifest.extensionId]
}
+// Dispatch tabs events.
+const hookWindowForTabEvents = function (win) {
+ const tabId = win.webContents.id
+ for (const page of objectValues(backgroundPages)) {
+ page.webContents.sendToAll('CHROME_TABS_ONCREATED', tabId)
+ }
+
+ win.once('closed', () => {
+ for (const page of objectValues(backgroundPages)) {
+ page.webContents.sendToAll('CHROME_TABS_ONREMOVED', tabId)
+ }
+ })
+}
+
// Handle the chrome.* API messages.
let nextId = 0
const init = BrowserWindow.prototype._init
BrowserWindow.prototype._init = function () {
init.call(this)
+ hookWindowForTabEvents(this)
this.webContents.on('devtools-opened', () => {
loadDevToolsExtensions(this, objectValues(manifestMap))
})
chrome.runtime.onMessage.emit(message, new MessageSender(tabId, extensionId))
})
+ ipcRenderer.on('CHROME_TABS_ONCREATED', (event, tabId) => {
+ chrome.tabs.onCreated.emit(new Tab(tabId))
+ })
+
+ ipcRenderer.on('CHROME_TABS_ONREMOVED', (event, tabId) => {
+ chrome.tabs.onRemoved.emit(tabId)
+ })
+
chrome.runtime = {
getURL: function (path) {
return url.format({
})
},
- onConnect: new Event(),
-
connect (...args) {
if (isBackgroundPage) {
console.error('chrome.runtime.connect is not supported in background page')
ipcRenderer.send('CHROME_RUNTIME_SENDMESSAGE', targetExtensionId, message)
},
- onMessage: new Event()
+ onConnect: new Event(),
+ onMessage: new Event(),
+ onInstalled: new Event()
}
chrome.tabs = {
ipcRenderer.send(`CHROME_TABS_SEND_MESSAGE`, tabId, extensionId, isBackgroundPage, message)
},
- onUpdated: new Event()
+ onUpdated: new Event(),
+ onCreated: new Event(),
+ onRemoved: new Event()
}
chrome.extension = {