diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index e3cd454078..4bb4a51c19 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -72,21 +72,29 @@ 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 + 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('') + html = new Buffer(`${scripts}`) + } const contents = webContents.create({ 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 })) } @@ -309,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 }) }