@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,24 +1,19 @@
1
- import { APITags, HTTPManagementRoutes, Methods, ServerError, contentTypes, writeResponse, } from '@browserless.io/browserless';
2
- const route = {
3
- accepts: [contentTypes.any],
4
- auth: true,
5
- browser: null,
6
- concurrency: false,
7
- contentTypes: [contentTypes.json],
8
- description: `Gets total metric details from the time the server started.`,
9
- handler: async (_req, res) => {
10
- const { getFileSystem: _fileSystem, getConfig: _config } = route;
11
- if (!_fileSystem || !_config) {
12
- throw new ServerError(`Couldn't locate the file-system or config module`);
13
- }
14
- const fileSystem = _fileSystem();
15
- const config = _config();
1
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, contentTypes, writeResponse, } from '@browserless.io/browserless';
2
+ export default class MetricsGetRoute extends HTTPRoute {
3
+ accepts = [contentTypes.any];
4
+ auth = true;
5
+ browser = null;
6
+ concurrency = false;
7
+ contentTypes = [contentTypes.json];
8
+ description = `Gets total metric details from the time the server started.`;
9
+ method = Methods.get;
10
+ path = HTTPManagementRoutes.metrics;
11
+ tags = [APITags.management];
12
+ handler = async (_req, res) => {
13
+ const fileSystem = this.fileSystem();
14
+ const config = this.config();
16
15
  const stats = await fileSystem.read(config.getMetricsJSONPath());
17
16
  const response = `[${stats.join(',')}]`;
18
17
  return writeResponse(res, 200, response, contentTypes.json);
19
- },
20
- method: Methods.get,
21
- path: HTTPManagementRoutes.metrics,
22
- tags: [APITags.management],
23
- };
24
- export default route;
18
+ };
19
+ }
@@ -1,4 +1,16 @@
1
- import { HTTPRoute, IBrowserlessMetricTotals } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, HTTPManagementRoutes, HTTPRoute, IBrowserlessMetricTotals, Methods, Request, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
2
4
  export type ResponseSchema = IBrowserlessMetricTotals;
3
- declare const route: HTTPRoute;
4
- export default route;
5
+ export default class MetricsTotalGetRoute extends HTTPRoute {
6
+ accepts: contentTypes[];
7
+ auth: boolean;
8
+ browser: null;
9
+ concurrency: boolean;
10
+ contentTypes: contentTypes[];
11
+ description: string;
12
+ method: Methods;
13
+ path: HTTPManagementRoutes;
14
+ tags: APITags[];
15
+ handler: (_req: Request, res: ServerResponse) => Promise<void>;
16
+ }
@@ -1,19 +1,18 @@
1
- import { APITags, HTTPManagementRoutes, Methods, ServerError, contentTypes, writeResponse, } from '@browserless.io/browserless';
1
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, contentTypes, writeResponse, } from '@browserless.io/browserless';
2
2
  const fiveMinuteIntervalsInAMonth = 8640;
