diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 8b850b5c4388..e73ef6cfa188 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -396,6 +396,17 @@ Method will also not return if the extension's manifest is missing or incomplete Remove the DevTools extension whose name is `name`. +### `BrowserWindow.getDevToolsExtensions()` + +Returns an Object where the keys are the extension names and each value is +an Object containing `name` and `version` properties. + +To check if a DevTools extension is installed you can run the following: + +```javascript +let installed = BrowserWindow.getDevToolsExtensions().hasOwnProperty('devtron') +``` + ## Instance Properties Objects created with `new BrowserWindow` have the following properties: diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index ea9dc15f2c71..8739c7a0aba3 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -339,4 +339,13 @@ app.once('ready', function () { delete manifestMap[manifest.extensionId] delete manifestNameMap[name] } + + BrowserWindow.getDevToolsExtensions = function () { + const extensions = {} + Object.keys(manifestNameMap).forEach(function (name) { + const manifest = manifestNameMap[name] + extensions[name] = {name: manifest.name, version: manifest.version} + }) + return extensions + } }) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 5048f3cd4a93..07a31420687c 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -838,9 +838,11 @@ describe('browser-window module', function () { beforeEach(function () { BrowserWindow.removeDevToolsExtension('foo') + assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), false) var extensionPath = path.join(__dirname, 'fixtures', 'devtools-extensions', 'foo') BrowserWindow.addDevToolsExtension(extensionPath) + assert.equal(BrowserWindow.getDevToolsExtensions().hasOwnProperty('foo'), true) w.webContents.on('devtools-opened', function () { var showPanelIntevalId = setInterval(function () {