mirror of
https://github.com/electron/electron.git
synced 2026-01-25 23:38:18 -05:00
Handle unloading devtools correctly
This commit is contained in:
@@ -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]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user