diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index c56e3f473f..8b9c263347 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -57,18 +57,25 @@ const getManifestFromPath = function (srcDirectory) { if (!manifestNameMap[manifest.name]) { const extensionId = generateExtensionIdFromName(manifest.name) manifestMap[extensionId] = manifestNameMap[manifest.name] = manifest + + let extensionURL = url.format({ + protocol: 'chrome-extension', + slashes: true, + hostname: extensionId, + pathname: manifest.devtools_page + }) + + // Chromium requires that startPage matches '([^:]+:\/\/[^/]*)\/' + // We also can't use the file:// protocol here since that would make Chromium + // treat all extension resources as being relative to root which we don't want. + if (!manifest.devtools_page) extensionURL += '/' + Object.assign(manifest, { srcDirectory: srcDirectory, extensionId: extensionId, - // We can not use 'file://' directly because all resources in the extension - // will be treated as relative to the root in Chrome. - startPage: url.format({ - protocol: 'chrome-extension', - slashes: true, - hostname: extensionId, - pathname: manifest.devtools_page - }) + startPage: extensionURL }) + return manifest } else if (manifest && manifest.name) { console.warn(`Attempted to load extension "${manifest.name}" that has already been loaded.`) @@ -389,7 +396,8 @@ const loadDevToolsExtensions = function (win, manifests) { }) extensionInfoArray.forEach((extensionInfo) => { - win.devToolsWebContents.executeJavaScript(`Extensions.extensionServer._addExtension(${JSON.stringify(extensionInfo)})`) + const info = JSON.stringify(extensionInfo) + win.devToolsWebContents.executeJavaScript(`Extensions.extensionServer._addExtension(${info})`) }) }