From 76f4bd01eb6e9d31f39ec945a680528b8ec82323 Mon Sep 17 00:00:00 2001 From: Jhen Date: Thu, 30 Jun 2016 15:45:03 +0800 Subject: [PATCH 1/2] Support background.page in extension manifest --- lib/browser/chrome-extension.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index e3cd454078..68b86ee498 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -72,10 +72,15 @@ const backgroundPages = {} const startBackgroundPages = function (manifest) { if (backgroundPages[manifest.extensionId] || !manifest.background) return - const scripts = manifest.background.scripts.map((name) => { - return `` - }).join('') - const html = new Buffer(`${scripts}`) + let html + if (manifest.background.page) { + html = fs.readFileSync(path.join(manifest.srcDirectory, manifest.background.page)) + } else { + const scripts = manifest.background.scripts.map((name) => { + return `` + }).join('') + html = new Buffer(`${scripts}`) + } const contents = webContents.create({ isBackgroundPage: true, From d4f64ce94307d3897231fd842e4a37fa42ef2d0a Mon Sep 17 00:00:00 2001 From: Jhen Date: Fri, 1 Jul 2016 23:05:00 +0800 Subject: [PATCH 2/2] 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 68b86ee498..4bb4a51c19 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 }) }