Handle unloading devtools correctly
This commit is contained in:
parent
a63ff714f8
commit
97c04735a2
1 changed files with 20 additions and 1 deletions
|
@ -60,7 +60,7 @@ const startBackgroundPages = function (manifest) {
|
|||
const html = new Buffer(`<html><body>${scripts}</body></html>`)
|
||||
|
||||
const contents = webContents.create({})
|
||||
backgroundPages[manifest.hostname] = { html: html, contents: contents }
|
||||
backgroundPages[manifest.hostname] = { html: html, webContents: contents }
|
||||
contents.loadURL(url.format({
|
||||
protocol: 'chrome-extension',
|
||||
slashes: true,
|
||||
|
@ -69,6 +69,13 @@ const startBackgroundPages = function (manifest) {
|
|||
}))
|
||||
}
|
||||
|
||||
const removeBackgroundPages = function (manifest) {
|
||||
if (!backgroundPages[manifest.hostname]) return
|
||||
|
||||
backgroundPages[manifest.hostname].webContents.destroy()
|
||||
delete backgroundPages[manifest.hostname]
|
||||
}
|
||||
|
||||
// Transfer the content scripts to renderer.
|
||||
const contentScripts = {}
|
||||
|
||||
|
@ -97,6 +104,13 @@ const injectContentScripts = function (manifest) {
|
|||
}
|
||||
}
|
||||
|
||||
const removeContentScripts = function (manifest) {
|
||||
if (!contentScripts[manifest.name]) return
|
||||
|
||||
renderProcessPreferences.removeEntry(contentScripts[manifest.name])
|
||||
delete contentScripts[manifest.name]
|
||||
}
|
||||
|
||||
// Transfer the |manifest| to a format that can be recognized by the
|
||||
// |DevToolsAPI.addExtensions|.
|
||||
const manifestToExtensionInfo = function (manifest) {
|
||||
|
@ -200,6 +214,11 @@ app.once('ready', function () {
|
|||
}
|
||||
}
|
||||
BrowserWindow.removeDevToolsExtension = function (name) {
|
||||
const manifest = manifestMap[name]
|
||||
if (!manifest) return
|
||||
|
||||
removeBackgroundPages(manifest)
|
||||
removeContentScripts(manifest)
|
||||
delete manifestMap[name]
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue