Skip to content

Instantly share code, notes, and snippets.

View bububa's full-sized avatar
💭
I may be slow to respond.

Prof Syd Xu bububa

💭
I may be slow to respond.
View GitHub Profile
@willwillems
willwillems / background.js
Last active June 8, 2024 21:36
Custom webpack chunk loading from a web extension (Chrome) content script.
// Throw this in your background script, it injects a generated webpack chunk when asked
chrome.runtime.onMessage.addListener(function ({ type, data}, sender, sendResponse) {
if (type === 'requestFileInjection') {
const file = data.fileName
if (!file) throw new Error('No file name provided.')
chrome.tabs.executeScript({ file: `${file}.js` }, (result) => {
console.log(`${file}.js injected`)
return sendResponse({ type: 'injected', target: { src: `${file}.js` }, success: true })
})
return true // return true so sendResponse stays valid