diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 1ccc130ebb85..f02a1113cc90 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -60,7 +60,7 @@ const startBackgroundPages = function (manifest) { const html = new Buffer(`${scripts}`) 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] }