Spaces:
Paused
Paused
Update worker.js
Browse files
worker.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
| 1 |
const { parentPort } = require('node:worker_threads')
|
| 2 |
const playwright = require('playwright')
|
| 3 |
|
| 4 |
-
const runUserScript = async (code) => {
|
| 5 |
const AsyncFunction =
|
| 6 |
Object.getPrototypeOf(async function () {}).constructor
|
| 7 |
-
|
| 8 |
const userFunc = new AsyncFunction(
|
| 9 |
-
'console',
|
| 10 |
'playwright',
|
|
|
|
| 11 |
code
|
| 12 |
)
|
| 13 |
-
|
| 14 |
return await userFunc(
|
| 15 |
-
|
| 16 |
-
|
| 17 |
)
|
| 18 |
}
|
| 19 |
|
| 20 |
parentPort.on('message', async (code) => {
|
| 21 |
try {
|
| 22 |
-
const result = await runUserScript(code)
|
| 23 |
parentPort.postMessage({ result })
|
| 24 |
} catch (e) {
|
| 25 |
parentPort.postMessage({ error: e })
|
|
|
|
| 1 |
const { parentPort } = require('node:worker_threads')
|
| 2 |
const playwright = require('playwright')
|
| 3 |
|
| 4 |
+
const runUserScript = async (browser, code) => {
|
| 5 |
const AsyncFunction =
|
| 6 |
Object.getPrototypeOf(async function () {}).constructor
|
| 7 |
+
|
| 8 |
const userFunc = new AsyncFunction(
|
|
|
|
| 9 |
'playwright',
|
| 10 |
+
'console',
|
| 11 |
code
|
| 12 |
)
|
| 13 |
+
|
| 14 |
return await userFunc(
|
| 15 |
+
browser,
|
| 16 |
+
console
|
| 17 |
)
|
| 18 |
}
|
| 19 |
|
| 20 |
parentPort.on('message', async (code) => {
|
| 21 |
try {
|
| 22 |
+
const result = await runUserScript(playwright, code)
|
| 23 |
parentPort.postMessage({ result })
|
| 24 |
} catch (e) {
|
| 25 |
parentPort.postMessage({ error: e })
|