@browserless.io/browserless 2.12.0-beta-3 → 2.12.0-beta-6

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.
Files changed (199) hide show
  1. package/build/browserless.d.ts +3 -3
  2. package/build/browserless.js +6 -6
  3. package/build/browsers/chromium.cdp.d.ts +13 -13
  4. package/build/browsers/chromium.cdp.js +79 -67
  5. package/build/browsers/chromium.playwright.d.ts +12 -12
  6. package/build/browsers/chromium.playwright.js +44 -36
  7. package/build/browsers/firefox.playwright.d.ts +12 -12
  8. package/build/browsers/firefox.playwright.js +44 -36
  9. package/build/browsers/index.d.ts +17 -16
  10. package/build/browsers/index.js +63 -42
  11. package/build/browsers/webkit.playwright.d.ts +12 -12
  12. package/build/browsers/webkit.playwright.js +47 -39
  13. package/build/config.d.ts +65 -63
  14. package/build/config.js +162 -102
  15. package/build/file-system.d.ts +4 -4
  16. package/build/file-system.js +8 -8
  17. package/build/hooks.d.ts +2 -2
  18. package/build/hooks.js +4 -4
  19. package/build/limiter.d.ts +4 -4
  20. package/build/limiter.js +10 -10
  21. package/build/logger.d.ts +6 -6
  22. package/build/logger.js +12 -12
  23. package/build/metrics.d.ts +12 -12
  24. package/build/metrics.js +23 -23
  25. package/build/monitoring.d.ts +4 -4
  26. package/build/monitoring.js +8 -8
  27. package/build/router.d.ts +8 -8
  28. package/build/router.js +74 -70
  29. package/build/routes/chrome/http/pdf.post.body.json +8 -8
  30. package/build/routes/chrome/http/scrape.post.body.json +8 -8
  31. package/build/routes/chrome/http/screenshot.post.body.json +8 -8
  32. package/build/routes/chromium/http/content.post.body.json +8 -8
  33. package/build/routes/chromium/http/pdf.post.body.json +8 -8
  34. package/build/routes/chromium/http/scrape.post.body.json +8 -8
  35. package/build/routes/chromium/http/screenshot.post.body.json +8 -8
  36. package/build/routes/firefox/ws/playwright.d.ts +1 -1
  37. package/build/routes/firefox/ws/playwright.js +2 -2
  38. package/build/routes/management/http/active.get.d.ts +1 -1
  39. package/build/routes/management/http/active.get.js +3 -1
  40. package/build/routes/management/http/config.get.d.ts +1 -1
  41. package/build/routes/management/http/config.get.js +2 -2
  42. package/build/routes/management/http/metrics-total.get.d.ts +1 -1
  43. package/build/routes/management/http/metrics-total.get.js +2 -2
  44. package/build/routes/management/http/metrics.get.d.ts +1 -1
  45. package/build/routes/management/http/metrics.get.js +2 -2
  46. package/build/routes/management/http/pressure.get.d.ts +1 -1
  47. package/build/routes/management/http/pressure.get.js +2 -2
  48. package/build/routes/management/http/sessions.get.d.ts +1 -1
  49. package/build/routes/management/http/sessions.get.js +2 -2
  50. package/build/routes/management/http/static.get.d.ts +1 -1
  51. package/build/routes/management/http/static.get.js +2 -2
  52. package/build/routes/webkit/ws/playwright.d.ts +1 -1
  53. package/build/routes/webkit/ws/playwright.js +2 -2
  54. package/build/server.d.ts +5 -5
  55. package/build/server.js +11 -11
  56. package/build/shared/browser.ws.d.ts +1 -1
  57. package/build/shared/browser.ws.js +3 -1
  58. package/build/shared/chromium.playwright.ws.d.ts +1 -1
  59. package/build/shared/chromium.playwright.ws.js +2 -2
  60. package/build/shared/chromium.ws.d.ts +1 -1
  61. package/build/shared/chromium.ws.js +3 -1
  62. package/build/shared/content.http.d.ts +1 -1
  63. package/build/shared/content.http.js +2 -2
  64. package/build/shared/download.http.d.ts +1 -1
  65. package/build/shared/download.http.js +60 -58
  66. package/build/shared/function.http.d.ts +1 -1
  67. package/build/shared/function.http.js +2 -2
  68. package/build/shared/json-list.http.d.ts +1 -1
  69. package/build/shared/json-list.http.js +2 -2
  70. package/build/shared/json-new.http.d.ts +1 -1
  71. package/build/shared/json-new.http.js +2 -2
  72. package/build/shared/json-protocol.http.d.ts +1 -1
  73. package/build/shared/json-protocol.http.js +2 -2
  74. package/build/shared/json-version.http.d.ts +1 -1
  75. package/build/shared/json-version.http.js +2 -2
  76. package/build/shared/page.ws.d.ts +1 -1
  77. package/build/shared/page.ws.js +3 -1
  78. package/build/shared/pdf.http.d.ts +1 -1
  79. package/build/shared/pdf.http.js +2 -2
  80. package/build/shared/performance.http.d.ts +1 -1
  81. package/build/shared/performance.http.js +2 -2
  82. package/build/shared/scrape.http.d.ts +1 -1
  83. package/build/shared/scrape.http.js +2 -2
  84. package/build/shared/screenshot.http.d.ts +1 -1
  85. package/build/shared/screenshot.http.js +2 -2
  86. package/build/shared/utils/function/client.d.ts +1 -1
  87. package/build/shared/utils/function/client.js +3 -1
  88. package/build/shim.d.ts +1 -1
  89. package/build/shim.js +2 -2
  90. package/build/token.d.ts +3 -3
  91. package/build/token.js +6 -6
  92. package/build/types.d.ts +5 -5
  93. package/build/webhooks.d.ts +2 -2
  94. package/build/webhooks.js +4 -4
  95. package/extensions/ublock/_locales/eu/messages.json +4 -4
  96. package/extensions/ublock/_locales/hi/messages.json +5 -5
  97. package/extensions/ublock/_locales/kn/messages.json +11 -11
  98. package/extensions/ublock/_locales/nb/messages.json +2 -2
  99. package/extensions/ublock/_locales/no/messages.json +2 -2
  100. package/extensions/ublock/_locales/ro/messages.json +1 -1
  101. package/extensions/ublock/_locales/sv/messages.json +1 -1
  102. package/extensions/ublock/_locales/zh_CN/messages.json +2 -2
  103. package/extensions/ublock/assets/assets.json +3 -8
  104. package/extensions/ublock/assets/resources/scriptlets.js +128 -31
  105. package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +4870 -3560
  106. package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +662 -173
  107. package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +10 -42
  108. package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +241 -80
  109. package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +2093 -1224
  110. package/extensions/ublock/assets/ublock/badlists.txt +2 -0
  111. package/extensions/ublock/assets/ublock/badware.min.txt +408 -287
  112. package/extensions/ublock/assets/ublock/filters.min.txt +947 -645
  113. package/extensions/ublock/assets/ublock/privacy.min.txt +43 -8
  114. package/extensions/ublock/assets/ublock/quick-fixes.min.txt +55 -93
  115. package/extensions/ublock/assets/ublock/unbreak.min.txt +52 -19
  116. package/extensions/ublock/css/1p-filters.css +2 -0
  117. package/extensions/ublock/css/codemirror.css +2 -2
  118. package/extensions/ublock/css/dashboard.css +2 -5
  119. package/extensions/ublock/css/epicker-ui.css +3 -3
  120. package/extensions/ublock/css/fa-icons.css +3 -0
  121. package/extensions/ublock/css/logger-ui-inspector.css +1 -0
  122. package/extensions/ublock/css/logger-ui.css +44 -32
  123. package/extensions/ublock/img/fontawesome/fontawesome-defs.svg +1 -0
  124. package/extensions/ublock/js/3p-filters.js +4 -5
  125. package/extensions/ublock/js/biditrie.js +16 -11
  126. package/extensions/ublock/js/cachestorage.js +37 -37
  127. package/extensions/ublock/js/contentscript-extra.js +0 -2
  128. package/extensions/ublock/js/contentscript.js +1 -6
  129. package/extensions/ublock/js/epicker-ui.js +28 -36
  130. package/extensions/ublock/js/fa-icons.js +1 -0
  131. package/extensions/ublock/js/hntrie.js +19 -13
  132. package/extensions/ublock/js/logger-ui-inspector.js +6 -13
  133. package/extensions/ublock/js/logger-ui.js +264 -264
  134. package/extensions/ublock/js/s14e-serializer.js +267 -264
  135. package/extensions/ublock/js/scriptlet-filtering.js +12 -18
  136. package/extensions/ublock/js/scriptlets/dom-inspector.js +1 -5
  137. package/extensions/ublock/js/scriptlets/epicker.js +53 -59
  138. package/extensions/ublock/js/start.js +0 -8
  139. package/extensions/ublock/js/storage.js +2 -9
  140. package/extensions/ublock/js/vapi-background.js +19 -20
  141. package/extensions/ublock/js/vapi-common.js +2 -7
  142. package/extensions/ublock/js/vapi.js +0 -4
  143. package/extensions/ublock/js/webext.js +23 -15
  144. package/extensions/ublock/logger-ui.html +24 -15
  145. package/extensions/ublock/manifest.json +2 -3
  146. package/package.json +4 -4
  147. package/src/browserless.ts +6 -6
  148. package/src/browsers/chromium.cdp.ts +35 -25
  149. package/src/browsers/chromium.playwright.ts +30 -23
  150. package/src/browsers/firefox.playwright.ts +30 -24
  151. package/src/browsers/index.ts +81 -50
  152. package/src/browsers/webkit.playwright.ts +33 -26
  153. package/src/config.ts +166 -104
  154. package/src/file-system.ts +9 -9
  155. package/src/hooks.ts +4 -4
  156. package/src/limiter.ts +12 -12
  157. package/src/logger.ts +12 -12
  158. package/src/metrics.ts +23 -23
  159. package/src/monitoring.ts +9 -9
  160. package/src/router.ts +31 -31
  161. package/src/routes/chrome/tests/websocket.spec.ts +2 -2
  162. package/src/routes/chromium/tests/websocket.spec.ts +2 -2
  163. package/src/routes/firefox/tests/websocket.spec.ts +2 -4
  164. package/src/routes/firefox/ws/playwright.ts +3 -3
  165. package/src/routes/management/http/active.get.ts +3 -2
  166. package/src/routes/management/http/config.get.ts +2 -2
  167. package/src/routes/management/http/metrics-total.get.ts +2 -2
  168. package/src/routes/management/http/metrics.get.ts +2 -2
  169. package/src/routes/management/http/pressure.get.ts +2 -2
  170. package/src/routes/management/http/sessions.get.ts +2 -2
  171. package/src/routes/management/http/static.get.ts +3 -3
  172. package/src/routes/webkit/tests/websocket.spec.ts +2 -3
  173. package/src/routes/webkit/ws/playwright.ts +3 -3
  174. package/src/server.ts +14 -16
  175. package/src/shared/browser.ws.ts +4 -2
  176. package/src/shared/chromium.playwright.ws.ts +3 -3
  177. package/src/shared/chromium.ws.ts +4 -2
  178. package/src/shared/content.http.ts +3 -3
  179. package/src/shared/download.http.ts +4 -3
  180. package/src/shared/function.http.ts +3 -3
  181. package/src/shared/json-list.http.ts +2 -2
  182. package/src/shared/json-new.http.ts +2 -2
  183. package/src/shared/json-protocol.http.ts +2 -6
  184. package/src/shared/json-version.http.ts +2 -6
  185. package/src/shared/page.ws.ts +4 -2
  186. package/src/shared/pdf.http.ts +3 -3
  187. package/src/shared/performance.http.ts +3 -3
  188. package/src/shared/scrape.http.ts +3 -3
  189. package/src/shared/screenshot.http.ts +3 -3
  190. package/src/shared/utils/function/client.ts +3 -1
  191. package/src/shim.ts +2 -2
  192. package/src/token.ts +7 -7
  193. package/src/types.ts +8 -8
  194. package/src/utils.ts +1 -1
  195. package/src/webhooks.ts +4 -4
  196. package/static/docs/swagger.json +1 -1
  197. package/static/docs/swagger.min.json +1 -1
  198. package/static/function/client.js +3 -1
  199. package/static/function/index.html +3 -1
package/src/limiter.ts CHANGED
@@ -19,7 +19,7 @@ export type ErrorFn<TArgs extends unknown[]> = (...args: TArgs) => void;
19
19
  interface Job {
20
20
  (): Promise<unknown>;
21
21
  args: unknown[];
22
- onTimeoutFn: (job: Job) => unknown;
22
+ onTimeoutFn(job: Job): unknown;
23
23
  start: number;
24
24
  timeout: number;
25
25
  }
@@ -62,15 +62,15 @@ export class Limiter extends q {
62
62
  });
63
63
 
64
64
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
- this.addEventListener('timeout', this.handleJobTimeout as any);
65
+ this.addEventListener('timeout', this.handleJobTimeout.bind(this) as any);
66
66
 
67
67
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
- this.addEventListener('success', this.handleSuccess as any);
68
+ this.addEventListener('success', this.handleSuccess.bind(this) as any);
69
69
 
70
70
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
71
- this.addEventListener('error', this.handleFail as any);
71
+ this.addEventListener('error', this.handleFail.bind(this) as any);
72
72
 
73
- this.addEventListener('end', this.handleEnd);
73
+ this.addEventListener('end', this.handleEnd.bind(this));
74
74
  }
75
75
 
76
76
  protected handleEnd() {
@@ -160,12 +160,12 @@ export class Limiter extends q {
160
160
  return this.length < this.concurrency + this.queued;
161
161
  }
162
162
 
163
- public limit = <TArgs extends unknown[], TResult>(
163
+ public limit<TArgs extends unknown[], TResult>(
164
164
  limitFn: LimitFn<TArgs, TResult>,
165
165
  overCapacityFn: ErrorFn<TArgs>,
166
166
  onTimeoutFn: ErrorFn<TArgs>,
167
167
  timeoutOverrideFn: (...args: TArgs) => number | undefined,
168
- ): LimitFn<TArgs, unknown> => {
168
+ ): LimitFn<TArgs, unknown> {
169
169
  return (...args: TArgs) =>
170
170
  new Promise(async (res, rej) => {
171
171
  const timeout = timeoutOverrideFn(...args) ?? this.timeout;
@@ -227,18 +227,18 @@ export class Limiter extends q {
227
227
 
228
228
  return bound;
229
229
  });
230
- };
230
+ }
231
231
 
232
232
  /**
233
233
  * Implement any browserless-core-specific shutdown logic here.
234
234
  * Calls the empty-SDK stop method for downstream implementations.
235
235
  */
236
- public shutdown = async () => {
237
- await this.stop();
238
- };
236
+ public async shutdown() {
237
+ return await this.stop();
238
+ }
239
239
 
240
240
  /**
241
241
  * Left blank for downstream SDK modules to optionally implement.
242
242
  */
243
- public stop = () => {};
243
+ public stop() {}
244
244
  }
package/src/logger.ts CHANGED
@@ -26,27 +26,27 @@ export class Logger {
26
26
  return this.request ? this.request.socket.remoteAddress ?? 'Unknown' : '';
27
27
  }
28
28
 
29
- public trace = (...messages: unknown[]) => {
29
+ public trace(...messages: unknown[]) {
30
30
  this._trace(this.reqInfo, ...messages);
31
- };
31
+ }
32
32
 
33
- public debug = (...messages: unknown[]) => {
33
+ public debug(...messages: unknown[]) {
34
34
  this._debug(this.reqInfo, ...messages);
35
- };
35
+ }
36
36
 
37
- public info = (...messages: unknown[]) => {
37
+ public info(...messages: unknown[]) {
38
38
  this._info(this.reqInfo, ...messages);
39
- };
39
+ }
40
40
 
41
- public warn = (...messages: unknown[]) => {
41
+ public warn(...messages: unknown[]) {
42
42
  this._warn(this.reqInfo, ...messages);
43
- };
43
+ }
44
44
 
45
- public error = (...messages: unknown[]) => {
45
+ public error(...messages: unknown[]) {
46
46
  this._error(this.reqInfo, ...messages);
47
- };
47
+ }
48
48
 
49
- public fatal = (...messages: unknown[]) => {
49
+ public fatal(...messages: unknown[]) {
50
50
  this._fatal(this.reqInfo, ...messages);
51
- };
51
+ }
52
52
  }
