Skip to content

Commit

Permalink
fix: loading of devtools extensions on startup (#13844)
Browse files Browse the repository at this point in the history
* Fix loading of devtools extensions on startup

The persisted DevTools Extensions were not being loaded correctly at startup. The `addDevToolsExtension` function was not defined when it was being called. An error was being thrown and ignored, so the whole thing would fail silently. I moved the code to load the extensions to the end of the event handler, so now it works.

* fixup: remove trailing spaces to unblock CI

* fixup: add logging when the Electron Enable Logging env var is set

* Fix linter error on undefined srcDirectory

* fixup: catch exception when loading extension

* Revert "fixup: catch exception when loading extension"

This reverts commit 42c2cf9.
  • Loading branch information
emusgrave authored and MarshallOfSound committed Oct 19, 2018
1 parent c0db001 commit 10db2bc
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions lib/browser/chrome-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,20 +360,6 @@ app.on('will-quit', function () {

// We can not use protocol or BrowserWindow until app is ready.
app.once('ready', function () {
// Load persisted extensions.
loadedDevToolsExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions')
try {
const loadedDevToolsExtensions = JSON.parse(fs.readFileSync(loadedDevToolsExtensionsPath))
if (Array.isArray(loadedDevToolsExtensions)) {
for (const srcDirectory of loadedDevToolsExtensions) {
// Start background pages and set content scripts.
BrowserWindow.addDevToolsExtension(srcDirectory)
}
}
} catch (error) {
// Ignore error
}

// The public API to add/remove extensions.
BrowserWindow.addExtension = function (srcDirectory) {
const manifest = getManifestFromPath(srcDirectory)
Expand Down Expand Up @@ -429,4 +415,21 @@ app.once('ready', function () {
})
return devExtensions
}

// Load persisted extensions.
loadedDevToolsExtensionsPath = path.join(app.getPath('userData'), 'DevTools Extensions')
try {
const loadedDevToolsExtensions = JSON.parse(fs.readFileSync(loadedDevToolsExtensionsPath))
if (Array.isArray(loadedDevToolsExtensions)) {
for (const srcDirectory of loadedDevToolsExtensions) {
// Start background pages and set content scripts.
BrowserWindow.addDevToolsExtension(srcDirectory)
}
}
} catch (error) {
if (process.env.ELECTRON_ENABLE_LOGGING) {
console.error('Failed to load browser extensions from directory:', loadedDevToolsExtensionsPath)
console.error(error)
}
}
})

0 comments on commit 10db2bc

Please sign in to comment.