File size: 645 Bytes
947e5c0
bc65ff0
 
947e5c0
bc65ff0
947e5c0
 
2597afc
947e5c0
 
c832d0a
2597afc
947e5c0
 
2597afc
947e5c0
bc65ff0
 
2597afc
947e5c0
 
 
 
 
bc65ff0
947e5c0
bc65ff0
 
947e5c0
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 })
	}
})