diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 2e8254c19668..868e07e96096 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -239,7 +239,8 @@ const injectContentScripts = function (manifest) { const contentScriptToEntry = function (script) { return { matches: script.matches, - js: script.js.map(readArrayOfFiles), + js: script.js ? script.js.map(readArrayOfFiles) : [], + css: script.css ? script.css.map(readArrayOfFiles) : [], runAt: script.run_at || 'document_idle' } } diff --git a/lib/renderer/content-scripts-injector.js b/lib/renderer/content-scripts-injector.js index 7d0f34009224..d26802c8a8e7 100644 --- a/lib/renderer/content-scripts-injector.js +++ b/lib/renderer/content-scripts-injector.js @@ -28,14 +28,26 @@ const runContentScript = function (extensionId, url, code) { const injectContentScript = function (extensionId, script) { if (!script.matches.some(matchesPattern)) return - for (const {url, code} of script.js) { - const fire = runContentScript.bind(window, extensionId, url, code) - if (script.runAt === 'document_start') { - process.once('document-start', fire) - } else if (script.runAt === 'document_end') { - process.once('document-end', fire) - } else if (script.runAt === 'document_idle') { - document.addEventListener('DOMContentLoaded', fire) + if (script.js) { + for (const {url, code} of script.js) { + const fire = runContentScript.bind(window, extensionId, url, code) + if (script.runAt === 'document_start') { + process.once('document-start', fire) + } else if (script.runAt === 'document_end') { + process.once('document-end', fire) + } else if (script.runAt === 'document_idle') { + document.addEventListener('DOMContentLoaded', fire) + } + } + } + + if (script.css) { + for (const {code} of script.css) { + process.once('document-end', () => { + var node = document.createElement('style') + node.innerHTML = code + window.document.body.appendChild(node) + }) } } }