From d4f64ce94307d3897231fd842e4a37fa42ef2d0a Mon Sep 17 00:00:00 2001 From: Jhen Date: Fri, 1 Jul 2016 23:05:00 +0800 Subject: [PATCH] Use background page path instead of generated path if extension use manifest.background.page --- lib/browser/chrome-extension.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 68b86ee4983c..4bb4a51c191d 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -73,9 +73,12 @@ const startBackgroundPages = function (manifest) { if (backgroundPages[manifest.extensionId] || !manifest.background) return let html + let name if (manifest.background.page) { + name = manifest.background.page html = fs.readFileSync(path.join(manifest.srcDirectory, manifest.background.page)) } else { + name = '_generated_background_page.html' const scripts = manifest.background.scripts.map((name) => { return `` }).join('') @@ -86,12 +89,12 @@ const startBackgroundPages = function (manifest) { isBackgroundPage: true, commandLineSwitches: ['--background-page'] }) - backgroundPages[manifest.extensionId] = { html: html, webContents: contents } + backgroundPages[manifest.extensionId] = { html: html, webContents: contents, name: name } contents.loadURL(url.format({ protocol: 'chrome-extension', slashes: true, hostname: manifest.extensionId, - pathname: '_generated_background_page.html' + pathname: name })) } @@ -314,11 +317,11 @@ app.once('ready', function () { const manifest = manifestMap[parsed.hostname] if (!manifest) return callback() - if (parsed.path === '/_generated_background_page.html' && - backgroundPages[parsed.hostname]) { + const page = backgroundPages[parsed.hostname] + if (page && parsed.path === `/${page.name}`) { return callback({ mimeType: 'text/html', - data: backgroundPages[parsed.hostname].html + data: page.html }) }