@browserless.io/browserless 2.12.0-beta-4 → 2.12.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/CHANGELOG.md +9 -1
- package/bin/scaffold/README.md +6 -5
- package/bin/scaffold/src/hello-world.http.ts +3 -3
- package/build/browserless.d.ts +3 -3
- package/build/browserless.js +6 -6
- package/build/browsers/chromium.cdp.d.ts +12 -12
- package/build/browsers/chromium.cdp.js +77 -65
- package/build/browsers/chromium.playwright.d.ts +11 -11
- package/build/browsers/chromium.playwright.js +42 -34
- package/build/browsers/firefox.playwright.d.ts +11 -11
- package/build/browsers/firefox.playwright.js +42 -34
- package/build/browsers/index.d.ts +14 -14
- package/build/browsers/index.js +27 -25
- package/build/browsers/webkit.playwright.d.ts +11 -11
- package/build/browsers/webkit.playwright.js +43 -35
- package/build/config.d.ts +65 -63
- package/build/config.js +162 -102
- package/build/file-system.d.ts +4 -4
- package/build/file-system.js +8 -8
- package/build/hooks.d.ts +2 -2
- package/build/hooks.js +4 -4
- package/build/limiter.d.ts +4 -4
- package/build/limiter.js +10 -10
- package/build/logger.d.ts +6 -6
- package/build/logger.js +12 -12
- package/build/metrics.d.ts +12 -12
- package/build/metrics.js +23 -23
- package/build/monitoring.d.ts +4 -4
- package/build/monitoring.js +8 -8
- package/build/router.d.ts +8 -8
- package/build/router.js +74 -70
- package/build/routes/chrome/http/pdf.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/pdf.post.body.json +8 -8
- package/build/routes/chromium/http/scrape.post.body.json +8 -8
- package/build/routes/chromium/http/screenshot.post.body.json +8 -8
- package/build/routes/firefox/ws/playwright.d.ts +1 -1
- package/build/routes/firefox/ws/playwright.js +2 -2
- package/build/routes/management/http/active.get.d.ts +1 -1
- package/build/routes/management/http/active.get.js +3 -1
- package/build/routes/management/http/config.get.d.ts +1 -1
- package/build/routes/management/http/config.get.js +2 -2
- package/build/routes/management/http/metrics-total.get.d.ts +1 -1
- package/build/routes/management/http/metrics-total.get.js +2 -2
- package/build/routes/management/http/metrics.get.d.ts +1 -1
- package/build/routes/management/http/metrics.get.js +2 -2
- package/build/routes/management/http/pressure.get.d.ts +1 -1
- package/build/routes/management/http/pressure.get.js +2 -2
- package/build/routes/management/http/sessions.get.d.ts +1 -1
- package/build/routes/management/http/sessions.get.js +2 -2
- package/build/routes/management/http/static.get.d.ts +1 -1
- package/build/routes/management/http/static.get.js +2 -2
- package/build/routes/webkit/ws/playwright.d.ts +1 -1
- package/build/routes/webkit/ws/playwright.js +2 -2
- package/build/server.d.ts +5 -5
- package/build/server.js +11 -11
- package/build/shared/browser.ws.d.ts +1 -1
- package/build/shared/browser.ws.js +3 -1
- package/build/shared/chromium.playwright.ws.d.ts +1 -1
- package/build/shared/chromium.playwright.ws.js +2 -2
- package/build/shared/chromium.ws.d.ts +1 -1
- package/build/shared/chromium.ws.js +3 -1
- package/build/shared/content.http.d.ts +1 -1
- package/build/shared/content.http.js +2 -2
- package/build/shared/download.http.d.ts +1 -1
- package/build/shared/download.http.js +60 -58
- package/build/shared/function.http.d.ts +1 -1
- package/build/shared/function.http.js +2 -2
- package/build/shared/json-list.http.d.ts +1 -1
- package/build/shared/json-list.http.js +2 -2
- package/build/shared/json-new.http.d.ts +1 -1
- package/build/shared/json-new.http.js +2 -2
- package/build/shared/json-protocol.http.d.ts +1 -1
- package/build/shared/json-protocol.http.js +2 -2
- package/build/shared/json-version.http.d.ts +1 -1
- package/build/shared/json-version.http.js +2 -2
- package/build/shared/page.ws.d.ts +1 -1
- package/build/shared/page.ws.js +3 -1
- package/build/shared/pdf.http.d.ts +1 -1
- package/build/shared/pdf.http.js +2 -2
- package/build/shared/performance.http.d.ts +1 -1
- package/build/shared/performance.http.js +2 -2
- package/build/shared/scrape.http.d.ts +1 -1
- package/build/shared/scrape.http.js +2 -2
- package/build/shared/screenshot.http.d.ts +1 -1
- package/build/shared/screenshot.http.js +2 -2
- package/build/shared/utils/function/client.d.ts +1 -1
- package/build/shared/utils/function/client.js +3 -1
- package/build/shim.d.ts +1 -1
- package/build/shim.js +2 -2
- package/build/token.d.ts +3 -3
- package/build/token.js +6 -6
- package/build/types.d.ts +4 -4
- package/build/webhooks.d.ts +2 -2
- package/build/webhooks.js +4 -4
- package/package.json +3 -3
- package/src/browserless.ts +6 -6
- package/src/browsers/chromium.cdp.ts +33 -23
- package/src/browsers/chromium.playwright.ts +28 -21
- package/src/browsers/firefox.playwright.ts +28 -21
- package/src/browsers/index.ts +32 -29
- package/src/browsers/webkit.playwright.ts +29 -22
- package/src/config.ts +166 -104
- package/src/file-system.ts +9 -9
- package/src/hooks.ts +4 -4
- package/src/limiter.ts +12 -12
- package/src/logger.ts +12 -12
- package/src/metrics.ts +23 -23
- package/src/monitoring.ts +9 -9
- package/src/router.ts +31 -31
- package/src/routes/firefox/ws/playwright.ts +3 -3
- package/src/routes/management/http/active.get.ts +3 -2
- package/src/routes/management/http/config.get.ts +2 -2
- package/src/routes/management/http/metrics-total.get.ts +2 -2
- package/src/routes/management/http/metrics.get.ts +2 -2
- package/src/routes/management/http/pressure.get.ts +2 -2
- package/src/routes/management/http/sessions.get.ts +2 -2
- package/src/routes/management/http/static.get.ts +3 -3
- package/src/routes/webkit/ws/playwright.ts +3 -3
- package/src/server.ts +14 -16
- package/src/shared/browser.ws.ts +4 -2
- package/src/shared/chromium.playwright.ws.ts +3 -3
- package/src/shared/chromium.ws.ts +4 -2
- package/src/shared/content.http.ts +3 -3
- package/src/shared/download.http.ts +4 -3
- package/src/shared/function.http.ts +3 -3
- package/src/shared/json-list.http.ts +2 -2
- package/src/shared/json-new.http.ts +2 -2
- package/src/shared/json-protocol.http.ts +2 -6
- package/src/shared/json-version.http.ts +2 -6
- package/src/shared/page.ws.ts +4 -2
- package/src/shared/pdf.http.ts +3 -3
- package/src/shared/performance.http.ts +3 -3
- package/src/shared/scrape.http.ts +3 -3
- package/src/shared/screenshot.http.ts +3 -3
- package/src/shared/utils/function/client.ts +3 -1
- package/src/shim.ts +2 -2
- package/src/token.ts +7 -7
- package/src/types.ts +7 -7
- package/src/webhooks.ts +4 -4
- package/static/docs/swagger.json +2 -2
- package/static/docs/swagger.min.json +1 -1
- package/static/function/client.js +3 -1
- package/static/function/index.html +3 -1
|
@@ -27,11 +27,7 @@ export default class ChromiumJSONProtocolGetRoute extends HTTPRoute {
|
|
|
27
27
|
path = HTTPRoutes.jsonProtocol;
|
|
28
28
|
tags = [APITags.browserAPI];
|
|
29
29
|
|
|
30
|
-
handler
|
|
31
|
-
_req: Request,
|
|
32
|
-
res: Response,
|
|
33
|
-
logger: Logger,
|
|
34
|
-
): Promise<void> => {
|
|
30
|
+
async handler(_req: Request, res: Response, logger: Logger): Promise<void> {
|
|
35
31
|
const browserManager = this.browserManager();
|
|
36
32
|
|
|
37
33
|
if (!this.cachedProtocol) {
|
|
@@ -39,5 +35,5 @@ export default class ChromiumJSONProtocolGetRoute extends HTTPRoute {
|
|
|
39
35
|
}
|
|
40
36
|
|
|
41
37
|
return jsonResponse(res, 200, this.cachedProtocol);
|
|
42
|
-
}
|
|
38
|
+
}
|
|
43
39
|
}
|
|
@@ -31,11 +31,7 @@ export default class ChromiumJSONVersionGetRoute extends HTTPRoute {
|
|
|
31
31
|
method = Methods.get;
|
|
32
32
|
path = HTTPRoutes.jsonVersion;
|
|
33
33
|
tags = [APITags.browserAPI];
|
|
34
|
-
handler
|
|
35
|
-
req: Request,
|
|
36
|
-
res: Response,
|
|
37
|
-
logger: Logger,
|
|
38
|
-
): Promise<void> => {
|
|
34
|
+
async handler(req: Request, res: Response, logger: Logger): Promise<void> {
|
|
39
35
|
const baseUrl = req.parsed.host;
|
|
40
36
|
const protocol = req.parsed.protocol.includes('s') ? 'wss' : 'ws';
|
|
41
37
|
|
|
@@ -56,5 +52,5 @@ export default class ChromiumJSONVersionGetRoute extends HTTPRoute {
|
|
|
56
52
|
contentTypes.text,
|
|
57
53
|
);
|
|
58
54
|
}
|
|
59
|
-
}
|
|
55
|
+
}
|
|
60
56
|
}
|
package/src/shared/page.ws.ts
CHANGED
|
@@ -29,11 +29,13 @@ export default class ChromiumPageWebSocketRoute extends BrowserWebsocketRoute {
|
|
|
29
29
|
);
|
|
30
30
|
path = WebsocketRoutes.page;
|
|
31
31
|
tags = [APITags.browserWS];
|
|
32
|
-
|
|
32
|
+
async handler(
|
|
33
33
|
req: Request,
|
|
34
34
|
socket: Duplex,
|
|
35
35
|
head: Buffer,
|
|
36
36
|
_logger: Logger,
|
|
37
37
|
browser: ChromiumCDP,
|
|
38
|
-
): Promise<void>
|
|
38
|
+
): Promise<void> {
|
|
39
|
+
return browser.proxyPageWebSocket(req, socket, head);
|
|
40
|
+
}
|
|
39
41
|
}
|
package/src/shared/pdf.http.ts
CHANGED
|
@@ -80,12 +80,12 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
|
|
|
80
80
|
method = Methods.post;
|
|
81
81
|
path = [HTTPRoutes.pdf, HTTPRoutes.chromiumPdf];
|
|
82
82
|
tags = [APITags.browserAPI];
|
|
83
|
-
|
|
83
|
+
async handler(
|
|
84
84
|
req: Request,
|
|
85
85
|
res: ServerResponse,
|
|
86
86
|
logger: Logger,
|
|
87
87
|
browser: BrowserInstance,
|
|
88
|
-
): Promise<void>
|
|
88
|
+
): Promise<void> {
|
|
89
89
|
logger.info('PDF API invoked with body:', req.body);
|
|
90
90
|
const contentType =
|
|
91
91
|
!req.headers.accept || req.headers.accept?.includes('*')
|
|
@@ -246,5 +246,5 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
|
|
|
246
246
|
page.close().catch(noop);
|
|
247
247
|
|
|
248
248
|
logger.info('PDF API request completed');
|
|
249
|
-
}
|
|
249
|
+
}
|
|
250
250
|
}
|
|
@@ -45,12 +45,12 @@ export default class PerformancePost extends BrowserHTTPRoute {
|
|
|
45
45
|
method = Methods.post;
|
|
46
46
|
path = [HTTPRoutes.performance, HTTPRoutes.chromiumPerformance];
|
|
47
47
|
tags = [APITags.browserAPI];
|
|
48
|
-
|
|
48
|
+
async handler(
|
|
49
49
|
req: Request,
|
|
50
50
|
res: ServerResponse,
|
|
51
51
|
_logger: Logger,
|
|
52
52
|
browser: BrowserInstance,
|
|
53
|
-
): Promise<void>
|
|
53
|
+
): Promise<void> {
|
|
54
54
|
const config = this.config();
|
|
55
55
|
const response = await main({
|
|
56
56
|
browser,
|
|
@@ -60,5 +60,5 @@ export default class PerformancePost extends BrowserHTTPRoute {
|
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
return jsonResponse(res, 200, response);
|
|
63
|
-
}
|
|
63
|
+
}
|
|
64
64
|
}
|
|
@@ -216,12 +216,12 @@ export default class ChromiumScrapePostRoute extends BrowserHTTPRoute {
|
|
|
216
216
|
method = Methods.post;
|
|
217
217
|
path = [HTTPRoutes.scrape, HTTPRoutes.chromiumScrape];
|
|
218
218
|
tags = [APITags.browserAPI];
|
|
219
|
-
|
|
219
|
+
async handler(
|
|
220
220
|
req: Request,
|
|
221
221
|
res: ServerResponse,
|
|
222
222
|
logger: Logger,
|
|
223
223
|
browser: BrowserInstance,
|
|
224
|
-
)
|
|
224
|
+
) {
|
|
225
225
|
logger.info('Scrape API invoked with body:', req.body);
|
|
226
226
|
const contentType =
|
|
227
227
|
!req.headers.accept || req.headers.accept?.includes('*')
|
|
@@ -440,5 +440,5 @@ export default class ChromiumScrapePostRoute extends BrowserHTTPRoute {
|
|
|
440
440
|
logger.info('Scrape API request completed');
|
|
441
441
|
|
|
442
442
|
return jsonResponse(res, 200, response, false);
|
|
443
|
-
}
|
|
443
|
+
}
|
|
444
444
|
}
|
|
@@ -83,12 +83,12 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
|
|
|
83
83
|
method = Methods.post;
|
|
84
84
|
path = [HTTPRoutes.screenshot, HTTPRoutes.chromiumScreenshot];
|
|
85
85
|
tags = [APITags.browserAPI];
|
|
86
|
-
|
|
86
|
+
async handler(
|
|
87
87
|
req: Request,
|
|
88
88
|
res: ServerResponse,
|
|
89
89
|
logger: Logger,
|
|
90
90
|
browser: BrowserInstance,
|
|
91
|
-
): Promise<void>
|
|
91
|
+
): Promise<void> {
|
|
92
92
|
logger.info('Screenshot API invoked with body:', req.body);
|
|
93
93
|
const contentType =
|
|
94
94
|
!req.headers.accept || req.headers.accept?.includes('*')
|
|
@@ -267,5 +267,5 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
|
|
|
267
267
|
|
|
268
268
|
page.close().catch(noop);
|
|
269
269
|
logger.info('Screenshot API request completed');
|
|
270
|
-
}
|
|
270
|
+
}
|
|
271
271
|
}
|
|
@@ -11,7 +11,9 @@ export class FunctionRunner {
|
|
|
11
11
|
protected browser?: Browser;
|
|
12
12
|
protected page?: Page;
|
|
13
13
|
|
|
14
|
-
public log
|
|
14
|
+
public log() {
|
|
15
|
+
return console.log.bind(console);
|
|
16
|
+
}
|
|
15
17
|
|
|
16
18
|
public async start(data: {
|
|
17
19
|
browserWSEndpoint: string;
|
package/src/shim.ts
CHANGED
|
@@ -14,7 +14,7 @@ const shimParam = ['headless', 'stealth', 'ignoreDefaultArgs', 'slowMo'];
|
|
|
14
14
|
*
|
|
15
15
|
* @param req A parsed user requests
|
|
16
16
|
*/
|
|
17
|
-
export
|
|
17
|
+
export function shimLegacyRequests(url: URL): URL {
|
|
18
18
|
const { searchParams } = url;
|
|
19
19
|
const params = [...searchParams];
|
|
20
20
|
const names = params.map(([k]) => k);
|
|
@@ -76,4 +76,4 @@ export const shimLegacyRequests = (url: URL): URL => {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
return url;
|
|
79
|
-
}
|
|
79
|
+
}
|
package/src/token.ts
CHANGED
|
@@ -14,14 +14,14 @@ export class Token extends EventEmitter {
|
|
|
14
14
|
super();
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
public
|
|
17
|
+
public async isAuthorized(
|
|
18
18
|
req: Request,
|
|
19
19
|
route:
|
|
20
20
|
| BrowserHTTPRoute
|
|
21
21
|
| BrowserWebsocketRoute
|
|
22
22
|
| HTTPRoute
|
|
23
23
|
| WebSocketRoute,
|
|
24
|
-
): Promise<boolean>
|
|
24
|
+
): Promise<boolean> {
|
|
25
25
|
const token = this.config.getToken();
|
|
26
26
|
|
|
27
27
|
if (token === null) {
|
|
@@ -39,18 +39,18 @@ export class Token extends EventEmitter {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
return (Array.isArray(token) ? token : [token]).includes(requestToken);
|
|
42
|
-
}
|
|
42
|
+
}
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* Implement any browserless-core-specific shutdown logic here.
|
|
46
46
|
* Calls the empty-SDK stop method for downstream implementations.
|
|
47
47
|
*/
|
|
48
|
-
public
|
|
49
|
-
await this.stop();
|
|
50
|
-
}
|
|
48
|
+
public async shutdown() {
|
|
49
|
+
return await this.stop();
|
|
50
|
+
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Left blank for downstream SDK modules to optionally implement.
|
|
54
54
|
*/
|
|
55
|
-
public stop
|
|
55
|
+
public stop() {}
|
|
56
56
|
}
|
package/src/types.ts
CHANGED
|
@@ -251,11 +251,11 @@ export abstract class HTTPRoute extends BasicHTTPRoute {
|
|
|
251
251
|
/**
|
|
252
252
|
* Handles an inbound HTTP request, and supplies the Request and Response objects from node's HTTP request event
|
|
253
253
|
*/
|
|
254
|
-
abstract handler
|
|
254
|
+
abstract handler(
|
|
255
255
|
req: Request,
|
|
256
256
|
res: http.ServerResponse,
|
|
257
257
|
logger: Logger,
|
|
258
|
-
)
|
|
258
|
+
): Promise<unknown>;
|
|
259
259
|
}
|
|
260
260
|
|
|
261
261
|
/**
|
|
@@ -272,12 +272,12 @@ export abstract class BrowserHTTPRoute extends BasicHTTPRoute {
|
|
|
272
272
|
* Handles an inbound HTTP request with a 3rd param of the predefined
|
|
273
273
|
* browser used for the route -- only Chrome CDP is support currently.
|
|
274
274
|
*/
|
|
275
|
-
abstract handler
|
|
275
|
+
abstract handler(
|
|
276
276
|
req: Request,
|
|
277
277
|
res: http.ServerResponse,
|
|
278
278
|
logger: Logger,
|
|
279
279
|
browser: BrowserInstance,
|
|
280
|
-
)
|
|
280
|
+
): Promise<unknown>;
|
|
281
281
|
|
|
282
282
|
/**
|
|
283
283
|
* An optional function to automatically set up or handle new page
|
|
@@ -296,12 +296,12 @@ export abstract class WebSocketRoute extends Route {
|
|
|
296
296
|
/**
|
|
297
297
|
* Handles an inbound Websocket request, and handles the connection
|
|
298
298
|
*/
|
|
299
|
-
abstract handler
|
|
299
|
+
abstract handler(
|
|
300
300
|
req: Request,
|
|
301
301
|
socket: stream.Duplex,
|
|
302
302
|
head: Buffer,
|
|
303
303
|
logger: Logger,
|
|
304
|
-
)
|
|
304
|
+
): Promise<unknown>;
|
|
305
305
|
}
|
|
306
306
|
|
|
307
307
|
/**
|
|
@@ -382,7 +382,7 @@ export interface BrowserlessSession {
|
|
|
382
382
|
isTempDataDir: boolean;
|
|
383
383
|
launchOptions: CDPLaunchOptions | BrowserServerOptions;
|
|
384
384
|
numbConnected: number;
|
|
385
|
-
resolver
|
|
385
|
+
resolver(val: unknown): void;
|
|
386
386
|
routePath: string | string[];
|
|
387
387
|
startedOn: number;
|
|
388
388
|
ttl: number;
|
package/src/webhooks.ts
CHANGED
|
@@ -55,12 +55,12 @@ export class WebHooks extends EventEmitter {
|
|
|
55
55
|
* Implement any browserless-core-specific shutdown logic here.
|
|
56
56
|
* Calls the empty-SDK stop method for downstream implementations.
|
|
57
57
|
*/
|
|
58
|
-
public
|
|
59
|
-
await this.stop();
|
|
60
|
-
}
|
|
58
|
+
public async shutdown() {
|
|
59
|
+
return await this.stop();
|
|
60
|
+
}
|
|
61
61
|
|
|
62
62
|
/**
|
|
63
63
|
* Left blank for downstream SDK modules to optionally implement.
|
|
64
64
|
*/
|
|
65
|
-
public stop
|
|
65
|
+
public stop() {}
|
|
66
66
|
}
|