browser-2 / worker.js
semuthitamku's picture
Rename browserWorker.js to worker.js
4224433 verified
raw
history blame
540 Bytes
const { parentPort } = require('node:worker_threads')
const playwright = require('playwright')
const runUserScript = async (code) => {
const AsyncFunction =
Object.getPrototypeOf(async function () {}).constructor
const userFunc = new AsyncFunction(
'console',
'playwright',
code
)
return await userFunc(
console,
playwright
)
}
parentPort.on('message', async (code) => {
try {
const result = await runUserScript(code)
parentPort.postMessage({ result })
} catch (e) {
parentPort.postMessage({ error: e })
}
})