File size: 540 Bytes
1359e39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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 })
	}
})