package/src/metrics.ts CHANGED
@@ -14,41 +14,41 @@ export class Metrics extends EventEmitter {
14
14
  protected unhealthy = 0;
15
15
  protected error = 0;
16
16
 
17
- addSuccessful = (sessionTime: number): number => {
17
+ addSuccessful(sessionTime: number): number {
18
18
  --this.running;
19
19
  this.sessionTimes.push(sessionTime);
20
20
  return ++this.successful;
21
- };
21
+ }
22
22
 
23
- addTimedout = (sessionTime: number): number => {
23
+ addTimedout(sessionTime: number): number {
24
24
  --this.running;
25
25
  this.sessionTimes.push(sessionTime);
26
26
  return ++this.timedout;
27
- };
27
+ }
28
28
 
29
- addError = (sessionTime: number): number => {
29
+ addError(sessionTime: number): number {
30
30
  --this.running;
31
31
  this.sessionTimes.push(sessionTime);
32
32
  return ++this.error;
33
- };
33
+ }
34
34
 
35
- addQueued = (): number => {
35
+ addQueued(): number {
36
36
  return ++this.queued;
37
- };
37
+ }
38
38
 
39
- addRejected = (): number => {
39
+ addRejected(): number {
40
40
  return ++this.rejected;
41
- };
41
+ }
42
42
 
43
- addUnhealthy = (): number => {
43
+ addUnhealthy(): number {
44
44
  return ++this.unhealthy;
45
- };
45
+ }
46
46
 
47
- addUnauthorized = (): number => {
47
+ addUnauthorized(): number {
48
48
  return ++this.unauthorized;
49
- };
49
+ }
50
50
 
51
- addRunning = (): number => {
51
+ addRunning(): number {
52
52
  ++this.running;
53
53
 
54
54
  if (this.concurrent < this.running) {
@@ -56,9 +56,9 @@ export class Metrics extends EventEmitter {
56
56
  }
57
57
 
58
58
  return this.running;
59
- };
59
+ }
60
60
 
61
- public get = (): Omit<IBrowserlessStats, 'cpu' | 'memory'> => {
61
+ public get(): Omit<IBrowserlessStats, 'cpu' | 'memory'> {
62
62
  const currentStat = {
63
63
  error: this.error,
64
64
  maxConcurrent: this.concurrent,
@@ -77,9 +77,9 @@ export class Metrics extends EventEmitter {
77
77
  ...this.calculateStats(currentStat.sessionTimes),
78
78
  date: Date.now(),
79
79
  };
80
- };
80
+ }
81
81
 
82
- public reset = () => {
82
+ public reset() {
83
83
  this.successful = 0;
84
84
  this.error = 0;
85
85
  this.queued = 0;
@@ -90,7 +90,7 @@ export class Metrics extends EventEmitter {
90
90
  this.running = 0;
91
91
  this.unhealthy = 0;
92
92
  this.sessionTimes = [];
93
- };
93
+ }
94
94
 
95
95
  protected calculateStats(sessionTimes: number[]) {
96
96
  return {
@@ -112,12 +112,12 @@ export class Metrics extends EventEmitter {
112
112
  * Implement any browserless-core-specific shutdown logic here.
113
113
  * Calls the empty-SDK stop method for downstream implementations.
114
114
  */
115
- public shutdown = async () => {
115
+ public async shutdown() {
116
116
  await this.stop();
117
- };
117
+ }
118
118
 
119
119
  /**
120
120
  * Left blank for downstream SDK modules to optionally implement.
121
121
  */
122
- public stop = () => {};
122
+ public stop() {}
123
123
  }
package/src/monitoring.ts CHANGED
@@ -8,7 +8,7 @@ export class Monitoring extends EventEmitter {
8
8
  super();
9
9
  }
10
10
 
11
- public getMachineStats = async (): Promise<IResourceLoad> => {
11
+ public async getMachineStats(): Promise<IResourceLoad> {
12
12
  const [cpuLoad, memLoad] = await Promise.all([
13
13
  si.currentLoad(),
14
14
  si.mem(),
@@ -24,14 +24,14 @@ export class Monitoring extends EventEmitter {
24
24
  cpu,
25
25
  memory,
26
26
  };
27
- };
27
+ }
28
28
 
29
- public overloaded = async (): Promise<{
29
+ public async overloaded(): Promise<{
30
30
  cpuInt: number | null;
31
31
  cpuOverloaded: boolean;
32
32
  memoryInt: number | null;
33
33
  memoryOverloaded: boolean;
34
- }> => {
34
+ }> {
35
35
  const { cpu, memory } = await this.getMachineStats();
36
36
  const cpuInt = cpu && Math.ceil(cpu * 100);
37
37
  const memoryInt = memory && Math.ceil(memory * 100);
@@ -50,18 +50,18 @@ export class Monitoring extends EventEmitter {
50
50
  memoryInt,
51
51
  memoryOverloaded,
52
52
  };
53
- };
53
+ }
54
54
 
55
55
  /**
56
56
  * Implement any browserless-core-specific shutdown logic here.
57
57
  * Calls the empty-SDK stop method for downstream implementations.
58
58
  */
59
- public shutdown = async () => {
60
- await this.stop();
61
- };
59
+ public async shutdown() {
60
+ return await this.stop();
61
+ }
62
62
 
63
63
  /**
64
64
  * Left blank for downstream SDK modules to optionally implement.
65
65
  */
66
- public stop = () => {};
66
+ public stop() {}
67
67
  }
package/src/router.ts CHANGED
@@ -40,32 +40,31 @@ export class Router extends EventEmitter {
40
40
  return timer ? +timer : undefined;
41
41
  }
42
42
 
43
- protected onQueueFullHTTP = (_req: Request, res: Response) => {
43
+ protected onQueueFullHTTP(_req: Request, res: Response) {
44
44
  this.log.warn(`Queue is full, sending 429 response`);
45
45
  return writeResponse(res, 429, 'Too many requests');
46
- };
46
+ }
47
47
 
48
- protected onQueueFullWebSocket = (_req: Request, socket: stream.Duplex) => {
48
+ protected onQueueFullWebSocket(_req: Request, socket: stream.Duplex) {
49
49
  this.log.warn(`Queue is full, sending 429 response`);
50
50
  return writeResponse(socket, 429, 'Too many requests');
51
- };
51
+ }
52
52
 
53
- protected onHTTPTimeout = (_req: Request, res: Response) => {
53
+ protected onHTTPTimeout(_req: Request, res: Response) {
54
54
  this.log.error(`HTTP job has timedout, sending 429 response`);
55
55
  return writeResponse(res, 408, 'Request has timed out');
56
- };
56
+ }
57
57
 
58
- protected onWebsocketTimeout = (_req: Request, socket: stream.Duplex) => {
58
+ protected onWebsocketTimeout(_req: Request, socket: stream.Duplex) {
59
59
  this.log.error(`Websocket job has timedout, sending 429 response`);
60
60
  return writeResponse(socket, 408, 'Request has timed out');
61
- };
62
-
63
- protected wrapHTTPHandler =
64
- (
65
- route: HTTPRoute | BrowserHTTPRoute,
66
- handler: HTTPRoute['handler'] | BrowserHTTPRoute['handler'],
67
- ) =>
68
- async (req: Request, res: Response) => {
61
+ }
62
+
63
+ protected wrapHTTPHandler(
64
+ route: HTTPRoute | BrowserHTTPRoute,
65
+ handler: HTTPRoute['handler'] | BrowserHTTPRoute['handler'],
66
+ ) {
67
+ return async (req: Request, res: Response) => {
69
68
  if (!isConnected(res)) {
70
69
  this.log.warn(`HTTP Request has closed prior to running`);
71
70
  return Promise.resolve();
@@ -110,13 +109,13 @@ export class Router extends EventEmitter {
110
109
 
111
110
  return (handler as HTTPRoute['handler'])(req, res, logger);
112
111
  };
112
+ }
113
113
 
114
- protected wrapWebSocketHandler =
115
- (
116
- route: WebSocketRoute | BrowserWebsocketRoute,
117
- handler: WebSocketRoute['handler'] | BrowserWebsocketRoute['handler'],
118
- ) =>
119
- async (req: Request, socket: stream.Duplex, head: Buffer) => {
114
+ protected wrapWebSocketHandler(
115
+ route: WebSocketRoute | BrowserWebsocketRoute,
116
+ handler: WebSocketRoute['handler'] | BrowserWebsocketRoute['handler'],
117
+ ) {
118
+ return async (req: Request, socket: stream.Duplex, head: Buffer) => {
120
119
  if (!isConnected(socket)) {
121
120
  this.log.warn(`WebSocket Request has closed prior to running`);
122
121
  return Promise.resolve();
@@ -150,6 +149,7 @@ export class Router extends EventEmitter {
150
149
  }
151
150
  return (handler as WebSocketRoute['handler'])(req, socket, head, logger);
152
151
  };
152
+ }
153
153
 
154
154
  public registerHTTPRoute(
155
155
  route: HTTPRoute | BrowserHTTPRoute,
@@ -164,9 +164,9 @@ export class Router extends EventEmitter {
164
164
  route.handler = route.concurrency
165
165
  ? this.limiter.limit(
166
166
  wrapped,
167
- this.onQueueFullHTTP,
168
- this.onHTTPTimeout,
169
- this.getTimeout,
167
+ this.onQueueFullHTTP.bind(this),
168
+ this.onHTTPTimeout.bind(this),
169
+ this.getTimeout.bind(this),
170
170
  )
171
171
  : wrapped;
172
172
  route.path = Array.isArray(route.path) ? route.path : [route.path];
@@ -194,9 +194,9 @@ export class Router extends EventEmitter {
194
194
  route.handler = route.concurrency
195
195
  ? this.limiter.limit(
196
196
  wrapped,
197
- this.onQueueFullWebSocket,
198
- this.onWebsocketTimeout,
199
- this.getTimeout,
197
+ this.onQueueFullWebSocket.bind(this),
198
+ this.onWebsocketTimeout.bind(this),
199
+ this.getTimeout.bind(this),
200
200
  )
201
201
  : wrapped;
202
202
  route.path = Array.isArray(route.path) ? route.path : [route.path];
@@ -256,14 +256,14 @@ export class Router extends EventEmitter {
256
256
  * Implement any browserless-core-specific shutdown logic here.
257
257
  * Calls the empty-SDK stop method for downstream implementations.
258
258
  */
259
- public shutdown = async () => {
259
+ public async shutdown() {
260
260
  this.httpRoutes = [];
261
261
  this.webSocketRoutes = [];
262
- await this.stop();
263
- };
262
+ return await this.stop();
263
+ }
264
264
 
265
265
  /**
266
266
  * Left blank for downstream SDK modules to optionally implement.
267
267
  */
268
- public stop = () => {};
268
+ public stop() {}
269
269
  }
@@ -470,9 +470,9 @@ describe('Chrome WebSocket API', function () {
470
470
  const browser = await pw.chromium.connect(
471
471
  `ws://localhost:3000/chrome/playwright?token=browserless`,
472
472
  );
473
-
473
+
474
474
  await browser.close();
475
- await sleep(100);
475
+ await sleep(100);
476
476
  }
477
477
 
478
478
  const results = metrics.get();
@@ -474,9 +474,9 @@ describe('Chromium WebSocket API', function () {
474
474
  const browser = await pw.chromium.connect(
475
475
  `ws://localhost:3000/playwright/chromium?token=browserless`,
476
476
  );
477
-
477
+
478
478
  await browser.close();
479
- await sleep(100);
479
+ await sleep(100);
480
480
  }
481
481
 
482
482
  const results = metrics.get();
@@ -38,9 +38,7 @@ describe('Firefox Websocket API', function () {
38
38
  await browser.close();
39
39
  });
40
40
 
41
-
42
41
  it('runs multiple versions of playwright', async () => {
43
-
44
42
  const config = new Config();
45
43
  config.setToken('browserless');
46
44
  const metrics = new Metrics();
@@ -53,9 +51,9 @@ describe('Firefox Websocket API', function () {
53
51
  const browser = await pw.firefox.connect(
54
52
  `ws://localhost:3000/playwright/firefox?token=browserless`,
55
53
  );
56
-
54
+
57
55
  await browser.close();
58
- await sleep(100);
56
+ await sleep(100);
59
57
  }
60
58
 
61
59
  const results = metrics.get();
@@ -26,13 +26,13 @@ export default class FirefoxPlaywrightWebSocketRoute extends BrowserWebsocketRou
26
26
  description = `Connect to Firefox with any playwright-compliant library.`;
27
27
  path = [WebsocketRoutes.playwrightFirefox, WebsocketRoutes.firefoxPlaywright];
28
28
  tags = [APITags.browserWS];
29
- handler = async (
29
+ async handler(
30
30
  req: Request,
31
31
  socket: Duplex,
32
32
  head: Buffer,
33
33
  _logger: Logger,
34
34
  browser: FirefoxPlaywright,
35
- ): Promise<void> => {
35
+ ): Promise<void> {
36
36
  const isPlaywright = req.headers['user-agent']
37
37
  ?.toLowerCase()
38
38
  .includes('playwright');
@@ -44,5 +44,5 @@ export default class FirefoxPlaywrightWebSocketRoute extends BrowserWebsocketRou
44
44
  }
45
45
 
46
46
  return browser.proxyWebSocket(req, socket, head);
47
- };
47
+ }
48
48
  }
@@ -25,6 +25,7 @@ export default class ActiveGetRoute extends HTTPRoute {
25
25
  method = Methods.get;
26
26
  path = HTTPManagementRoutes.active;
27
27
  tags = [APITags.management];
28
- handler = async (_req: Request, res: ServerResponse): Promise<void> =>
29
- writeResponse(res, 204, '', contentTypes.text);
28
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
29
+ return writeResponse(res, 204, '', contentTypes.text);
30
+ }
30
31
  }
@@ -44,7 +44,7 @@ export default class ConfigGetRoute extends HTTPRoute {
44
44
  method = Methods.get;
45
45
  path = HTTPManagementRoutes.config;
46
46
  tags = [APITags.management];
47
- handler = async (_req: Request, res: ServerResponse): Promise<void> => {
47
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
48
48
  const config = this.config();
49
49
 
50
50
  const response: ResponseSchema = {
@@ -71,5 +71,5 @@ export default class ConfigGetRoute extends HTTPRoute {
71
71
  };
72
72
 
73
73
  return jsonResponse(res, 200, response);
74
- };
74
+ }
75
75
  }
@@ -26,7 +26,7 @@ export default class MetricsTotalGetRoute extends HTTPRoute {
26
26
  method = Methods.get;
27
27
  path = HTTPManagementRoutes.metricsTotal;
28
28
  tags = [APITags.management];
29
- handler = async (_req: Request, res: ServerResponse): Promise<void> => {
29
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
30
30
  const fileSystem = this.fileSystem();
31
31
  const config = this.config();
32
32
  const metrics = (
@@ -76,5 +76,5 @@ export default class MetricsTotalGetRoute extends HTTPRoute {
76
76
  );
77
77
 
78
78
  return writeResponse(res, 200, JSON.stringify(totals), contentTypes.json);
79
- };
79
+ }
80
80
  }
@@ -24,7 +24,7 @@ export default class MetricsGetRoute extends HTTPRoute {
24
24
  method = Methods.get;
25
25
  path = HTTPManagementRoutes.metrics;
26
26
  tags = [APITags.management];
27
- handler = async (_req: Request, res: ServerResponse): Promise<void> => {
27
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
28
28
  const fileSystem = this.fileSystem();
29
29
  const config = this.config();
30
30
 
@@ -32,5 +32,5 @@ export default class MetricsGetRoute extends HTTPRoute {
32
32
  const response = `[${stats.join(',')}]`;
33
33
 
34
34
  return writeResponse(res, 200, response, contentTypes.json);
35
- };
35
+ }
36
36
  }
@@ -81,7 +81,7 @@ export default class PressureGetRoute extends HTTPRoute {
81
81
  method = Methods.get;
82
82
  path = HTTPManagementRoutes.pressure;
83
83
  tags = [APITags.management];
84
- handler = async (_req: Request, res: ServerResponse): Promise<void> => {
84
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
85
85
  const monitoring = this.monitoring();
86
86
  const config = this.config();
87
87
  const limiter = this.limiter();
@@ -135,5 +135,5 @@ export default class PressureGetRoute extends HTTPRoute {
135
135
  };
136
136
 
137
137
  return jsonResponse(res, 200, response);
138
- };
138
+ }
139
139
  }
@@ -24,10 +24,10 @@ export default class SessionsGetRoute extends HTTPRoute {
24
24
  method = Methods.get;
25
25
  path = HTTPManagementRoutes.sessions;
26
26
  tags = [APITags.management];
27
- handler = async (_req: Request, res: ServerResponse): Promise<void> => {
27
+ async handler(_req: Request, res: ServerResponse): Promise<void> {
28
28
  const browserManager = this.browserManager();
29
29
  const response: ResponseSchema = await browserManager.getAllSessions();
30
30
 
31
31
  return jsonResponse(res, 200, response);
32
- };
32
+ }
33
33
  }
@@ -60,11 +60,11 @@ export default class StaticGetRoute extends HTTPRoute {
60
60
  method = Methods.get;
61
61
  path = HTTPManagementRoutes.static;
62
62
  tags = [APITags.management];
63
- handler = async (
63
+ async handler(
64
64
  req: Request,
65
65
  res: ServerResponse,
66
66
  logger: Logger,
67
- ): Promise<unknown> => {
67
+ ): Promise<unknown> {
68
68
  const { pathname } = req.parsed;
69
69
  const fileCache = pathMap.get(pathname);
70
70
 
@@ -117,5 +117,5 @@ export default class StaticGetRoute extends HTTPRoute {
117
117
  });
118
118
 
119
119
  return streamFile(logger, res, foundFilePath, contentType);
120
- };
120
+ }
121
121
  }
@@ -39,7 +39,6 @@ describe('Webkit Websocket API', function () {
39
39
  await browser.close();
40
40
  });
41
41
 
42
-
43
42
  it('runs multiple versions of playwright', async () => {
44
43
  const config = new Config();
45
44
  config.setToken('browserless');
@@ -53,9 +52,9 @@ describe('Webkit Websocket API', function () {
53
52
  const browser = await pw.webkit.connect(
54
53
  `ws://localhost:3000/playwright/webkit?token=browserless`,
55
54
  );
56
-
55
+
57
56
  await browser.close();
58
- await sleep(100);
57
+ await sleep(100);
59
58
  }
60
59
 
61
60
  const results = metrics.get();
@@ -24,13 +24,13 @@ export default class WebKitPlaywrightWebSocketRoute extends BrowserWebsocketRout
24
24
  description = `Connect to Webkit with any playwright-compliant library.`;
25
25
  path = [WebsocketRoutes.playwrightWebkit, WebsocketRoutes.webkitPlaywright];
26
26
  tags = [APITags.browserWS];
27
- handler = async (
27
+ async handler(
28
28
  req: Request,
29
29
  socket: Duplex,
30
30
  head: Buffer,
31
31
  _logger: Logger,
32
32
  browser: WebkitPlaywright,
33
- ): Promise<void> => {
33
+ ): Promise<void> {
34
34
  const isPlaywright = req.headers['user-agent']
35
35
  ?.toLowerCase()
36
36
  .includes('playwright');
@@ -42,5 +42,5 @@ export default class WebKitPlaywrightWebSocketRoute extends BrowserWebsocketRout
42
42
  }
43
43
 
44
44
  return browser.proxyWebSocket(req, socket, head);
45
- };
45
+ }
46
46
  }