@browserless/function 13.6.10 → 13.6.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -5
- package/src/index.js +38 -36
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/function",
|
|
3
3
|
"description": "Execute arbitrary JavaScript code in a secure browser sandbox with access to page DOM and network.",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "13.6.
|
|
5
|
+
"version": "13.6.12",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -32,14 +32,13 @@
|
|
|
32
32
|
],
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@browserless/errors": "13.6.10",
|
|
35
|
-
"@cloudflare/puppeteer": "~1.
|
|
36
|
-
"acorn": "~8.
|
|
35
|
+
"@cloudflare/puppeteer": "~1.2.0",
|
|
36
|
+
"acorn": "~8.18.0",
|
|
37
37
|
"acorn-walk": "~8.3.5",
|
|
38
38
|
"isolated-function": "~0.2.0",
|
|
39
39
|
"require-one-of": "~1.0.24"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@browserless/test": "13.6.10",
|
|
43
42
|
"ava": "5",
|
|
44
43
|
"lodash": "latest"
|
|
45
44
|
},
|
|
@@ -58,5 +57,5 @@
|
|
|
58
57
|
"timeout": "2m",
|
|
59
58
|
"workerThreads": false
|
|
60
59
|
},
|
|
61
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "363898247585b3b6cd51781fbd55ca61ee9ef8a6"
|
|
62
61
|
}
|
package/src/index.js
CHANGED
|
@@ -69,42 +69,44 @@ module.exports = ({ tmpdir } = {}) => {
|
|
|
69
69
|
const browser = await getBrowser()
|
|
70
70
|
const browserless = await browser.createContext()
|
|
71
71
|
|
|
72
|
-
return browserless
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
runFunctionOpts.
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
72
|
+
return browserless
|
|
73
|
+
.withPage((page, goto) => async () => {
|
|
74
|
+
const { device, response } = await goto(page, { url, timeout, ...gotoOpts })
|
|
75
|
+
|
|
76
|
+
const targetId = await getTargetId(page)
|
|
77
|
+
|
|
78
|
+
const runFunctionOpts = {
|
|
79
|
+
url,
|
|
80
|
+
code,
|
|
81
|
+
device,
|
|
82
|
+
...opts,
|
|
83
|
+
...fnOpts,
|
|
84
|
+
...(isHttpResponse(response) && { _response: serializeResponse(response) })
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (runFunctionOpts.code === code) {
|
|
88
|
+
runFunctionOpts.needsNetwork = needsNetwork
|
|
89
|
+
runFunctionOpts.source = source
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const browserFromPage = typeof page.browser === 'function' ? page.browser() : undefined
|
|
93
|
+
const browserWSEndpoint =
|
|
94
|
+
browserFromPage && typeof browserFromPage.wsEndpoint === 'function'
|
|
95
|
+
? browserFromPage.wsEndpoint()
|
|
96
|
+
: undefined
|
|
97
|
+
|
|
98
|
+
if (!browserWSEndpoint) throw new Error('Browser WebSocket endpoint not found')
|
|
99
|
+
runFunctionOpts.browserWSEndpoint = browserWSEndpoint
|
|
100
|
+
runFunctionOpts.targetId = targetId
|
|
101
|
+
|
|
102
|
+
const result = await runFunction(runFunctionOpts)
|
|
103
|
+
|
|
104
|
+
if (result.isFulfilled) return result
|
|
105
|
+
const error = ensureError(result.value)
|
|
106
|
+
if (isBrowserlessError(error)) throw error
|
|
107
|
+
return result
|
|
108
|
+
})()
|
|
109
|
+
.finally(() => browserless.destroyContext())
|
|
108
110
|
}
|
|
109
111
|
|
|
110
112
|
const runWithoutBrowser = async (url, fnOpts) => {
|