Use background page path instead of generated path

if extension use manifest.background.page
This commit is contained in:
Jhen 2016-07-01 23:05:00 +08:00
parent 76f4bd01eb
commit d4f64ce943

View file

@ -73,9 +73,12 @@ const startBackgroundPages = function (manifest) {
if (backgroundPages[manifest.extensionId] || !manifest.background) return if (backgroundPages[manifest.extensionId] || !manifest.background) return
let html let html
let name
if (manifest.background.page) { if (manifest.background.page) {
name = manifest.background.page
html = fs.readFileSync(path.join(manifest.srcDirectory, manifest.background.page)) html = fs.readFileSync(path.join(manifest.srcDirectory, manifest.background.page))
} else { } else {
name = '_generated_background_page.html'
const scripts = manifest.background.scripts.map((name) => { const scripts = manifest.background.scripts.map((name) => {
return `<script src="${name}"></script>` return `<script src="${name}"></script>`
}).join('') }).join('')
@ -86,12 +89,12 @@ const startBackgroundPages = function (manifest) {
isBackgroundPage: true, isBackgroundPage: true,
commandLineSwitches: ['--background-page'] commandLineSwitches: ['--background-page']
}) })
backgroundPages[manifest.extensionId] = { html: html, webContents: contents } backgroundPages[manifest.extensionId] = { html: html, webContents: contents, name: name }
contents.loadURL(url.format({ contents.loadURL(url.format({
protocol: 'chrome-extension', protocol: 'chrome-extension',
slashes: true, slashes: true,
hostname: manifest.extensionId, hostname: manifest.extensionId,
pathname: '_generated_background_page.html' pathname: name
})) }))
} }
@ -314,11 +317,11 @@ app.once('ready', function () {
const manifest = manifestMap[parsed.hostname] const manifest = manifestMap[parsed.hostname]
if (!manifest) return callback() if (!manifest) return callback()
if (parsed.path === '/_generated_background_page.html' && const page = backgroundPages[parsed.hostname]
backgroundPages[parsed.hostname]) { if (page && parsed.path === `/${page.name}`) {
return callback({ return callback({
mimeType: 'text/html', mimeType: 'text/html',
data: backgroundPages[parsed.hostname].html data: page.html
}) })
} }