@browserless.io/browserless 2.0.0-beta-5 → 2.0.0-beta-7

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 (246) hide show
  1. package/LICENSE +2 -0
  2. package/README.md +11 -11
  3. package/bin/browserless.js +169 -11
  4. package/bin/scaffold/README.md +415 -0
  5. package/bin/scaffold/package.json +21 -0
  6. package/bin/scaffold/src/hello-world.http.ts +27 -0
  7. package/bin/scaffold/tsconfig.json +4 -0
  8. package/build/browserless.js +18 -15
  9. package/build/browsers/index.d.ts +2 -18
  10. package/build/browsers/index.js +43 -14
  11. package/build/file-system.d.ts +5 -0
  12. package/build/file-system.js +20 -5
  13. package/build/file-system.spec.d.ts +1 -0
  14. package/build/file-system.spec.js +44 -0
  15. package/build/http.d.ts +3 -3
  16. package/build/http.js +3 -3
  17. package/build/router.js +2 -4
  18. package/build/routes/chromium/http/content-post.body.json +8 -8
  19. package/build/routes/chromium/http/content-post.d.ts +15 -3
  20. package/build/routes/chromium/http/content-post.js +14 -15
  21. package/build/routes/chromium/http/download-post.d.ts +16 -3
  22. package/build/routes/chromium/http/download-post.js +17 -22
  23. package/build/routes/chromium/http/function-post.d.ts +16 -3
  24. package/build/routes/chromium/http/function-post.js +17 -22
  25. package/build/routes/chromium/http/pdf-post.body.json +8 -8
  26. package/build/routes/chromium/http/pdf-post.d.ts +15 -3
  27. package/build/routes/chromium/http/pdf-post.js +19 -15
  28. package/build/routes/chromium/http/performance.d.ts +15 -3
  29. package/build/routes/chromium/http/performance.js +15 -23
  30. package/build/routes/chromium/http/scrape-post.body.json +8 -8
  31. package/build/routes/chromium/http/scrape-post.d.ts +15 -3
  32. package/build/routes/chromium/http/scrape-post.js +15 -16
  33. package/build/routes/chromium/http/screenshot-post.body.json +8 -8
  34. package/build/routes/chromium/http/screenshot-post.d.ts +15 -3
  35. package/build/routes/chromium/http/screenshot-post.js +18 -15
  36. package/build/routes/chromium/tests/websocket.spec.js +20 -1
  37. package/build/routes/chromium/utils/function/handler.js +2 -2
  38. package/build/routes/chromium/ws/browser.d.ts +13 -3
  39. package/build/routes/chromium/ws/browser.js +10 -11
  40. package/build/routes/chromium/ws/cdp-chromium.d.ts +13 -3
  41. package/build/routes/chromium/ws/cdp-chromium.js +10 -11
  42. package/build/routes/chromium/ws/page.d.ts +13 -3
  43. package/build/routes/chromium/ws/page.js +10 -11
  44. package/build/routes/chromium/ws/playwright-chromium.d.ts +13 -3
  45. package/build/routes/chromium/ws/playwright-chromium.js +11 -12
  46. package/build/routes/firefox/ws/playwright-firefox.d.ts +13 -3
  47. package/build/routes/firefox/ws/playwright-firefox.js +11 -12
  48. package/build/routes/management/http/config-get.d.ts +15 -3
  49. package/build/routes/management/http/config-get.js +15 -20
  50. package/build/routes/management/http/metrics-get.d.ts +15 -3
  51. package/build/routes/management/http/metrics-get.js +16 -21
  52. package/build/routes/management/http/metrics-total-get.d.ts +15 -3
  53. package/build/routes/management/http/metrics-total-get.js +16 -21
  54. package/build/routes/management/http/sessions-get.d.ts +15 -3
  55. package/build/routes/management/http/sessions-get.js +16 -20
  56. package/build/routes/management/http/static-get.d.ts +15 -3
  57. package/build/routes/management/http/static-get.js +15 -20
  58. package/build/routes/webkit/ws/playwright-webkit.d.ts +13 -3
  59. package/build/routes/webkit/ws/playwright-webkit.js +11 -12
  60. package/build/server.js +0 -1
  61. package/build/types.d.ts +48 -38
  62. package/build/types.js +135 -0
  63. package/extensions/ublock/1p-filters.html +0 -1
  64. package/extensions/ublock/3p-filters.html +0 -2
  65. package/extensions/ublock/_locales/bg/messages.json +6 -6
  66. package/extensions/ublock/_locales/br_FR/messages.json +14 -14
  67. package/extensions/ublock/_locales/bs/messages.json +8 -8
  68. package/extensions/ublock/_locales/ca/messages.json +1 -1
  69. package/extensions/ublock/_locales/da/messages.json +5 -5
  70. package/extensions/ublock/_locales/fa/messages.json +1 -1
  71. package/extensions/ublock/_locales/fi/messages.json +6 -6
  72. package/extensions/ublock/_locales/hr/messages.json +4 -4
  73. package/extensions/ublock/_locales/nb/messages.json +1 -1
  74. package/extensions/ublock/_locales/no/messages.json +1 -1
  75. package/extensions/ublock/_locales/ro/messages.json +2 -2
  76. package/extensions/ublock/_locales/ru/messages.json +1 -1
  77. package/extensions/ublock/_locales/sk/messages.json +1 -1
  78. package/extensions/ublock/_locales/sv/messages.json +2 -2
  79. package/extensions/ublock/_locales/te/messages.json +17 -17
  80. package/extensions/ublock/_locales/vi/messages.json +12 -12
  81. package/extensions/ublock/_locales/zh_TW/messages.json +13 -13
  82. package/extensions/ublock/assets/assets.json +3 -3
  83. package/extensions/ublock/assets/resources/scriptlets.js +218 -97
  84. package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +3010 -2056
  85. package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +624 -433
  86. package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +93 -24
  87. package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +7 -15
  88. package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +795 -777
  89. package/extensions/ublock/assets/ublock/badware.min.txt +138 -72
  90. package/extensions/ublock/assets/ublock/filters.min.txt +1929 -2735
  91. package/extensions/ublock/assets/ublock/privacy.min.txt +57 -26
  92. package/extensions/ublock/assets/ublock/quick-fixes.min.txt +125 -74
  93. package/extensions/ublock/assets/ublock/unbreak.min.txt +46 -53
  94. package/extensions/ublock/css/codemirror.css +8 -7
  95. package/extensions/ublock/css/dom-inspector.css +40 -0
  96. package/extensions/ublock/css/logger-ui-inspector.css +7 -1
  97. package/extensions/ublock/css/logger-ui.css +12 -5
  98. package/extensions/ublock/css/popup-fenix.css +1 -1
  99. package/extensions/ublock/devtools.html +1 -0
  100. package/extensions/ublock/js/1p-filters.js +4 -3
  101. package/extensions/ublock/js/3p-filters.js +25 -31
  102. package/extensions/ublock/js/about.js +1 -1
  103. package/extensions/ublock/js/advanced-settings.js +1 -1
  104. package/extensions/ublock/js/asset-viewer.js +1 -1
  105. package/extensions/ublock/js/assets.js +74 -44
  106. package/extensions/ublock/js/background.js +9 -3
  107. package/extensions/ublock/js/base64-custom.js +1 -1
  108. package/extensions/ublock/js/benchmarks.js +1 -1
  109. package/extensions/ublock/js/biditrie.js +1 -1
  110. package/extensions/ublock/js/broadcast.js +75 -0
  111. package/extensions/ublock/js/cachestorage.js +68 -45
  112. package/extensions/ublock/js/click2load.js +1 -1
  113. package/extensions/ublock/js/cloud-ui.js +1 -1
  114. package/extensions/ublock/js/code-viewer.js +1 -1
  115. package/extensions/ublock/js/codemirror/search-thread.js +1 -1
  116. package/extensions/ublock/js/codemirror/search.js +1 -1
  117. package/extensions/ublock/js/codemirror/ubo-dynamic-filtering.js +1 -1
  118. package/extensions/ublock/js/codemirror/ubo-static-filtering.js +98 -24
  119. package/extensions/ublock/js/commands.js +1 -1
  120. package/extensions/ublock/js/console.js +1 -1
  121. package/extensions/ublock/js/contentscript-extra.js +1 -1
  122. package/extensions/ublock/js/contentscript.js +1 -3
  123. package/extensions/ublock/js/contextmenu.js +1 -1
  124. package/extensions/ublock/js/cosmetic-filtering.js +4 -4
  125. package/extensions/ublock/js/dashboard-common.js +1 -1
  126. package/extensions/ublock/js/dashboard.js +1 -1
  127. package/extensions/ublock/js/devtools.js +23 -15
  128. package/extensions/ublock/js/diff-updater.js +3 -3
  129. package/extensions/ublock/js/document-blocked.js +1 -1
  130. package/extensions/ublock/js/dom-inspector.js +68 -0
  131. package/extensions/ublock/js/dom.js +1 -1
  132. package/extensions/ublock/js/dyna-rules.js +1 -1
  133. package/extensions/ublock/js/dynamic-net-filtering.js +1 -1
  134. package/extensions/ublock/js/epicker-ui.js +35 -59
  135. package/extensions/ublock/js/fa-icons.js +1 -1
  136. package/extensions/ublock/js/filtering-context.js +1 -1
  137. package/extensions/ublock/js/filtering-engines.js +1 -1
  138. package/extensions/ublock/js/hnswitches.js +1 -1
  139. package/extensions/ublock/js/hntrie.js +1 -1
  140. package/extensions/ublock/js/html-filtering.js +1 -1
  141. package/extensions/ublock/js/httpheader-filtering.js +1 -1
  142. package/extensions/ublock/js/i18n.js +1 -1
  143. package/extensions/ublock/js/is-webrtc-supported.js +1 -1
  144. package/extensions/ublock/js/logger-ui-inspector.js +203 -145
  145. package/extensions/ublock/js/logger-ui.js +21 -5
  146. package/extensions/ublock/js/logger.js +6 -2
  147. package/extensions/ublock/js/lz4.js +2 -2
  148. package/extensions/ublock/js/messaging.js +266 -166
  149. package/extensions/ublock/js/mrucache.js +58 -0
  150. package/extensions/ublock/js/pagestore.js +1 -1
  151. package/extensions/ublock/js/popup-fenix.js +2 -1
  152. package/extensions/ublock/js/redirect-engine.js +1 -1
  153. package/extensions/ublock/js/redirect-resources.js +1 -12
  154. package/extensions/ublock/js/reverselookup-worker.js +1 -1
  155. package/extensions/ublock/js/reverselookup.js +1 -1
  156. package/extensions/ublock/js/scriptlet-filtering-core.js +300 -0
  157. package/extensions/ublock/js/scriptlet-filtering.js +122 -350
  158. package/extensions/ublock/js/scriptlets/cosmetic-logger.js +36 -47
  159. package/extensions/ublock/js/scriptlets/cosmetic-off.js +1 -1
  160. package/extensions/ublock/js/scriptlets/cosmetic-on.js +1 -1
  161. package/extensions/ublock/js/scriptlets/cosmetic-report.js +1 -1
  162. package/extensions/ublock/js/scriptlets/dom-inspector.js +341 -323
  163. package/extensions/ublock/js/scriptlets/dom-survey-elements.js +1 -1
  164. package/extensions/ublock/js/scriptlets/dom-survey-scripts.js +1 -1
  165. package/extensions/ublock/js/scriptlets/epicker.js +80 -89
  166. package/extensions/ublock/js/scriptlets/load-3p-css.js +1 -1
  167. package/extensions/ublock/js/scriptlets/load-large-media-all.js +1 -1
  168. package/extensions/ublock/js/scriptlets/load-large-media-interactive.js +1 -1
  169. package/extensions/ublock/js/scriptlets/noscript-spoof.js +1 -1
  170. package/extensions/ublock/js/scriptlets/should-inject-contentscript.js +1 -1
  171. package/extensions/ublock/js/scriptlets/subscriber.js +1 -1
  172. package/extensions/ublock/js/scriptlets/updater.js +20 -3
  173. package/extensions/ublock/js/settings.js +1 -1
  174. package/extensions/ublock/js/start.js +19 -20
  175. package/extensions/ublock/js/static-dnr-filtering.js +1 -1
  176. package/extensions/ublock/js/static-ext-filtering-db.js +1 -1
  177. package/extensions/ublock/js/static-ext-filtering.js +1 -1
  178. package/extensions/ublock/js/static-filtering-io.js +1 -1
  179. package/extensions/ublock/js/static-filtering-parser.js +5 -3
  180. package/extensions/ublock/js/static-net-filtering.js +57 -37
  181. package/extensions/ublock/js/storage.js +49 -29
  182. package/extensions/ublock/js/support.js +4 -4
  183. package/extensions/ublock/js/tab.js +1 -1
  184. package/extensions/ublock/js/tasks.js +1 -1
  185. package/extensions/ublock/js/text-encode.js +1 -1
  186. package/extensions/ublock/js/text-utils.js +1 -1
  187. package/extensions/ublock/js/theme.js +1 -1
  188. package/extensions/ublock/js/traffic.js +2 -1
  189. package/extensions/ublock/js/ublock.js +15 -11
  190. package/extensions/ublock/js/uri-utils.js +1 -1
  191. package/extensions/ublock/js/url-net-filtering.js +1 -1
  192. package/extensions/ublock/js/utils.js +1 -73
  193. package/extensions/ublock/js/vapi-background-ext.js +1 -1
  194. package/extensions/ublock/js/vapi-background.js +92 -83
  195. package/extensions/ublock/js/vapi-client.js +4 -33
  196. package/extensions/ublock/js/vapi-common.js +16 -30
  197. package/extensions/ublock/js/vapi.js +1 -1
  198. package/extensions/ublock/js/wasm/biditrie.wat +1 -1
  199. package/extensions/ublock/js/wasm/hntrie.wat +1 -1
  200. package/extensions/ublock/js/webext.js +1 -1
  201. package/extensions/ublock/js/whitelist.js +1 -1
  202. package/extensions/ublock/logger-ui.html +2 -2
  203. package/extensions/ublock/manifest.json +1 -1
  204. package/extensions/ublock/support.html +0 -1
  205. package/extensions/ublock/web_accessible_resources/dom-inspector.html +25 -0
  206. package/extensions/ublock/web_accessible_resources/epicker-ui.html +0 -1
  207. package/extensions/ublock/web_accessible_resources/googletagservices_gpt.js +1 -0
  208. package/package.json +7 -19
  209. package/scripts/build-open-api.js +7 -4
  210. package/src/browserless.ts +42 -18
  211. package/src/browsers/index.ts +48 -20
  212. package/src/file-system.spec.ts +58 -0
  213. package/src/file-system.ts +36 -8
  214. package/src/http.ts +3 -3
  215. package/src/router.ts +2 -6
  216. package/src/routes/chromium/http/content-post.ts +13 -16
  217. package/src/routes/chromium/http/download-post.ts +16 -27
  218. package/src/routes/chromium/http/function-post.ts +16 -25
  219. package/src/routes/chromium/http/pdf-post.ts +19 -15
  220. package/src/routes/chromium/http/performance.ts +14 -26
  221. package/src/routes/chromium/http/scrape-post.ts +14 -16
  222. package/src/routes/chromium/http/screenshot-post.ts +18 -15
  223. package/src/routes/chromium/tests/websocket.spec.ts +28 -1
  224. package/src/routes/chromium/utils/function/handler.ts +2 -1
  225. package/src/routes/chromium/ws/browser.ts +10 -12
  226. package/src/routes/chromium/ws/cdp-chromium.ts +10 -12
  227. package/src/routes/chromium/ws/page.ts +10 -12
  228. package/src/routes/chromium/ws/playwright-chromium.ts +10 -12
  229. package/src/routes/firefox/ws/playwright-firefox.ts +10 -12
  230. package/src/routes/management/http/config-get.ts +14 -23
  231. package/src/routes/management/http/metrics-get.ts +15 -24
  232. package/src/routes/management/http/metrics-total-get.ts +15 -26
  233. package/src/routes/management/http/sessions-get.ts +15 -23
  234. package/src/routes/management/http/static-get.ts +14 -22
  235. package/src/routes/webkit/ws/playwright-webkit.ts +10 -12
  236. package/src/server.ts +0 -1
  237. package/src/types.ts +59 -45
  238. package/static/docs/browserless-logo-inline.svg +1 -0
  239. package/static/docs/index.html +27 -0
  240. package/static/docs/swagger.json +33 -33
  241. package/static/function/client.js +626 -78
  242. package/extensions/ublock/js/vapi-client-extra.js +0 -312
  243. package/extensions/ublock/web_accessible_resources/addthis_widget.js +0 -39
  244. package/extensions/ublock/web_accessible_resources/ligatus_angular-tag.js +0 -29
  245. package/extensions/ublock/web_accessible_resources/monkeybroker.js +0 -43
  246. package/extensions/ublock/web_accessible_resources/mxpnl_mixpanel.js +0 -51
