feat: service worker preload scripts for improved extensions support (#44411)
* feat: preload scripts for service workers * feat: service worker IPC * test: service worker preload scripts and ipc
This commit is contained in:
parent
bc22ee7897
commit
26da3c5d6e
67 changed files with 2103 additions and 298 deletions
34
spec/fixtures/api/preload-realm/preload-tests.js
vendored
Normal file
34
spec/fixtures/api/preload-realm/preload-tests.js
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
const evalTests = {
|
||||
evalConstructorName: () => globalThis.constructor.name
|
||||
};
|
||||
|
||||
const tests = {
|
||||
testSend: (name, ...args) => {
|
||||
ipcRenderer.send(name, ...args);
|
||||
},
|
||||
testInvoke: async (name, ...args) => {
|
||||
const result = await ipcRenderer.invoke(name, ...args);
|
||||
return result;
|
||||
},
|
||||
testEvaluate: (testName, args) => {
|
||||
const func = evalTests[testName];
|
||||
const result = args
|
||||
? contextBridge.executeInMainWorld({ func, args })
|
||||
: contextBridge.executeInMainWorld({ func });
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
ipcRenderer.on('test', async (_event, uuid, name, ...args) => {
|
||||
console.debug(`running test ${name} for ${uuid}`);
|
||||
try {
|
||||
const result = await tests[name]?.(...args);
|
||||
console.debug(`responding test ${name} for ${uuid}`);
|
||||
ipcRenderer.send(`test-result-${uuid}`, { error: false, result });
|
||||
} catch (error) {
|
||||
console.debug(`erroring test ${name} for ${uuid}`);
|
||||
ipcRenderer.send(`test-result-${uuid}`, { error: true, result: error.message });
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue