@browserless/function 9.2.18 → 9.3.0
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 +5 -6
- package/src/function.js +4 -4
- package/src/index.js +4 -4
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@browserless/function",
|
|
3
3
|
"description": "Run abritrary JavaScript inside a browser sandbox",
|
|
4
4
|
"homepage": "https://browserless.js.org",
|
|
5
|
-
"version": "9.
|
|
5
|
+
"version": "9.3.0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"email": "hello@microlink.io",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"serverless"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@browserless/errors": "^9.
|
|
32
|
+
"@browserless/errors": "^9.3.0",
|
|
33
33
|
"debug-logfmt": "~1.0.4",
|
|
34
34
|
"deepmerge": "~4.2.2",
|
|
35
35
|
"execa": "~5.1.1",
|
|
@@ -39,12 +39,11 @@
|
|
|
39
39
|
"p-timeout": "~4.1.0",
|
|
40
40
|
"require-one-of": "~1.0.15",
|
|
41
41
|
"serialize-error": "~8.1.0",
|
|
42
|
-
"vm2": "3.9.
|
|
42
|
+
"vm2": "~3.9.5"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"ava": "latest",
|
|
46
46
|
"browserless": "latest",
|
|
47
|
-
"nyc": "latest",
|
|
48
47
|
"puppeteer": "latest"
|
|
49
48
|
},
|
|
50
49
|
"engines": {
|
|
@@ -54,12 +53,12 @@
|
|
|
54
53
|
"src"
|
|
55
54
|
],
|
|
56
55
|
"scripts": {
|
|
57
|
-
"test": "NODE_ENV=test
|
|
56
|
+
"test": "NODE_ENV=test ava"
|
|
58
57
|
},
|
|
59
58
|
"license": "MIT",
|
|
60
59
|
"ava": {
|
|
61
60
|
"timeout": "2m",
|
|
62
61
|
"verbose": true
|
|
63
62
|
},
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "489d6fffc2e001fba2961838b73d10f916862676"
|
|
65
64
|
}
|
package/src/function.js
CHANGED
|
@@ -7,12 +7,12 @@ const createVm = require('./vm')
|
|
|
7
7
|
const scriptPath = path.resolve(__dirname, 'function.js')
|
|
8
8
|
|
|
9
9
|
const createFn = code => `
|
|
10
|
-
async ({ url,
|
|
10
|
+
async ({ url, gotoOpts, browserWSEndpoint, ...opts }) => {
|
|
11
11
|
const { serializeError } = require('serialize-error')
|
|
12
12
|
|
|
13
13
|
const getBrowserless = require('browserless')
|
|
14
14
|
const browserless = await getBrowserless({ mode: 'connect', browserWSEndpoint }).createContext()
|
|
15
|
-
const fnWrapper = fn => (page, response) => fn({ page, response,
|
|
15
|
+
const fnWrapper = fn => (page, response) => fn({ page, response, ...opts })
|
|
16
16
|
const browserFn = browserless.evaluate(fnWrapper(${code}), gotoOpts)
|
|
17
17
|
|
|
18
18
|
try {
|
|
@@ -25,9 +25,9 @@ async ({ url, query, gotoOpts, browserWSEndpoint }) => {
|
|
|
25
25
|
}
|
|
26
26
|
}`
|
|
27
27
|
|
|
28
|
-
process.on('message', async ({ url, code,
|
|
28
|
+
process.on('message', async ({ url, code, vmOpts, gotoOpts, browserWSEndpoint, ...opts }) => {
|
|
29
29
|
const vm = createVm(vmOpts)
|
|
30
30
|
const fn = createFn(code.endsWith(';') ? code.slice(0, -1) : code)
|
|
31
31
|
const run = vm(fn, scriptPath)
|
|
32
|
-
process.send(await run({ url,
|
|
32
|
+
process.send(await run({ url, gotoOpts, browserWSEndpoint, ...opts }))
|
|
33
33
|
})
|
package/src/index.js
CHANGED
|
@@ -16,9 +16,9 @@ const execPath = path.resolve(__dirname, 'function.js')
|
|
|
16
16
|
|
|
17
17
|
module.exports = (
|
|
18
18
|
fn,
|
|
19
|
-
{ getBrowserless = requireOneOf(['browserless']), retry = 2, timeout = 30000, ...opts }
|
|
19
|
+
{ getBrowserless = requireOneOf(['browserless']), retry = 2, timeout = 30000, ...opts } = {}
|
|
20
20
|
) => {
|
|
21
|
-
return async (url,
|
|
21
|
+
return async (url, fnOpts = {}) => {
|
|
22
22
|
const browserlessPromise = getBrowserless()
|
|
23
23
|
let isRejected = false
|
|
24
24
|
let subprocess
|
|
@@ -36,9 +36,9 @@ module.exports = (
|
|
|
36
36
|
subprocess.send({
|
|
37
37
|
url,
|
|
38
38
|
code: fn.toString(),
|
|
39
|
-
query,
|
|
40
39
|
browserWSEndpoint,
|
|
41
|
-
...opts
|
|
40
|
+
...opts,
|
|
41
|
+
...fnOpts
|
|
42
42
|
})
|
|
43
43
|
|
|
44
44
|
const { value, reason, isFulfilled } = await pEvent(subprocess, 'message')
|