3
- const route = {
4
- accepts: [contentTypes.any],
5
- auth: true,
6
- browser: null,
7
- concurrency: false,
8
- contentTypes: [contentTypes.json],
9
- description: `Gets total metric details summed from the time the server started.`,
10
- handler: async (_req, res) => {
11
- const { getFileSystem: _fileSystem, getConfig: _config } = route;
12
- if (!_fileSystem || !_config) {
13
- throw new ServerError(`Couldn't locate the file-system or config module`);
14
- }
15
- const fileSystem = _fileSystem();
16
- const config = _config();
3
+ export default class MetricsTotalGetRoute extends HTTPRoute {
4
+ accepts = [contentTypes.any];
5
+ auth = true;
6
+ browser = null;
7
+ concurrency = false;
8
+ contentTypes = [contentTypes.json];
9
+ description = `Gets total metric details summed from the time the server started.`;
10
+ method = Methods.get;
11
+ path = HTTPManagementRoutes.metricsTotal;
12
+ tags = [APITags.management];
13
+ handler = async (_req, res) => {
14
+ const fileSystem = this.fileSystem();
15
+ const config = this.config();
17
16
  const metrics = (await fileSystem.read(config.getMetricsJSONPath())).map((m) => JSON.parse(m));
18
17
  const availableMetrics = metrics.length;
19
18
  const totals = metrics.reduce((accum, metric) => ({
@@ -52,9 +51,5 @@ const route = {
52
51
  totals.meanTime = totals.meanTime / metrics.length;
53
52
  totals.estimatedMonthlyUnits = Math.round(totals.units / (availableMetrics / fiveMinuteIntervalsInAMonth));
54
53
  return writeResponse(res, 200, JSON.stringify(totals), contentTypes.json);
55
- },
56
- method: Methods.get,
57
- path: HTTPManagementRoutes.metricsTotal,
58
- tags: [APITags.management],
59
- };
60
- export default route;
54
+ };
55
+ }
@@ -1,4 +1,16 @@
1
- import { BrowserlessSessionJSON, HTTPRoute } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ import { APITags, BrowserlessSessionJSON, HTTPManagementRoutes, HTTPRoute, Methods, Request, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
2
4
  export type ResponseSchema = BrowserlessSessionJSON[];
3
- declare const route: HTTPRoute;
4
- export default route;
5
+ export default class SessionsGetRoute extends HTTPRoute {
6
+ accepts: contentTypes[];
7
+ auth: boolean;
8
+ browser: null;
9
+ concurrency: boolean;
10
+ contentTypes: contentTypes[];
11
+ description: string;
12
+ method: Methods;
13
+ path: HTTPManagementRoutes;
14
+ tags: APITags[];
15
+ handler: (_req: Request, res: ServerResponse) => Promise<void>;
16
+ }
@@ -1,21 +1,17 @@
1
- import { APITags, BadRequest, HTTPManagementRoutes, Methods, contentTypes, jsonResponse, } from '@browserless.io/browserless';
2
- const route = {
3
- accepts: [contentTypes.any],
4
- auth: true,
5
- browser: null,
6
- concurrency: false,
7
- contentTypes: [contentTypes.json],
8
- description: `Lists all currently running sessions and relevant meta-data excluding potentially open pages.`,
9
- handler: async (_req, res) => {
10
- const { getBrowserManager: browserManager } = route;
11
- if (!browserManager) {
12
- throw new BadRequest(`Couldn't load browsers running`);
13
- }
14
- const response = await browserManager().getAllSessions();
1
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, contentTypes, jsonResponse, } from '@browserless.io/browserless';
2
+ export default class SessionsGetRoute extends HTTPRoute {
3
+ accepts = [contentTypes.any];
4
+ auth = true;
5
+ browser = null;
6
+ concurrency = false;
7
+ contentTypes = [contentTypes.json];
8
+ description = `Lists all currently running sessions and relevant meta-data excluding potentially open pages.`;
9
+ method = Methods.get;
10
+ path = HTTPManagementRoutes.sessions;
11
+ tags = [APITags.management];
12
+ handler = async (_req, res) => {
13
+ const browserManager = this.browserManager();
14
+ const response = await browserManager.getAllSessions();
15
15
  return jsonResponse(res, 200, response);
16
- },
17
- method: Methods.get,
18
- path: HTTPManagementRoutes.sessions,
19
- tags: [APITags.management],
20
- };
21
- export default route;
16
+ };
17
+ }
@@ -1,3 +1,15 @@
1
- import { HTTPRoute } from '@browserless.io/browserless';
2
- declare const route: HTTPRoute;
3
- export default route;
1
+ /// <reference types="node" />
2
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, Request, contentTypes } from '@browserless.io/browserless';
3
+ import { ServerResponse } from 'http';
4
+ export default class StaticGetRoute extends HTTPRoute {
5
+ accepts: contentTypes[];
6
+ auth: boolean;
7
+ browser: null;
8
+ concurrency: boolean;
9
+ contentTypes: contentTypes[];
10
+ description: string;
11
+ method: Methods;
12
+ path: HTTPManagementRoutes;
13
+ tags: APITags[];
14
+ handler: (req: Request, res: ServerResponse) => Promise<unknown>;
15
+ }
@@ -1,4 +1,4 @@
1
- import { APITags, HTTPManagementRoutes, Methods, NotFound, ServerError, contentTypes, createLogger, fileExists, mimeTypes, } from '@browserless.io/browserless';
1
+ import { APITags, HTTPManagementRoutes, HTTPRoute, Methods, NotFound, contentTypes, createLogger, fileExists, mimeTypes, } from '@browserless.io/browserless';
2
2
  import { createReadStream } from 'fs';
3
3
  import path from 'path';
4
4
  const debug = createLogger('http:static');
@@ -20,24 +20,23 @@ const streamFile = (res, file, contentType) => new Promise((resolve, reject) =>
20
20
  .on('end', resolve)
21
21
  .pipe(res);
22
22
  });
23
- const route = {
24
- accepts: [contentTypes.any],
25
- auth: false,
26
- browser: null,
27
- concurrency: false,
28
- contentTypes: [contentTypes.any],
29
- description: `Serves static files inside of this "static" directory. Content-types will vary depending on the type of file being returned.`,
30
- handler: async (req, res) => {
31
- const { getConfig: getConfig } = route;
23
+ export default class StaticGetRoute extends HTTPRoute {
24
+ accepts = [contentTypes.any];
25
+ auth = false;
26
+ browser = null;
27
+ concurrency = false;
28
+ contentTypes = [contentTypes.any];
29
+ description = `Serves static files inside of this "static" directory. Content-types will vary depending on the type =of file being returned.`;
30
+ method = Methods.get;
31
+ path = HTTPManagementRoutes.static;
32
+ tags = [APITags.management];
33
+ handler = async (req, res) => {
32
34
  const { pathname } = req.parsed;
33
35
  const fileCache = pathMap.get(pathname);
34
36
  if (fileCache) {
35
37
  return streamFile(res, fileCache.path, fileCache.contentType);
36
38
  }
37
- if (!getConfig) {
38
- throw new ServerError(`Couldn't load configuration for request`);
39
- }
40
- const config = getConfig();
39
+ const config = this.config();
41
40
  const file = path.join(config.getStatic(), pathname);
42
41
  const indexFile = path.join(file, 'index.html');
43
42
  const filePath = (await Promise.all([
@@ -59,9 +58,5 @@ const route = {
59
58
  path: filePath,
60
59
  });
61
60
  return streamFile(res, filePath, contentType);
62
- },
63
- method: Methods.get,
64
- path: HTTPManagementRoutes.static,
65
- tags: [APITags.management],
66
- };
67
- export default route;
61
+ };
62
+ }
@@ -1,6 +1,16 @@
1
- import { BrowserServerOptions, BrowserWebsocketRoute, SystemQueryParameters } from '@browserless.io/browserless';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { APITags, BrowserServerOptions, BrowserWebsocketRoute, PlaywrightWebkit, Request, SystemQueryParameters, WebsocketRoutes } from '@browserless.io/browserless';
4
+ import { Duplex } from 'stream';
2
5
  export interface QuerySchema extends SystemQueryParameters {
3
6
  launch?: BrowserServerOptions | string;
4
7
  }
5
- declare const route: BrowserWebsocketRoute;
6
- export default route;
8
+ export default class PlaywrightWebkitRoute extends BrowserWebsocketRoute {
9
+ auth: boolean;
10
+ browser: typeof PlaywrightWebkit;
11
+ concurrency: boolean;
12
+ description: string;
13
+ path: WebsocketRoutes;
14
+ tags: APITags[];
15
+ handler: (req: Request, socket: Duplex, head: Buffer, browser: PlaywrightWebkit) => Promise<void>;
16
+ }
@@ -1,10 +1,12 @@
1
- import { APITags, BadRequest, PlaywrightWebkit, WebsocketRoutes, } from '@browserless.io/browserless';
2
- const route = {
3
- auth: true,
4
- browser: PlaywrightWebkit,
5
- concurrency: true,
6
- description: `Connect to Webkit with any playwright-compliant library.`,
7
- handler: async (req, socket, head, browser) => {
1
+ import { APITags, BadRequest, BrowserWebsocketRoute, PlaywrightWebkit, WebsocketRoutes, } from '@browserless.io/browserless';
2
+ export default class PlaywrightWebkitRoute extends BrowserWebsocketRoute {
3
+ auth = true;
4
+ browser = PlaywrightWebkit;
5
+ concurrency = true;
6
+ description = `Connect to Webkit with any playwright-compliant library.`;
7
+ path = WebsocketRoutes.playwrightWebkit;
8
+ tags = [APITags.browserWS];
9
+ handler = async (req, socket, head, browser) => {
8
10
  const isPlaywright = req.headers['user-agent']
9
11
  ?.toLowerCase()
10
12
  .includes('playwright');
@@ -12,8 +14,5 @@ const route = {
12
14
  throw new BadRequest(`Only playwright is allowed to work with this route`);
13
15
  }
14
16
  return browser.proxyWebSocket(req, socket, head);
15
- },
16
- path: WebsocketRoutes.playwrightWebkit,
17
- tags: [APITags.browserWS],
18
- };
19
- export default route;
17
+ };
18
+ }
package/build/server.js CHANGED
@@ -172,7 +172,6 @@ export class HTTPServer {
172
172
  if (e instanceof Timeout) {
173
173
  return writeResponse(res, 408, e.message);
174
174
  }
175
- this.log(`Error handling request at "${route.path}": ${e}`);
176
175
  return writeResponse(res, 500, e.toString());
177
176
  });
178
177
  };
package/build/types.d.ts CHANGED
@@ -47,7 +47,14 @@ export interface BrowserJSON {
47
47
  * the request object, that produces the launch options.
48
48
  */
49
49
  type defaultLaunchOptions = CDPLaunchOptions | BrowserlessLaunch | ((req: Request) => CDPLaunchOptions | BrowserlessLaunch);
50
- interface Route {
50
+ declare abstract class Route {
51
+ protected _browserManager: Browserless['browserManager'];
52
+ protected _config: Browserless['config'];
53
+ protected _fileSystem: Browserless['fileSystem'];
54
+ protected _debug: Browserless['debug'];
55
+ protected _metrics: Browserless['metrics'];
56
+ protected _monitoring: Browserless['monitoring'];
57
+ constructor(_browserManager: Browserless['browserManager'], _config: Browserless['config'], _fileSystem: Browserless['fileSystem'], _debug: Browserless['debug'], _metrics: Browserless['metrics'], _monitoring: Browserless['monitoring']);
51
58
  /**
52
59
  * A boolean, or a function that returns a boolean, on
53
60
  * whether the route requires an API token to access.
@@ -59,6 +66,18 @@ interface Route {
59
66
  * automatically if your route defines a BodySchema type.
60
67
  */
61
68
  bodySchema?: unknown;
69
+ /**
70
+ * The query parameters accepted by the route, defined in
71
+ * an object format. This is auto-generated for you if your
72
+ * route defines and exports a QuerySchema type.
73
+ */
74
+ querySchema?: unknown;
75
+ /**
76
+ * The structure of the routes response when successful. This
77
+ * is auto-generated for you if your route defines a ResponseSchema
78
+ * type and exports it in your route.
79
+ */
80
+ responseSchema?: unknown;
62
81
  /**
63
82
  * Whether the route should be bound by the global
64
83
  * concurrency limit defined in your configuration.
@@ -68,142 +87,133 @@ interface Route {
68
87
  * Description of the route and what it does. This description
69
88
  * is then used in the embedded documentation site.
70
89
  */
71
- description: string;
90
+ description?: string;
72
91
  /**
73
92
  * Helper function to load the browser-manager instance. Defined
74
93
  * and injected by browserless after initialization.
75
94
  * @returns BrowserManager
76
95
  */
77
- getBrowserManager?: () => Browserless['browserManager'];
96
+ browserManager: () => import("@browserless.io/browserless").BrowserManager;
78
97
  /**
79
98
  * Helper function that loads the config module. Defined and injected by
80
99
  * browserless after initialization.
81
100
  * @returns Config
82
101
  */
83
- getConfig?: () => Browserless['config'];
102
+ config: () => Config;
84
103
  /**
85
104
  * Helper function that loads the debug module, useful
86
105
  * for logging messages scoped to the routes path. Defined
87
106
  * and injected by browserless after initialization.
88
107
  * @returns Debug
89
108
  */
90
- getDebug?: () => debug.Debugger;
109
+ debug: () => import("debug").Debugger;
91
110
  /**
92
111
  * Helper function that loads the file-system module
93
112
  * for interacting with file-systems. Defined and injected by
94
113
  * browserless after initialization.
95
114
  * @returns FileSystem
96
115
  */
97
- getFileSystem?: () => Browserless['fileSystem'];
116
+ fileSystem: () => import("@browserless.io/browserless").FileSystem;
98
117
  /**
99
118
  * Helper function that loads the metrics module for
100
119
  * collecting and aggregating statistics. Defined and injected by
101
120
  * browserless after initialization.
102
121
  * @returns Metrics
103
122
  */
104
- getMetrics?: () => Browserless['metrics'];
123
+ metrics: () => Metrics;
105
124
  /**
106
125
  * Helper function that loads the monitoring module useful
107
126
  * for monitoring system health. Defined and injected by
108
127
  * browserless after initialization.
109
128
  * @returns Monitor
110
129
  */
111
- getMonitoring?: () => Browserless['monitoring'];
130
+ monitoring: () => import("@browserless.io/browserless").Monitoring;
112
131
  /**
113
132
  * The HTTP path that this route handles, eg '/my-route'
114
133
  */
115
- path: HTTPRoutes | WebsocketRoutes | HTTPManagementRoutes | string;
116
- /**
117
- * The query parameters accepted by the route, defined in
118
- * an object format. This is auto-generated for you if your
119
- * route defines and exports a QuerySchema type.
120
- */
121
- querySchema?: unknown;
122
- /**
123
- * The structure of the routes response when successful. This
124
- * is auto-generated for you if your route defines a ResponseSchema
125
- * type and exports it in your route.
126
- */
127
- responseSchema?: unknown;
134
+ abstract path: HTTPRoutes | WebsocketRoutes | HTTPManagementRoutes | string;
128
135
  /**
129
136
  * The tag(s) for the route to categorize it in the
130
137
  * documentation portal
131
138
  */
132
- tags: APITags[];
139
+ abstract tags: APITags[];
133
140
  }
134
141
  /**
135
142
  * A primitive HTTP-based route that doesn't require a
136
143
  * browser in order to fulfill requests. Used by downstream HTTPRoute
137
144
  * and WebSocketRoute
138
145
  */
139
- interface BasicHTTPRoute extends Route {
146
+ declare abstract class BasicHTTPRoute extends Route {
140
147
  /**
141
148
  * The allowed Content-Types that this route can read and handle.
142
149
  * If a request comes in with a Content-Type of 'application/json', then
143
150
  * this accepts would need to include ["application/json"] in order to not 404
144
151
  */
145
- accepts: Array<contentTypes>;
152
+ abstract accepts: Array<contentTypes>;
146
153
  /**
147
154
  * The Content-Types that this route will will respond with, and must match the Accepts
148
155
  * Header from a client if present. If a request comes in with an Accepts of "application/json"
149
156
  * then the contentTypes here would need to include ["application/json"] in order to not 404.
150
157
  */
151
- contentTypes: Array<contentTypes>;
158
+ abstract contentTypes: Array<contentTypes>;
152
159
  /**
153
160
  * The allowed methods ("GET", "POST", etc) this route can utilize and match against.
154
161
  */
155
- method: Methods;
162
+ abstract method: Methods;
156
163
  }
157
164
  /**
158
165
  * A HTTP-based route, with a handler, that can fulfill requests without
159
166
  * a browser required.
160
167
  */
161
- export interface HTTPRoute extends BasicHTTPRoute {
162
- browser: null;
168
+ export declare abstract class HTTPRoute extends BasicHTTPRoute {
163
169
  /**
164
170
  * Handles an inbound HTTP request, and supplies the Request and Response objects from node's HTTP request event
165
171
  */
166
- handler: (req: Request, res: http.ServerResponse) => Promise<unknown>;
172
+ abstract handler: (req: Request, res: http.ServerResponse) => Promise<unknown>;
167
173
  }
168
174
  /**
169
175
  * A HTTP-based route, with a handler, that can fulfill requests but
170
176
  * requires a browser in order to do so. Handler will then be called
171
177
  * with a 3rd argument of the browser class specified.
172
178
  */
173
- export interface BrowserHTTPRoute extends BasicHTTPRoute {
174
- browser: BrowserClasses;
179
+ export declare abstract class BrowserHTTPRoute extends BasicHTTPRoute {
175
180
  defaultLaunchOptions?: defaultLaunchOptions;
181
+ abstract browser: BrowserClasses;
176
182
  /**
177
183
  * Handles an inbound HTTP request with a 3rd param of the predefined
178
184
  * browser used for the route -- only Chrome CDP is support currently.
179
185
  */
180
- handler: (req: Request, res: http.ServerResponse, browser: BrowserInstance) => Promise<unknown>;
181
- onNewPage?: undefined;
186
+ abstract handler: (req: Request, res: http.ServerResponse, browser: BrowserInstance) => Promise<unknown>;
187
+ /**
188
+ * An optional function to automatically set up or handle new page
189
+ * creation. Useful for injecting behaviors or other functionality.
190
+ */
191
+ onNewPage?: (url: URL, page: Page) => Promise<void>;
182
192
  }
183
193
  /**
184
194
  * A WebSocket-based route, with a handler, that can fulfill requests
185
195
  * that do not require a browser in order to operate.
186
196
  */
187
- export interface WebSocketRoute extends Route {
197
+ export declare abstract class WebSocketRoute extends Route {
188
198
  browser: null;
189
199
  /**
190
200
  * Handles an inbound Websocket request, and handles the connection
191
201
  */
192
- handler: (req: Request, socket: stream.Duplex, head: Buffer) => Promise<unknown>;
202
+ abstract handler: (req: Request, socket: stream.Duplex, head: Buffer) => Promise<unknown>;
193
203
  }
194
204
  /**
195
205
  * A WebSocket-based route, with a handler, that can fulfill requests
196
206
  * that need a browser. Handler is called with an additional argument of
197
207
  * browser (the browser class required to run the route).
198
208
  */
199
- export interface BrowserWebsocketRoute extends Route {
200
- browser: BrowserClasses;
209
+ export declare abstract class BrowserWebsocketRoute extends Route {
210
+ abstract browser: BrowserClasses;
201
211
  defaultLaunchOptions?: defaultLaunchOptions;
202
212
  /**
203
213
  * Handles an inbound Websocket request, and handles the connection
204
214
  * with the prior set browser being injected.
205
215
  */
206
- handler(req: Request, socket: stream.Duplex, head: Buffer, browser: BrowserInstance): Promise<unknown>;
216
+ abstract handler(req: Request, socket: stream.Duplex, head: Buffer, browser: BrowserInstance): Promise<unknown>;
207
217
  /**
208
218
  * An optional function to automatically set up or handle new page
209
219
  * creation. Useful for injecting behaviors or other functionality.
package/build/types.js CHANGED
@@ -1,3 +1,138 @@
1
+ class Route {
2
+ _browserManager;
3
+ _config;
4
+ _fileSystem;
5
+ _debug;
6
+ _metrics;
7
+ _monitoring;
8
+ constructor(_browserManager, _config, _fileSystem, _debug, _metrics, _monitoring) {
9
+ this._browserManager = _browserManager;
10
+ this._config = _config;
11
+ this._fileSystem = _fileSystem;
12
+ this._debug = _debug;
13
+ this._metrics = _metrics;
14
+ this._monitoring = _monitoring;
15
+ }
16
+ /**
17
+ * A boolean, or a function that returns a boolean, on
18
+ * whether the route requires an API token to access.
19
+ */
20
+ auth = true;
21
+ /**
22
+ * The schematic of the submitted BODY (typically)
23
+ * an object when the route is json-based. This is generated
24
+ * automatically if your route defines a BodySchema type.
25
+ */
26
+ bodySchema;
27
+ /**
28
+ * The query parameters accepted by the route, defined in
29
+ * an object format. This is auto-generated for you if your
30
+ * route defines and exports a QuerySchema type.
31
+ */
32
+ querySchema;
33
+ /**
34
+ * The structure of the routes response when successful. This
35
+ * is auto-generated for you if your route defines a ResponseSchema
36
+ * type and exports it in your route.
37
+ */
38
+ responseSchema;
39
+ /**
40
+ * Whether the route should be bound by the global
41
+ * concurrency limit defined in your configuration.
42
+ */
43
+ concurrency = true;
44
+ /**
45
+ * Description of the route and what it does. This description
46
+ * is then used in the embedded documentation site.
47
+ */
48
+ description;
49
+ /**
50
+ * Helper function to load the browser-manager instance. Defined
51
+ * and injected by browserless after initialization.
52
+ * @returns BrowserManager
53
+ */
54
+ browserManager = () => this._browserManager;
55
+ /**
56
+ * Helper function that loads the config module. Defined and injected by
57
+ * browserless after initialization.
58
+ * @returns Config
59
+ */
60
+ config = () => this._config;
61
+ /**
62
+ * Helper function that loads the debug module, useful
63
+ * for logging messages scoped to the routes path. Defined
64
+ * and injected by browserless after initialization.
65
+ * @returns Debug
66
+ */
67
+ debug = () => this._debug;
68
+ /**
69
+ * Helper function that loads the file-system module
70
+ * for interacting with file-systems. Defined and injected by
71
+ * browserless after initialization.
72
+ * @returns FileSystem
73
+ */
74
+ fileSystem = () => this._fileSystem;
75
+ /**
76
+ * Helper function that loads the metrics module for
77
+ * collecting and aggregating statistics. Defined and injected by
78
+ * browserless after initialization.
79
+ * @returns Metrics
80
+ */
81
+ metrics = () => this._metrics;
82
+ /**
83
+ * Helper function that loads the monitoring module useful
84
+ * for monitoring system health. Defined and injected by
85
+ * browserless after initialization.
86
+ * @returns Monitor
87
+ */
88
+ monitoring = () => this._monitoring;
89
+ }
90
+ /**
91
+ * A primitive HTTP-based route that doesn't require a
92
+ * browser in order to fulfill requests. Used by downstream HTTPRoute
93
+ * and WebSocketRoute
94
+ */
95
+ class BasicHTTPRoute extends Route {
96
+ }
97
+ /**
98
+ * A HTTP-based route, with a handler, that can fulfill requests without
99
+ * a browser required.
100
+ */
101
+ export class HTTPRoute extends BasicHTTPRoute {
102
+ }
103
+ /**
104
+ * A HTTP-based route, with a handler, that can fulfill requests but
105
+ * requires a browser in order to do so. Handler will then be called
106
+ * with a 3rd argument of the browser class specified.
107
+ */
108
+ export class BrowserHTTPRoute extends BasicHTTPRoute {
109
+ defaultLaunchOptions;
110
+ /**
111
+ * An optional function to automatically set up or handle new page
112
+ * creation. Useful for injecting behaviors or other functionality.
113
+ */
114
+ onNewPage;
115
+ }
116
+ /**
117
+ * A WebSocket-based route, with a handler, that can fulfill requests
118
+ * that do not require a browser in order to operate.
119
+ */
120
+ export class WebSocketRoute extends Route {
121
+ browser = null;
122
+ }
123
+ /**
124
+ * A WebSocket-based route, with a handler, that can fulfill requests
125
+ * that need a browser. Handler is called with an additional argument of
126
+ * browser (the browser class required to run the route).
127
+ */
128
+ export class BrowserWebsocketRoute extends Route {
129
+ defaultLaunchOptions;
130
+ /**
131
+ * An optional function to automatically set up or handle new page
132
+ * creation. Useful for injecting behaviors or other functionality.
133
+ */
134
+ onNewPage;
135
+ }
1
136
  export const debugScreenshotOpts = {
2
137
  encoding: 'base64',
3
138
  fullPage: true,
@@ -53,7 +53,6 @@
53
53
  <script src="js/vapi.js"></script>
54
54
  <script src="js/vapi-common.js"></script>
55
55
  <script src="js/vapi-client.js"></script>
56
- <script src="js/vapi-client-extra.js"></script>
57
56
 
58
57
  <script src="js/codemirror/search.js" type="module"></script>
59
58
  <script src="js/codemirror/search-thread.js"></script>