@@ -1,11 +1,28 @@
1
- import { decrypt, encrypt } from '@browserless.io/browserless';
1
+ import { createLogger, decrypt, encrypt, } from '@browserless.io/browserless';
2
2
  import { readFile, writeFile } from 'fs/promises';
3
3
  export class FileSystem {
4
4
  config;
5
5
  fsMap = new Map();
6
+ currentAESKey;
7
+ log = createLogger('file-system');
6
8
  constructor(config) {
7
9
  this.config = config;
10
+ this.currentAESKey = config.getAESKey();
11
+ this.config.on('token', this.handleTokenChange);
8
12
  }
13
+ handleTokenChange = async () => {
14
+ this.log(`Token has changed, updating file-system contents`);
15
+ const start = Date.now();
16
+ const newAESKey = this.config.getAESKey();
17
+ await Promise.all(Array.from(this.fsMap).map(async ([filePath, contents]) => {
18
+ const newlyEncoded = encrypt(contents.join('\n'), Buffer.from(newAESKey));
19
+ return writeFile(filePath, newlyEncoded);
20
+ })).catch((e) => {
21
+ this.log(`Error in setting new token: "${e}"`);
22
+ });
23
+ this.log(`Successfully updated file encodings in ${Date.now() - start}ms`);
24
+ this.currentAESKey = this.config.getAESKey();
25
+ };
9
26
  /**
10
27
  * Appends contents to a file-path for persistance. File contents are
11
28
  * encrypted before being saved to disk. Reads happen via the in-memory
@@ -19,8 +36,7 @@ export class FileSystem {
19
36
  const contents = await this.read(path);
20
37
  contents.push(newContent);
21
38
  this.fsMap.set(path, contents);
22
- const key = this.config.getAESKey();
23
- const encoded = await encrypt(contents.join('\n'), Buffer.from(key));
39
+ const encoded = await encrypt(contents.join('\n'), Buffer.from(this.currentAESKey));
24
40
  return writeFile(path, encoded.toString());
25
41
  };
26
42
  /**
@@ -35,10 +51,9 @@ export class FileSystem {
35
51
  if (hasKey) {
36
52
  return this.fsMap.get(path);
37
53
  }
38
- const key = this.config.getAESKey();
39
54
  const contents = (await readFile(path).catch(() => '')).toString();
40
55
  const splitContents = contents.length
41
- ? (await decrypt(contents, Buffer.from(key))).split('\n')
56
+ ? (await decrypt(contents, Buffer.from(this.currentAESKey))).split('\n')
42
57
  : [];
43
58
  this.fsMap.set(path, splitContents);
44
59
  return splitContents;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,44 @@
1
+ import { Config, FileSystem, sleep } from '@browserless.io/browserless';
2
+ import { readFile, unlink } from 'fs/promises';
3
+ import { expect } from 'chai';
4
+ const filePath = '/tmp/_browserless_test_fs_';
5
+ describe.only('File-System', () => {
6
+ afterEach(async () => unlink(filePath));
7
+ it('saves and encodes files', async () => {
8
+ const mySecretContents = 'pony-foo';
9
+ const config = new Config();
10
+ config.setToken('browserless.io');
11
+ const f = new FileSystem(config);
12
+ await f.append(filePath, mySecretContents);
13
+ expect(await f.read(filePath)).to.eql([mySecretContents]);
14
+ const rawText = (await readFile(filePath)).toString();
15
+ expect(rawText.toString()).to.not.include(mySecretContents);
16
+ });
17
+ it('appends newlines to files', async () => {
18
+ const mySecretContents = 'pony-foo';
19
+ const moreSecretContents = 'pony-pony-foo-foo';
20
+ const config = new Config();
21
+ config.setToken('browserless.io');
22
+ const f = new FileSystem(config);
23
+ await f.append(filePath, mySecretContents);
24
+ expect(await f.read(filePath)).to.eql([mySecretContents]);
25
+ await f.append(filePath, moreSecretContents);
26
+ expect(await f.read(filePath)).to.eql([
27
+ mySecretContents,
28
+ moreSecretContents,
29
+ ]);
30
+ });
31
+ it('re-encodes files on token changes', async () => {
32
+ const config = new Config();
33
+ config.setToken('browserless.io');
34
+ const f = new FileSystem(config);
35
+ const mySecretContents = 'pony-foo';
36
+ await f.append(filePath, mySecretContents);
37
+ const oldText = (await readFile(filePath)).toString();
38
+ config.setToken('super-browserless-64');
39
+ await sleep(200);
40
+ const newText = (await readFile(filePath)).toString();
41
+ expect(oldText).to.not.equal(newText);
42
+ expect(await f.read(filePath)).to.eql([mySecretContents]);
43
+ });
44
+ });
package/build/http.d.ts CHANGED
@@ -132,9 +132,9 @@ export declare enum HTTPManagementRoutes {
132
132
  static = "/"
133
133
  }
134
134
  export declare enum APITags {
135
- 'browserAPI' = "Browser APIs",
136
- 'browserWS' = "Browser WebSockets",
137
- 'management' = "Management APIs"
135
+ 'browserAPI' = "Browser REST APIs",
136
+ 'browserWS' = "Browser WebSocket APIs",
137
+ 'management' = "Management REST APIs"
138
138
  }
139
139
  export interface Request extends http.IncomingMessage {
140
140
  body: unknown;
package/build/http.js CHANGED
@@ -98,7 +98,7 @@ export var HTTPManagementRoutes;
98
98
  })(HTTPManagementRoutes || (HTTPManagementRoutes = {}));
99
99
  export var APITags;
100
100
  (function (APITags) {
101
- APITags["browserAPI"] = "Browser APIs";
102
- APITags["browserWS"] = "Browser WebSockets";
103
- APITags["management"] = "Management APIs";
101
+ APITags["browserAPI"] = "Browser REST APIs";
102
+ APITags["browserWS"] = "Browser WebSocket APIs";
103
+ APITags["management"] = "Management REST APIs";
104
104
  })(APITags || (APITags = {}));
package/build/router.js CHANGED
@@ -38,7 +38,7 @@ export class Router {
38
38
  this.log(`HTTP Request has closed prior to running`);
39
39
  return Promise.resolve();
40
40
  }
41
- if (route.browser) {
41
+ if ('browser' in route && route.browser) {
42
42
  const browser = await this.browserManager.getBrowserForRequest(req, route);
43
43
  if (!isConnected(res)) {
44
44
  this.log(`HTTP Request has closed prior to running`);
@@ -68,7 +68,7 @@ export class Router {
68
68
  this.log(`WebSocket Request has closed prior to running`);
69
69
  return Promise.resolve();
70
70
  }
71
- if (route.browser) {
71
+ if ('browser' in route && route.browser) {
72
72
  const browser = await this.browserManager.getBrowserForRequest(req, route);
73
73
  if (!isConnected(socket)) {
74
74
  this.log(`WebSocket Request has closed prior to running`);
@@ -92,7 +92,6 @@ export class Router {
92
92
  };
93
93
  registerHTTPRoute(route) {
94
94
  this.verbose(`Registering HTTP ${route.method.toUpperCase()} ${route.path}`);
95
- route.getBrowserManager = () => this.browserManager;
96
95
  const bound = route.handler.bind(route);
97
96
  const wrapped = this.wrapHTTPHandler(route, bound);
98
97
  route.handler = route.concurrency
@@ -103,7 +102,6 @@ export class Router {
103
102
  }
104
103
  registerWebSocketRoute(route) {
105
104
  this.verbose(`Registering WebSocket "${route.path}"`);
106
- route.getBrowserManager = () => this.browserManager;
107
105
  const bound = route.handler.bind(route);
108
106
  const wrapped = this.wrapWebSocketHandler(route, bound);
109
107
  route.handler = route.concurrency
@@ -398,14 +398,14 @@
398
398
  "length": {
399
399
  "type": "number"
400
400
  },
401
- "__@toStringTag@10725": {
401
+ "__@toStringTag@10732": {
402
402
  "type": "string",
403
403
  "const": "Uint8Array"
404
404
  }
405
405
  },
406
406
  "required": [
407
407
  "BYTES_PER_ELEMENT",
408
- "__@toStringTag@10725",
408
+ "__@toStringTag@10732",
409
409
  "buffer",
410
410
  "byteLength",
411
411
  "byteOffset",
@@ -440,13 +440,13 @@
440
440
  "byteLength": {
441
441
  "type": "number"
442
442
  },
443
- "__@toStringTag@10725": {
443
+ "__@toStringTag@10732": {
444
444
  "type": "string"
445
445
  }
446
446
  },
447
447
  "additionalProperties": false,
448
448
  "required": [
449
- "__@toStringTag@10725",
449
+ "__@toStringTag@10732",
450
450
  "byteLength"
451
451
  ]
452
452
  },
@@ -456,18 +456,18 @@
456
456
  "byteLength": {
457
457
  "type": "number"
458
458
  },
459
- "__@species@10826": {
459
+ "__@species@10833": {
460
460
  "$ref": "#/definitions/SharedArrayBuffer"
461
461
  },
462
- "__@toStringTag@10725": {
462
+ "__@toStringTag@10732": {
463
463
  "type": "string",
464
464
  "const": "SharedArrayBuffer"
465
465
  }
466
466
  },
467
467
  "additionalProperties": false,
468
468
  "required": [
469
- "__@species@10826",
470
- "__@toStringTag@10725",
469
+ "__@species@10833",
470
+ "__@toStringTag@10732",
471
471
  "byteLength"
472
472
  ]
473
473
  },
@@ -1,5 +1,7 @@
1
- import { BrowserHTTPRoute, CDPLaunchOptions, SystemQueryParameters, WaitForEventOptions, WaitForFunctionOptions, WaitForSelectorOptions, bestAttempt, rejectRequestPattern, rejectResourceTypes, requestInterceptors, setJavaScriptEnabled } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, Methods, Request, SystemQueryParameters, WaitForEventOptions, WaitForFunctionOptions, WaitForSelectorOptions, bestAttempt, contentTypes, rejectRequestPattern, rejectResourceTypes, requestInterceptors, setJavaScriptEnabled } from '@browserless.io/browserless';
2
3
  import { Page } from 'puppeteer-core';
4
+ import { ServerResponse } from 'http';
3
5
  export interface BodySchema {
4
6
  addScriptTag?: Array<Parameters<Page['addScriptTag']>[0]>;
5
7
  addStyleTag?: Array<Parameters<Page['addStyleTag']>[0]>;
@@ -30,5 +32,15 @@ export type ResponseSchema = string;
30
32
  export type QuerySchema = SystemQueryParameters & {
31
33
  launch?: CDPLaunchOptions | string;
32
34
  };
33
- declare const route: BrowserHTTPRoute;
34
- export default route;
35
+ export default class ContentPostRoute extends BrowserHTTPRoute {
36
+ accepts: contentTypes[];
37
+ auth: boolean;
38
+ browser: typeof CDPChromium;
39
+ concurrency: boolean;
40
+ contentTypes: contentTypes[];
41
+ description: string;
42
+ method: Methods;
43
+ path: HTTPRoutes;
44
+ tags: APITags[];
45
+ handler: (req: Request, res: ServerResponse, browser: BrowserInstance) => Promise<void>;
46
+ }
@@ -1,12 +1,15 @@
1
- import { APITags, BadRequest, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
2
- const route = {
3
- accepts: [contentTypes.json],
4
- auth: true,
5
- browser: CDPChromium,
6
- concurrency: true,
7
- contentTypes: [contentTypes.html],
8
- description: `A JSON-based API. Given a "url" or "html" field, runs and returns HTML content after the page has loaded and JavaScript has parsed.`,
9
- handler: async (req, res, browser) => {
1
+ import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
2
+ export default class ContentPostRoute extends BrowserHTTPRoute {
3
+ accepts = [contentTypes.json];
4
+ auth = true;
5
+ browser = CDPChromium;
6
+ concurrency = true;
7
+ contentTypes = [contentTypes.html];
8
+ description = `A JSON-based API. Given a "url" or "html" field, runs and returns HTML content after the page has loaded and JavaScript has parsed.`;
9
+ method = Methods.post;
10
+ path = HTTPRoutes.content;
11
+ tags = [APITags.browserAPI];
12
+ handler = async (req, res, browser) => {
10
13
  const contentType = !req.headers.accept || req.headers.accept?.includes('*')
11
14
  ? contentTypes.html
12
15
  : req.headers.accept;
@@ -101,9 +104,5 @@ const route = {
101
104
  const markup = await page.content();
102
105
  page.close().catch(noop);
103
106
  return writeResponse(res, 200, markup, contentTypes.html);
104
- },
105
- method: Methods.post,
106
- path: HTTPRoutes.content,
107
- tags: [APITags.browserAPI],
108
- };
109
- export default route;
107
+ };
108
+ }
@@ -1,4 +1,6 @@
1
- import { BrowserHTTPRoute, CDPLaunchOptions, SystemQueryParameters } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, Methods, Request, SystemQueryParameters, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
2
4
  interface JSONSchema {
3
5
  code: string;
4
6
  context?: Record<string, string | number>;
@@ -12,5 +14,16 @@ export interface QuerySchema extends SystemQueryParameters {
12
14
  * themselves, so there isn't a static response type for this API.
13
15
  */
14
16
  export type ResponseSchema = unknown;
15
- declare const route: BrowserHTTPRoute;
16
- export default route;
17
+ export default class DownloadPost extends BrowserHTTPRoute {
18
+ accepts: contentTypes[];
19
+ auth: boolean;
20
+ browser: typeof CDPChromium;
21
+ concurrency: boolean;
22
+ contentTypes: contentTypes[];
23
+ description: string;
24
+ method: Methods;
25
+ path: HTTPRoutes;
26
+ tags: APITags[];
27
+ handler: (req: Request, res: ServerResponse, browser: BrowserInstance) => Promise<void>;
28
+ }
29
+ export {};
@@ -1,29 +1,28 @@
1
- import { APITags, CDPChromium, HTTPRoutes, Methods, NotFound, ServerError, contentTypes, dedent, id, mimeTypes, once, sleep, } from '@browserless.io/browserless';
1
+ import { APITags, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, NotFound, contentTypes, dedent, id, mimeTypes, once, sleep, } from '@browserless.io/browserless';
2
2
  import { mkdir, readdir } from 'fs/promises';
3
3
  import { createReadStream } from 'fs';
4
4
  import { deleteAsync } from 'del';
5
5
  import functionHandler from '../utils/function/handler.js';
6
6
  import path from 'path';
7
- const route = {
8
- accepts: [contentTypes.json, contentTypes.javascript],
9
- auth: true,
10
- browser: CDPChromium,
11
- concurrency: true,
12
- contentTypes: [contentTypes.any],
13
- description: dedent(`
7
+ export default class DownloadPost extends BrowserHTTPRoute {
8
+ accepts = [contentTypes.json, contentTypes.javascript];
9
+ auth = true;
10
+ browser = CDPChromium;
11
+ concurrency = true;
12
+ contentTypes = [contentTypes.any];
13
+ description = dedent(`
14
14
  A JSON or JavaScript content-type API for returning files Chrome has downloaded during
15
15
  the execution of puppeteer code, which is ran inside context of the browser.
16
16
  Browserless sets up a blank page, a fresh download directory, injects your puppeteer code, and then executes it.
17
17
  You can load external libraries via the "import" syntax, and import ESM-style modules
18
18
  that are written for execution inside of the browser. Once your script is finished, any
19
- downloaded files from Chromium are returned back with the appropriate content-type header.`),
20
- handler: async (req, res, browser) => new Promise(async (resolve, reject) => {
21
- const { getConfig: getConfig, getDebug: getDebug } = route;
22
- if (!getConfig || !getDebug) {
23
- return reject(new ServerError(`Couldn't load configuration for request`));
24
- }
25
- const debug = getDebug();
26
- const config = getConfig();
19
+ downloaded files from Chromium are returned back with the appropriate content-type header.`);
20
+ method = Methods.post;
21
+ path = HTTPRoutes.download;
22
+ tags = [APITags.browserAPI];
23
+ handler = async (req, res, browser) => new Promise(async (resolve, reject) => {
24
+ const debug = this.debug();
25
+ const config = this.config();
27
26
  const downloadPath = path.join(await config.getDownloadsDir(), `.browserless.download.${id()}`);
28
27
  debug(`Generating a download directory at "${downloadPath}"`);
29
28
  await mkdir(downloadPath);
@@ -84,9 +83,5 @@ const route = {
84
83
  return resolve();
85
84
  })
86
85
  .pipe(res);
87
- }),
88
- method: Methods.post,
89
- path: HTTPRoutes.download,
90
- tags: [APITags.browserAPI],
91
- };
92
- export default route;
86
+ });
87
+ }
@@ -1,4 +1,6 @@
1
- import { BrowserHTTPRoute, CDPLaunchOptions, SystemQueryParameters } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, Methods, Request, SystemQueryParameters, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
2
4
  interface JSONSchema {
3
5
  code: string;
4
6
  context?: Record<string, string | number>;
@@ -14,5 +16,16 @@ export interface QuerySchema extends SystemQueryParameters {
14
16
  * by type (HTML data is "text/html", Objects are "application/json")
15
17
  */
16
18
  export type ResponseSchema = unknown;
17
- declare const route: BrowserHTTPRoute;
18
- export default route;
19
+ export default class FunctionPost extends BrowserHTTPRoute {
20
+ accepts: contentTypes[];
21
+ auth: boolean;
22
+ browser: typeof CDPChromium;
23
+ concurrency: boolean;
24
+ contentTypes: contentTypes[];
25
+ description: string;
26
+ method: Methods;
27
+ path: HTTPRoutes;
28
+ tags: APITags[];
29
+ handler: (req: Request, res: ServerResponse, browser: BrowserInstance) => Promise<void>;
30
+ }
31
+ export {};
@@ -1,26 +1,25 @@
1
- import { APITags, BadRequest, CDPChromium, HTTPRoutes, Methods, ServerError, contentTypes, dedent, writeResponse, } from '@browserless.io/browserless';
1
+ import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, contentTypes, dedent, writeResponse, } from '@browserless.io/browserless';
2
2
  import Stream from 'stream';
3
3
  import { fileTypeFromBuffer } from 'file-type';
4
4
  import functionHandler from '../utils/function/handler.js';
5
- const route = {
6
- accepts: [contentTypes.json, contentTypes.javascript],
7
- auth: true,
8
- browser: CDPChromium,
9
- concurrency: true,
10
- contentTypes: [contentTypes.any],
11
- description: dedent(`
5
+ export default class FunctionPost extends BrowserHTTPRoute {
6
+ accepts = [contentTypes.json, contentTypes.javascript];
7
+ auth = true;
8
+ browser = CDPChromium;
9
+ concurrency = true;
10
+ contentTypes = [contentTypes.any];
11
+ description = dedent(`
12
12
  A JSON or JavaScript content-type API for running puppeteer code in the browser's context.
13
13
  Browserless sets up a blank page, injects your puppeteer code, and runs it.
14
14
  You can optionally load external libraries via the "import" module that are meant for browser usage.
15
15
  Values returned from the function are checked and an appropriate content-type and response is sent back
16
- to your HTTP call.`),
17
- handler: async (req, res, browser) => {
18
- const { getConfig: getConfig, getDebug: getDebug } = route;
19
- if (!getConfig || !getDebug) {
20
- throw new ServerError(`Couldn't load configuration for request`);
21
- }
22
- const debug = getDebug();
23
- const config = getConfig();
16
+ to your HTTP call.`);
17
+ method = Methods.post;
18
+ path = HTTPRoutes.function;
19
+ tags = [APITags.browserAPI];
20
+ handler = async (req, res, browser) => {
21
+ const debug = this.debug();
22
+ const config = this.config();
24
23
  const handler = functionHandler(config, debug);
25
24
  const { contentType, payload, page } = await handler(req, browser);
26
25
  debug(`Got function response of "${contentType}"`);
@@ -45,9 +44,5 @@ const route = {
45
44
  writeResponse(res, 200, payload, contentType);
46
45
  }
47
46
  return;
48
- },
49
- method: Methods.post,
50
- path: HTTPRoutes.function,
51
- tags: [APITags.browserAPI],
52
- };
53
- export default route;
47
+ };
48
+ }
@@ -538,14 +538,14 @@
538
538
  "length": {
539
539
  "type": "number"
540
540
  },
541
- "__@toStringTag@42863": {
541
+ "__@toStringTag@21651": {
542
542
  "type": "string",
543
543
  "const": "Uint8Array"
544
544
  }
545
545
  },
546
546
  "required": [
547
547
  "BYTES_PER_ELEMENT",
548
- "__@toStringTag@42863",
548
+ "__@toStringTag@21651",
549
549
  "buffer",
550
550
  "byteLength",
551
551
  "byteOffset",
@@ -580,13 +580,13 @@
580
580
  "byteLength": {
581
581
  "type": "number"
582
582
  },
583
- "__@toStringTag@42863": {
583
+ "__@toStringTag@21651": {
584
584
  "type": "string"
585
585
  }
586
586
  },
587
587
  "additionalProperties": false,
588
588
  "required": [
589
- "__@toStringTag@42863",
589
+ "__@toStringTag@21651",
590
590
  "byteLength"
591
591
  ]
592
592
  },
@@ -596,18 +596,18 @@
596
596
  "byteLength": {
597
597
  "type": "number"
598
598
  },
599
- "__@species@42964": {
599
+ "__@species@21752": {
600
600
  "$ref": "#/definitions/SharedArrayBuffer"
601
601
  },
602
- "__@toStringTag@42863": {
602
+ "__@toStringTag@21651": {
603
603
  "type": "string",
604
604
  "const": "SharedArrayBuffer"
605
605
  }
606
606
  },
607
607
  "additionalProperties": false,
608
608
  "required": [
609
- "__@species@42964",
610
- "__@toStringTag@42863",
609
+ "__@species@21752",
610
+ "__@toStringTag@21651",
611
611
  "byteLength"
612
612
  ]
613
613
  },
@@ -1,5 +1,7 @@
1
- import { BrowserHTTPRoute, CDPLaunchOptions, SystemQueryParameters, WaitForEventOptions, WaitForFunctionOptions, WaitForSelectorOptions, bestAttempt, rejectRequestPattern, rejectResourceTypes, requestInterceptors } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, Methods, Request, SystemQueryParameters, WaitForEventOptions, WaitForFunctionOptions, WaitForSelectorOptions, bestAttempt, contentTypes, rejectRequestPattern, rejectResourceTypes, requestInterceptors } from '@browserless.io/browserless';
2
3
  import { Page } from 'puppeteer-core';
4
+ import { ServerResponse } from 'http';
3
5
  export interface BodySchema {
4
6
  addScriptTag?: Array<Parameters<Page['addScriptTag']>[0]>;
5
7
  addStyleTag?: Array<Parameters<Page['addStyleTag']>[0]>;
@@ -31,5 +33,15 @@ export interface QuerySchema extends SystemQueryParameters {
31
33
  * Responds with an application/pdf content-type and a binary PDF
32
34
  */
33
35
  export type ResponseSchema = string;
34
- declare const route: BrowserHTTPRoute;
35
- export default route;
36
+ export default class PDFPost extends BrowserHTTPRoute {
37
+ accepts: contentTypes[];
38
+ auth: boolean;
39
+ browser: typeof CDPChromium;
40
+ concurrency: boolean;
41
+ contentTypes: contentTypes[];
42
+ description: string;
43
+ method: Methods;
44
+ path: HTTPRoutes;
45
+ tags: APITags[];
46
+ handler: (req: Request, res: ServerResponse, browser: BrowserInstance) => Promise<void>;
47
+ }
@@ -1,12 +1,20 @@
1
- import { APITags, BadRequest, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
2
- const route = {
3
- accepts: [contentTypes.json],
4
- auth: true,
5
- browser: CDPChromium,
6
- concurrency: true,
7
- contentTypes: [contentTypes.pdf],
8
- description: `A JSON-based API for getting a PDF binary from either a supplied "url" or "html" payload in your request.`,
9
- handler: async (req, res, browser) => {
1
+ import { APITags, BadRequest, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, bestAttemptCatch, contentTypes, dedent, noop, waitForEvent as waitForEvt, waitForFunction as waitForFn, writeResponse, } from '@browserless.io/browserless';
2
+ export default class PDFPost extends BrowserHTTPRoute {
3
+ accepts = [contentTypes.json];
4
+ auth = true;
5
+ browser = CDPChromium;
6
+ concurrency = true;
7
+ contentTypes = [contentTypes.pdf];
8
+ description = dedent(`
9
+ A JSON-based API for getting a PDF binary from either a supplied
10
+ "url" or "html" payload in your request. Many options exist for
11
+ injecting cookies, request interceptors, user-agents and waiting for
12
+ selectors, timers and more.
13
+ `);
14
+ method = Methods.post;
15
+ path = HTTPRoutes.pdf;
16
+ tags = [APITags.browserAPI];
17
+ handler = async (req, res, browser) => {
10
18
  const contentType = !req.headers.accept || req.headers.accept?.includes('*')
11
19
  ? 'application/pdf'
12
20
  : req.headers.accept;
@@ -99,9 +107,5 @@ const route = {
99
107
  return pdfStream.pipe(res).once('finish', resolve).once('error', reject);
100
108
  });
101
109
  page.close().catch(noop);
102
- },
103
- method: Methods.post,
104
- path: HTTPRoutes.pdf,
105
- tags: [APITags.browserAPI],
106
- };
107
- export default route;
110
+ };
111
+ }
@@ -1,4 +1,6 @@
1
- import { BrowserHTTPRoute, CDPLaunchOptions, SystemQueryParameters } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserHTTPRoute, BrowserInstance, CDPChromium, CDPLaunchOptions, HTTPRoutes, Methods, Request, SystemQueryParameters, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
2
4
  export interface BodySchema {
3
5
  budgets?: Array<object>;
4
6
  config?: object;
@@ -13,5 +15,15 @@ export interface QuerySchema extends SystemQueryParameters {
13
15
  * JSON body
14
16
  */
15
17
  export type ResponseSchema = object;
16
- declare const route: BrowserHTTPRoute;
17
- export default route;
18
+ export default class PerformancePost extends BrowserHTTPRoute {
19
+ accepts: contentTypes[];
20
+ auth: boolean;
21
+ browser: typeof CDPChromium;
22
+ concurrency: boolean;
23
+ contentTypes: contentTypes[];
24
+ description: string;
25
+ method: Methods;
26
+ path: HTTPRoutes;
27
+ tags: APITags[];
28
+ handler: (req: Request, res: ServerResponse, browser: BrowserInstance) => Promise<void>;
29
+ }
@@ -1,30 +1,22 @@
1
- import { APITags, BadRequest, CDPChromium, HTTPRoutes, Methods, ServerError, contentTypes, jsonResponse, } from '@browserless.io/browserless';
1
+ import { APITags, BrowserHTTPRoute, CDPChromium, HTTPRoutes, Methods, contentTypes, jsonResponse, } from '@browserless.io/browserless';
2
2
  import main from '../utils/performance/main.js';
3
- const route = {
4
- accepts: [contentTypes.json],
5
- auth: true,
6
- browser: CDPChromium,
7
- concurrency: true,
8
- contentTypes: [contentTypes.json],
9
- description: `Run lighthouse performance audits with a supplied "url" in your JSON payload.`,
10
- handler: async (req, res, browser) => {
11
- const { getConfig: getConfig } = route;
12
- if (!req.body) {
13
- throw new BadRequest(`No JSON body present`);
14
- }
15
- if (!getConfig) {
16
- throw new ServerError(`Couldn't load configuration for timeouts`);
17
- }
18
- const config = getConfig();
3
+ export default class PerformancePost extends BrowserHTTPRoute {
4
+ accepts = [contentTypes.json];
5
+ auth = true;
6
+ browser = CDPChromium;
7
+ concurrency = true;
8
+ contentTypes = [contentTypes.json];
9
+ description = `Run lighthouse performance audits with a supplied "url" in your JSON payload.`;
10
+ method = Methods.post;
11
+ path = HTTPRoutes.performance;
12
+ tags = [APITags.browserAPI];
13
+ handler = async (req, res, browser) => {
14
+ const config = this.config();
19
15
  const response = await main({
20
16
  browser,
21
17
  context: req.body,
22
18
  timeout: config.getTimeout(),
23
19
  });
24
20
  return jsonResponse(res, 200, response);
25
- },
26
- method: Methods.post,
27
- path: HTTPRoutes.performance,
28
- tags: [APITags.browserAPI],
29
- };
30
- export default route;
21
+ };
22
+ }