Add support for css in content_scripts
This commit is contained in:
		
					parent
					
						
							
								6bf2ec4188
							
						
					
				
			
			
				commit
				
					
						e1a232e7c8
					
				
			
		
					 2 changed files with 22 additions and 9 deletions
				
			
		| 
						 | 
					@ -239,7 +239,8 @@ const injectContentScripts = function (manifest) {
 | 
				
			||||||
  const contentScriptToEntry = function (script) {
 | 
					  const contentScriptToEntry = function (script) {
 | 
				
			||||||
    return {
 | 
					    return {
 | 
				
			||||||
      matches: script.matches,
 | 
					      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'
 | 
					      runAt: script.run_at || 'document_idle'
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -28,6 +28,7 @@ const runContentScript = function (extensionId, url, code) {
 | 
				
			||||||
const injectContentScript = function (extensionId, script) {
 | 
					const injectContentScript = function (extensionId, script) {
 | 
				
			||||||
  if (!script.matches.some(matchesPattern)) return
 | 
					  if (!script.matches.some(matchesPattern)) return
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (script.js) {
 | 
				
			||||||
    for (const {url, code} of script.js) {
 | 
					    for (const {url, code} of script.js) {
 | 
				
			||||||
      const fire = runContentScript.bind(window, extensionId, url, code)
 | 
					      const fire = runContentScript.bind(window, extensionId, url, code)
 | 
				
			||||||
      if (script.runAt === 'document_start') {
 | 
					      if (script.runAt === 'document_start') {
 | 
				
			||||||
| 
						 | 
					@ -40,6 +41,17 @@ const injectContentScript = function (extensionId, script) {
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  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)
 | 
				
			||||||
 | 
					      })
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Handle the request of chrome.tabs.executeJavaScript.
 | 
					// Handle the request of chrome.tabs.executeJavaScript.
 | 
				
			||||||
ipcRenderer.on('CHROME_TABS_EXECUTESCRIPT', function (event, senderWebContentsId, requestId, extensionId, url, code) {
 | 
					ipcRenderer.on('CHROME_TABS_EXECUTESCRIPT', function (event, senderWebContentsId, requestId, extensionId, url, code) {
 | 
				
			||||||
  const result = runContentScript.call(window, extensionId, url, code)
 | 
					  const result = runContentScript.call(window, extensionId, url, code)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue