Add devtools from web-contents-created event
This commit is contained in:
parent
d8fe5da3ea
commit
c8c60dd313
3 changed files with 18 additions and 27 deletions
|
@ -10,6 +10,14 @@ session
|
||||||
const binding = process.atomBinding('web_contents')
|
const binding = process.atomBinding('web_contents')
|
||||||
const debuggerBinding = process.atomBinding('debugger')
|
const debuggerBinding = process.atomBinding('debugger')
|
||||||
|
|
||||||
|
const WebContents = new EventEmitter()
|
||||||
|
WebContents.create = (options = {}) => {
|
||||||
|
return binding.create(options)
|
||||||
|
}
|
||||||
|
WebContents.fromId = (id) => {
|
||||||
|
return binding.fromId(id)
|
||||||
|
}
|
||||||
|
|
||||||
let nextId = 0
|
let nextId = 0
|
||||||
const getNextId = function () {
|
const getNextId = function () {
|
||||||
return ++nextId
|
return ++nextId
|
||||||
|
@ -223,6 +231,8 @@ const wrapWebContents = function (webContents) {
|
||||||
|
|
||||||
this._printToPDF(printingSetting, callback)
|
this._printToPDF(printingSetting, callback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WebContents.emit('web-contents-created', webContents)
|
||||||
}
|
}
|
||||||
|
|
||||||
binding._setWrapWebContents(wrapWebContents)
|
binding._setWrapWebContents(wrapWebContents)
|
||||||
|
@ -235,12 +245,4 @@ const wrapDebugger = function (webContentsDebugger) {
|
||||||
|
|
||||||
debuggerBinding._setWrapDebugger(wrapDebugger)
|
debuggerBinding._setWrapDebugger(wrapDebugger)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = WebContents
|
||||||
create (options = {}) {
|
|
||||||
return binding.create(options)
|
|
||||||
},
|
|
||||||
|
|
||||||
fromId (id) {
|
|
||||||
return binding.fromId(id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -222,6 +222,13 @@ const loadDevToolsExtensions = function (win, manifests) {
|
||||||
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
win.devToolsWebContents.executeJavaScript(`DevToolsAPI.addExtensions(${JSON.stringify(extensionInfoArray)})`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
webContents.on('web-contents-created', function (webContents) {
|
||||||
|
hookWindowForTabEvents(webContents)
|
||||||
|
webContents.on('devtools-opened', function () {
|
||||||
|
loadDevToolsExtensions(webContents, objectValues(manifestMap))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// The persistent path of "DevTools Extensions" preference file.
|
// The persistent path of "DevTools Extensions" preference file.
|
||||||
let loadedExtensionsPath = null
|
let loadedExtensionsPath = null
|
||||||
|
|
||||||
|
@ -312,18 +319,4 @@ app.once('ready', function () {
|
||||||
delete manifestMap[manifest.extensionId]
|
delete manifestMap[manifest.extensionId]
|
||||||
delete manifestNameMap[name]
|
delete manifestNameMap[name]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load extensions automatically when devtools is opened.
|
|
||||||
const init = BrowserWindow.prototype._init
|
|
||||||
BrowserWindow.prototype._init = function () {
|
|
||||||
init.call(this)
|
|
||||||
exports.loadDevToolsExtensions(this.webContents)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
exports.loadDevToolsExtensions = function (webContents) {
|
|
||||||
hookWindowForTabEvents(webContents)
|
|
||||||
webContents.on('devtools-opened', function () {
|
|
||||||
loadDevToolsExtensions(webContents, objectValues(manifestMap))
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const ChromeExtension = require('./chrome-extension')
|
|
||||||
const ipcMain = require('electron').ipcMain
|
const ipcMain = require('electron').ipcMain
|
||||||
const webContents = require('electron').webContents
|
const webContents = require('electron').webContents
|
||||||
|
|
||||||
|
@ -151,9 +150,6 @@ const createGuest = function (embedder, params) {
|
||||||
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args))
|
embedder.send.apply(embedder, ['ELECTRON_GUEST_VIEW_INTERNAL_SIZE_CHANGED-' + guest.viewInstanceId].concat(args))
|
||||||
})
|
})
|
||||||
|
|
||||||
// Enable DevTools extensions in guest view
|
|
||||||
ChromeExtension.loadDevToolsExtensions(guest)
|
|
||||||
|
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue