browser-2 / worker.js
semuthitamku's picture
Update worker.js
c832d0a verified
raw
history blame contribute delete
645 Bytes
const { parentPort } = require('node:worker_threads')
const playwright = require('playwright-extra')
const pluginStealth = require('puppeteer-extra-plugin-stealth')
const runUserScript = async (code) => {
const AsyncFunction =
Object.getPrototypeOf(async function () {}).constructor
const userFunc = new AsyncFunction(
'playwright',
'pluginStealth',
'console',
code
)
return await userFunc(
playwright,
pluginStealth,
console
)
}
parentPort.on('message', async (code) => {
try {
const result = await runUserScript(code)
parentPort.postMessage({ result })
} catch (error) {
parentPort.postMessage({ error })
}
})