|
@@ -97,17 +97,42 @@ const removeBackgroundPages = function (manifest) {
|
|
|
delete backgroundPages[manifest.extensionId]
|
|
|
}
|
|
|
|
|
|
-// Dispatch tabs events.
|
|
|
-const hookWebContentsForTabEvents = function (webContents) {
|
|
|
- const tabId = webContents.id
|
|
|
+const sendToBackgroundPages = function (...args) {
|
|
|
for (const page of objectValues(backgroundPages)) {
|
|
|
- page.webContents.sendToAll('CHROME_TABS_ONCREATED', tabId)
|
|
|
+ page.webContents.sendToAll(...args)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+// Dispatch web contents events to Chrome APIs
|
|
|
+const hookWebContentsEvents = function (webContents) {
|
|
|
+ const tabId = webContents.id
|
|
|
+
|
|
|
+ sendToBackgroundPages('CHROME_TABS_ONCREATED')
|
|
|
+
|
|
|
+ webContents.on('will-navigate', (event, url) => {
|
|
|
+ sendToBackgroundPages('CHROME_WEBNAVIGATION_ONBEFORENAVIGATE', {
|
|
|
+ frameId: 0,
|
|
|
+ parentFrameId: -1,
|
|
|
+ processId: webContents.getId(),
|
|
|
+ tabId: tabId,
|
|
|
+ timeStamp: Date.now(),
|
|
|
+ url: url
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ webContents.on('did-navigate', (event, url) => {
|
|
|
+ sendToBackgroundPages('CHROME_WEBNAVIGATION_ONCOMPLETED', {
|
|
|
+ frameId: 0,
|
|
|
+ parentFrameId: -1,
|
|
|
+ processId: webContents.getId(),
|
|
|
+ tabId: tabId,
|
|
|
+ timeStamp: Date.now(),
|
|
|
+ url: url
|
|
|
+ })
|
|
|
+ })
|
|
|
|
|
|
webContents.once('destroyed', () => {
|
|
|
- for (const page of objectValues(backgroundPages)) {
|
|
|
- page.webContents.sendToAll('CHROME_TABS_ONREMOVED', tabId)
|
|
|
- }
|
|
|
+ sendToBackgroundPages('CHROME_TABS_ONREMOVED', tabId)
|
|
|
})
|
|
|
}
|
|
|
|
|
@@ -245,7 +270,7 @@ const loadDevToolsExtensions = function (win, manifests) {
|
|
|
app.on('web-contents-created', function (event, webContents) {
|
|
|
if (!isWindowOrWebView(webContents)) return
|
|
|
|
|
|
- hookWebContentsForTabEvents(webContents)
|
|
|
+ hookWebContentsEvents(webContents)
|
|
|
webContents.on('devtools-opened', function () {
|
|
|
loadDevToolsExtensions(webContents, objectValues(manifestMap))
|
|
|
})
|