@browserless.io/browserless 2.4.0-beta-1 → 2.4.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 +14 -1
- package/bin/scaffold/README.md +2 -0
- package/build/browserless.d.ts +4 -2
- package/build/browserless.js +17 -4
- package/build/browsers/chromium.cdp.d.ts +1 -5
- package/build/browsers/chromium.cdp.js +5 -115
- package/build/browsers/chromium.playwright.d.ts +1 -3
- package/build/browsers/chromium.playwright.js +1 -6
- package/build/browsers/firefox.playwright.d.ts +1 -3
- package/build/browsers/firefox.playwright.js +1 -6
- package/build/browsers/index.d.ts +5 -1
- package/build/browsers/index.js +6 -5
- package/build/browsers/webkit.playwright.d.ts +1 -3
- package/build/browsers/webkit.playwright.js +1 -6
- package/build/config.d.ts +9 -0
- package/build/config.js +11 -0
- package/build/constants.d.ts +0 -1
- package/build/constants.js +0 -1
- package/build/file-system.d.ts +12 -1
- package/build/file-system.js +14 -1
- package/build/http.d.ts +0 -7
- package/build/limiter.d.ts +9 -0
- package/build/limiter.js +11 -0
- package/build/metrics.d.ts +12 -1
- package/build/metrics.js +13 -1
- package/build/monitoring.d.ts +12 -1
- package/build/monitoring.js +14 -1
- package/build/router.d.ts +12 -2
- package/build/router.js +16 -6
- package/build/routes/chrome/http/content.post.body.json +8 -8
- package/build/routes/chrome/http/content.post.query.json +0 -4
- package/build/routes/chrome/http/download.post.query.json +0 -4
- package/build/routes/chrome/http/function.post.query.json +0 -4
- package/build/routes/chrome/http/pdf.post.body.json +8 -11
- package/build/routes/chrome/http/pdf.post.query.json +0 -4
- package/build/routes/chrome/http/performance.post.query.json +0 -4
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.query.json +0 -4
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.query.json +0 -4
- package/build/routes/chrome/ws/browser.query.json +0 -4
- package/build/routes/chrome/ws/cdp.query.json +0 -4
- package/build/routes/chrome/ws/page.query.json +0 -4
- package/build/routes/chrome/ws/playwright.query.json +0 -4
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/content.post.query.json +0 -4
- package/build/routes/chromium/http/download.post.query.json +0 -4
- package/build/routes/chromium/http/function.post.query.json +0 -4
- package/build/routes/chromium/http/pdf.post.body.json +8 -11
- package/build/routes/chromium/http/pdf.post.query.json +0 -4
- package/build/routes/chromium/http/performance.post.query.json +0 -4
- package/build/routes/chromium/http/scrape.post.body.json +8 -8
- package/build/routes/chromium/http/scrape.post.query.json +0 -4
- package/build/routes/chromium/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/http/screenshot.post.query.json +0 -4
- package/build/routes/chromium/ws/browser.query.json +0 -4
- package/build/routes/chromium/ws/cdp.query.json +0 -4
- package/build/routes/chromium/ws/page.query.json +0 -4
- package/build/routes/chromium/ws/playwright.query.json +0 -4
- package/build/routes/firefox/ws/playwright.query.json +0 -4
- package/build/routes/webkit/ws/playwright.query.json +0 -4
- package/build/server.d.ts +8 -3
- package/build/server.js +15 -13
- package/build/shared/content.http.js +1 -1
- package/build/shared/pdf.http.d.ts +0 -1
- package/build/shared/pdf.http.js +1 -1
- package/build/shared/screenshot.http.js +1 -1
- package/build/token.d.ts +12 -1
- package/build/token.js +14 -1
- package/build/types.d.ts +3 -14
- package/build/webhooks.d.ts +12 -1
- package/build/webhooks.js +14 -1
- package/extensions/.gitkeep +0 -0
- package/package.json +8 -8
- package/src/browserless.ts +17 -4
- package/src/browsers/chromium.cdp.ts +10 -157
- package/src/browsers/chromium.playwright.ts +0 -8
- package/src/browsers/firefox.playwright.ts +0 -8
- package/src/browsers/index.ts +7 -6
- package/src/browsers/webkit.playwright.ts +0 -8
- package/src/config.ts +13 -0
- package/src/constants.ts +0 -1
- package/src/file-system.ts +16 -1
- package/src/http.ts +0 -8
- package/src/limiter.ts +13 -0
- package/src/metrics.ts +16 -1
- package/src/monitoring.ts +18 -2
- package/src/router.ts +20 -9
- package/src/server.ts +18 -16
- package/src/shared/content.http.ts +5 -4
- package/src/shared/pdf.http.ts +4 -5
- package/src/shared/screenshot.http.ts +4 -4
- package/src/token.ts +18 -2
- package/src/types.ts +0 -13
- package/src/webhooks.ts +18 -2
- package/static/docs/swagger.json +10 -192
- package/static/docs/swagger.min.json +9 -191
- package/extensions/screencast/background.js +0 -143
- package/extensions/screencast/content_script.js +0 -18
- package/extensions/screencast/manifest.json +0 -19
package/src/server.ts
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
shimLegacyRequests,
|
|
24
24
|
writeResponse,
|
|
25
25
|
} from '@browserless.io/browserless';
|
|
26
|
+
import { EventEmitter } from 'events';
|
|
26
27
|
|
|
27
28
|
// @ts-ignore
|
|
28
29
|
import Enjoi from 'enjoi';
|
|
@@ -35,7 +36,7 @@ export interface HTTPServerOptions {
|
|
|
35
36
|
timeout: number;
|
|
36
37
|
}
|
|
37
38
|
|
|
38
|
-
export class HTTPServer {
|
|
39
|
+
export class HTTPServer extends EventEmitter {
|
|
39
40
|
protected server: http.Server = http.createServer();
|
|
40
41
|
protected port: number;
|
|
41
42
|
protected host?: string;
|
|
@@ -48,6 +49,7 @@ export class HTTPServer {
|
|
|
48
49
|
protected token: Token,
|
|
49
50
|
protected router: Router,
|
|
50
51
|
) {
|
|
52
|
+
super();
|
|
51
53
|
this.host = config.getHost();
|
|
52
54
|
this.port = config.getPort();
|
|
53
55
|
|
|
@@ -100,21 +102,6 @@ export class HTTPServer {
|
|
|
100
102
|
});
|
|
101
103
|
}
|
|
102
104
|
|
|
103
|
-
public async stop(): Promise<void> {
|
|
104
|
-
this.log(`HTTP Server is shutting down`);
|
|
105
|
-
await new Promise((r) => this.server.close(r));
|
|
106
|
-
await Promise.all([this.tearDown(), this.router.teardown()]);
|
|
107
|
-
this.log(`HTTP Server shutdown complete`);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
protected tearDown() {
|
|
111
|
-
this.log(`Tearing down all listeners and internal routes`);
|
|
112
|
-
this.server && this.server.removeAllListeners();
|
|
113
|
-
|
|
114
|
-
// @ts-ignore garbage collect this reference
|
|
115
|
-
this.server = null;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
105
|
protected handleRequest = async (
|
|
119
106
|
request: http.IncomingMessage,
|
|
120
107
|
res: http.ServerResponse,
|
|
@@ -410,4 +397,19 @@ export class HTTPServer {
|
|
|
410
397
|
this.log(`No matching WebSocket route handler for "${req.parsed.href}"`);
|
|
411
398
|
return writeResponse(socket, 404, 'Not Found');
|
|
412
399
|
};
|
|
400
|
+
|
|
401
|
+
public async shutdown(): Promise<void> {
|
|
402
|
+
this.log(`HTTP Server is shutting down`);
|
|
403
|
+
await new Promise((r) => this.server.close(r));
|
|
404
|
+
this.server && this.server.removeAllListeners();
|
|
405
|
+
|
|
406
|
+
// @ts-ignore garbage collect this reference
|
|
407
|
+
this.server = null;
|
|
408
|
+
this.log(`HTTP Server shutdown complete`);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
413
|
+
*/
|
|
414
|
+
public stop = () => {};
|
|
413
415
|
}
|
|
@@ -176,6 +176,11 @@ export default class ChromiumContentPostRoute extends BrowserHTTPRoute {
|
|
|
176
176
|
});
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
+
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
180
|
+
bestAttemptCatch(bestAttempt),
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
|
|
179
184
|
if (addStyleTag.length) {
|
|
180
185
|
for (const tag in addStyleTag) {
|
|
181
186
|
await page.addStyleTag(addStyleTag[tag]);
|
|
@@ -188,10 +193,6 @@ export default class ChromiumContentPostRoute extends BrowserHTTPRoute {
|
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
|
|
191
|
-
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
192
|
-
bestAttemptCatch(bestAttempt),
|
|
193
|
-
);
|
|
194
|
-
|
|
195
196
|
if (waitForTimeout) {
|
|
196
197
|
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
197
198
|
}
|
package/src/shared/pdf.http.ts
CHANGED
|
@@ -36,7 +36,6 @@ export interface BodySchema {
|
|
|
36
36
|
addStyleTag?: Array<Parameters<Page['addStyleTag']>[0]>;
|
|
37
37
|
authenticate?: Parameters<Page['authenticate']>[0];
|
|
38
38
|
bestAttempt?: bestAttempt;
|
|
39
|
-
blockModals?: boolean;
|
|
40
39
|
cookies?: Array<Parameters<Page['setCookie']>[0]>;
|
|
41
40
|
emulateMediaType?: Parameters<Page['emulateMediaType']>[0];
|
|
42
41
|
gotoOptions?: Parameters<Page['goto']>[1];
|
|
@@ -185,6 +184,10 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
|
|
|
185
184
|
});
|
|
186
185
|
}
|
|
187
186
|
|
|
187
|
+
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
188
|
+
bestAttemptCatch(bestAttempt),
|
|
189
|
+
);
|
|
190
|
+
|
|
188
191
|
if (addStyleTag.length) {
|
|
189
192
|
for (const tag in addStyleTag) {
|
|
190
193
|
await page.addStyleTag(addStyleTag[tag]);
|
|
@@ -197,10 +200,6 @@ export default class ChromiumPDFPostRoute extends BrowserHTTPRoute {
|
|
|
197
200
|
}
|
|
198
201
|
}
|
|
199
202
|
|
|
200
|
-
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
201
|
-
bestAttemptCatch(bestAttempt),
|
|
202
|
-
);
|
|
203
|
-
|
|
204
203
|
if (waitForTimeout) {
|
|
205
204
|
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
206
205
|
}
|
|
@@ -191,6 +191,10 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
|
|
|
191
191
|
});
|
|
192
192
|
}
|
|
193
193
|
|
|
194
|
+
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
195
|
+
bestAttemptCatch(bestAttempt),
|
|
196
|
+
);
|
|
197
|
+
|
|
194
198
|
if (addStyleTag.length) {
|
|
195
199
|
for (const tag in addStyleTag) {
|
|
196
200
|
await page.addStyleTag(addStyleTag[tag]);
|
|
@@ -203,10 +207,6 @@ export default class ScreenshotPost extends BrowserHTTPRoute {
|
|
|
203
207
|
}
|
|
204
208
|
}
|
|
205
209
|
|
|
206
|
-
const gotoResponse = await gotoCall(content, gotoOptions).catch(
|
|
207
|
-
bestAttemptCatch(bestAttempt),
|
|
208
|
-
);
|
|
209
|
-
|
|
210
210
|
if (waitForTimeout) {
|
|
211
211
|
await sleep(waitForTimeout).catch(bestAttemptCatch(bestAttempt));
|
|
212
212
|
}
|
package/src/token.ts
CHANGED
|
@@ -7,9 +7,12 @@ import {
|
|
|
7
7
|
WebSocketRoute,
|
|
8
8
|
getTokenFromRequest,
|
|
9
9
|
} from '@browserless.io/browserless';
|
|
10
|
+
import { EventEmitter } from 'events';
|
|
10
11
|
|
|
11
|
-
export class Token {
|
|
12
|
-
constructor(protected config: Config) {
|
|
12
|
+
export class Token extends EventEmitter {
|
|
13
|
+
constructor(protected config: Config) {
|
|
14
|
+
super();
|
|
15
|
+
}
|
|
13
16
|
|
|
14
17
|
public isAuthorized = async (
|
|
15
18
|
req: Request,
|
|
@@ -37,4 +40,17 @@ export class Token {
|
|
|
37
40
|
|
|
38
41
|
return (Array.isArray(token) ? token : [token]).includes(requestToken);
|
|
39
42
|
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Implement any browserless-core-specific shutdown logic here.
|
|
46
|
+
* Calls the empty-SDK stop method for downstream implementations.
|
|
47
|
+
*/
|
|
48
|
+
public shutdown = async () => {
|
|
49
|
+
await this.stop();
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
54
|
+
*/
|
|
55
|
+
public stop = () => {};
|
|
40
56
|
}
|
package/src/types.ts
CHANGED
|
@@ -478,19 +478,6 @@ export const debugScreenshotOpts: ScreenshotOptions = {
|
|
|
478
478
|
type: 'jpeg',
|
|
479
479
|
};
|
|
480
480
|
|
|
481
|
-
declare global {
|
|
482
|
-
interface Window {
|
|
483
|
-
browserless: BrowserlessEmbeddedAPI;
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
export interface BrowserlessEmbeddedAPI {
|
|
488
|
-
getRecording: () => Promise<string>;
|
|
489
|
-
liveUrl: () => string;
|
|
490
|
-
saveRecording: () => Promise<boolean>;
|
|
491
|
-
startRecording: () => void;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
481
|
/**
|
|
495
482
|
* When bestAttempt is set to true, browserless attempt to proceed
|
|
496
483
|
* when "awaited" events fail or timeout. This includes things like
|
package/src/webhooks.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { Config, fetchTimeout, noop } from '@browserless.io/browserless';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
2
3
|
|
|
3
|
-
export class WebHooks {
|
|
4
|
-
constructor(protected config: Config) {
|
|
4
|
+
export class WebHooks extends EventEmitter {
|
|
5
|
+
constructor(protected config: Config) {
|
|
6
|
+
super();
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
protected callURL(url: string | null) {
|
|
7
10
|
if (url) {
|
|
@@ -47,4 +50,17 @@ export class WebHooks {
|
|
|
47
50
|
);
|
|
48
51
|
}
|
|
49
52
|
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Implement any browserless-core-specific shutdown logic here.
|
|
56
|
+
* Calls the empty-SDK stop method for downstream implementations.
|
|
57
|
+
*/
|
|
58
|
+
public shutdown = async () => {
|
|
59
|
+
await this.stop();
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Left blank for downstream SDK modules to optionally implement.
|
|
64
|
+
*/
|
|
65
|
+
public stop = () => {};
|
|
50
66
|
}
|