@browserless.io/browserless 2.3.0-beta-1 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/README.md +2 -2
  3. package/bin/browserless.js +47 -18
  4. package/bin/scaffold/README.md +50 -0
  5. package/bin/scaffold/src/hello-world.http.ts +2 -1
  6. package/build/browserless.d.ts +3 -5
  7. package/build/browserless.js +17 -11
  8. package/build/browsers/chrome.cdp.js +1 -1
  9. package/build/browsers/chrome.playwright.js +1 -1
  10. package/build/browsers/index.d.ts +1 -0
  11. package/build/browsers/index.js +4 -1
  12. package/build/data/classes.json +1 -1
  13. package/build/data/selectors.json +1 -1
  14. package/build/exports.d.ts +24 -38
  15. package/build/exports.js +25 -44
  16. package/build/limiter.d.ts +2 -1
  17. package/build/limiter.js +6 -3
  18. package/build/routes/chrome/http/content.post.body.json +8 -8
  19. package/build/routes/chrome/http/content.post.d.ts +2 -1
  20. package/build/routes/chrome/http/content.post.js +3 -2
  21. package/build/routes/chrome/http/download.post.body.json +11 -489
  22. package/build/routes/chrome/http/download.post.d.ts +2 -1
  23. package/build/routes/chrome/http/download.post.js +3 -2
  24. package/build/routes/chrome/http/download.post.query.json +6 -69
  25. package/build/routes/chrome/http/download.post.response.json +0 -1
  26. package/build/routes/chrome/http/function.post.body.json +11 -489
  27. package/build/routes/chrome/http/function.post.d.ts +2 -1
  28. package/build/routes/chrome/http/function.post.js +3 -2
  29. package/build/routes/chrome/http/function.post.query.json +6 -69
  30. package/build/routes/chrome/http/function.post.response.json +0 -1
  31. package/build/routes/chrome/http/json-list.get.d.ts +5 -1
  32. package/build/routes/chrome/http/json-list.get.js +5 -1
  33. package/build/routes/chrome/http/json-list.get.response.json +49 -1
  34. package/build/routes/chrome/http/json-new.put.d.ts +5 -1
  35. package/build/routes/chrome/http/json-new.put.js +5 -1
  36. package/build/routes/chrome/http/json-new.put.response.json +41 -1
  37. package/build/routes/chrome/http/json-protocol.get.d.ts +5 -1
  38. package/build/routes/chrome/http/json-protocol.get.js +5 -1
  39. package/build/routes/chrome/http/json-protocol.get.response.json +3 -1
  40. package/build/routes/chrome/http/json-version.get.d.ts +5 -1
  41. package/build/routes/chrome/http/json-version.get.js +5 -1
  42. package/build/routes/chrome/http/json-version.get.response.json +41 -1
  43. package/build/routes/chrome/http/pdf.post.body.json +153 -9
  44. package/build/routes/chrome/http/pdf.post.d.ts +2 -1
  45. package/build/routes/chrome/http/pdf.post.js +3 -2
  46. package/build/routes/chrome/http/pdf.post.query.json +6 -69
  47. package/build/routes/chrome/http/performance.post.body.json +10 -494
  48. package/build/routes/chrome/http/performance.post.d.ts +2 -1
  49. package/build/routes/chrome/http/performance.post.js +3 -2
  50. package/build/routes/chrome/http/performance.post.query.json +6 -69
  51. package/build/routes/chrome/http/performance.post.response.json +3 -1
  52. package/build/routes/chrome/http/scrape.post.body.json +56 -9
  53. package/build/routes/chrome/http/scrape.post.d.ts +2 -1
  54. package/build/routes/chrome/http/scrape.post.js +3 -2
  55. package/build/routes/chrome/http/scrape.post.response.json +305 -1
  56. package/build/routes/chrome/http/screenshot.post.body.json +99 -9
  57. package/build/routes/chrome/http/screenshot.post.d.ts +2 -1
  58. package/build/routes/chrome/http/screenshot.post.js +3 -2
  59. package/build/routes/chrome/http/screenshot.post.query.json +6 -69
  60. package/build/routes/chrome/ws/browser.d.ts +2 -1
  61. package/build/routes/chrome/ws/browser.js +3 -2
  62. package/build/routes/chrome/ws/browser.query.json +6 -69
  63. package/build/routes/chrome/ws/cdp.d.ts +2 -1
  64. package/build/routes/chrome/ws/cdp.js +3 -2
  65. package/build/routes/chrome/ws/cdp.query.json +6 -69
  66. package/build/routes/chrome/ws/page.d.ts +3 -2
  67. package/build/routes/chrome/ws/page.js +3 -2
  68. package/build/routes/chrome/ws/page.query.json +6 -69
  69. package/build/routes/chrome/ws/playwright.d.ts +1 -0
  70. package/build/routes/chrome/ws/playwright.js +2 -1
  71. package/build/routes/chrome/ws/playwright.query.json +7 -90
  72. package/build/routes/chromium/http/content.post.body.json +8 -8
  73. package/build/routes/chromium/http/download.post.body.json +11 -489
  74. package/build/routes/chromium/http/download.post.query.json +6 -69
  75. package/build/routes/chromium/http/download.post.response.json +0 -1
  76. package/build/routes/chromium/http/function.post.body.json +11 -489
  77. package/build/routes/chromium/http/function.post.query.json +6 -69
  78. package/build/routes/chromium/http/function.post.response.json +0 -1
  79. package/build/routes/chromium/http/json-list.get.response.json +49 -1
  80. package/build/routes/chromium/http/json-new.put.response.json +41 -1
  81. package/build/routes/chromium/http/json-protocol.get.response.json +3 -1
  82. package/build/routes/chromium/http/json-version.get.response.json +41 -1
  83. package/build/routes/chromium/http/pdf.post.body.json +153 -9
  84. package/build/routes/chromium/http/pdf.post.query.json +6 -69
  85. package/build/routes/chromium/http/performance.post.body.json +10 -494
  86. package/build/routes/chromium/http/performance.post.query.json +6 -69
  87. package/build/routes/chromium/http/performance.post.response.json +3 -1
  88. package/build/routes/chromium/http/scrape.post.body.json +56 -9
  89. package/build/routes/chromium/http/scrape.post.response.json +305 -1
  90. package/build/routes/chromium/http/screenshot.post.body.json +99 -9
  91. package/build/routes/chromium/http/screenshot.post.query.json +6 -69
  92. package/build/routes/chromium/ws/browser.query.json +6 -69
  93. package/build/routes/chromium/ws/cdp.query.json +6 -69
  94. package/build/routes/chromium/ws/page.query.json +6 -69
  95. package/build/routes/chromium/ws/playwright.query.json +7 -90
  96. package/build/routes/firefox/ws/playwright.d.ts +2 -1
  97. package/build/routes/firefox/ws/playwright.js +3 -2
  98. package/build/routes/firefox/ws/playwright.query.json +30 -115
  99. package/build/routes/management/http/config.get.d.ts +1 -0
  100. package/build/routes/management/http/config.get.js +2 -1
  101. package/build/routes/management/http/config.get.response.json +104 -1
  102. package/build/routes/management/http/metrics-total.get.d.ts +1 -0
  103. package/build/routes/management/http/metrics-total.get.js +2 -1
  104. package/build/routes/management/http/metrics-total.get.response.json +69 -1
  105. package/build/routes/management/http/metrics.get.d.ts +1 -0
  106. package/build/routes/management/http/metrics.get.js +2 -1
  107. package/build/routes/management/http/metrics.get.response.json +91 -1
  108. package/build/routes/management/http/sessions.get.d.ts +1 -0
  109. package/build/routes/management/http/sessions.get.js +2 -1
  110. package/build/routes/management/http/sessions.get.response.json +232 -1
  111. package/build/routes/management/http/static.get.d.ts +1 -0
  112. package/build/routes/management/http/static.get.js +2 -1
  113. package/build/routes/webkit/ws/playwright.d.ts +2 -1
  114. package/build/routes/webkit/ws/playwright.js +3 -2
  115. package/build/routes/webkit/ws/playwright.query.json +7 -90
  116. package/build/shared/browser.ws.d.ts +2 -1
  117. package/build/shared/browser.ws.js +3 -2
  118. package/build/shared/chromium.playwright.ws.d.ts +2 -1
  119. package/build/shared/chromium.playwright.ws.js +3 -2
  120. package/build/shared/chromium.ws.d.ts +2 -1
  121. package/build/shared/chromium.ws.js +3 -2
  122. package/build/shared/content.http.d.ts +2 -1
  123. package/build/shared/content.http.js +3 -2
  124. package/build/shared/download.http.d.ts +2 -1
  125. package/build/shared/download.http.js +3 -2
  126. package/build/shared/function.http.d.ts +2 -1
  127. package/build/shared/function.http.js +3 -2
  128. package/build/shared/json-list.http.d.ts +2 -1
  129. package/build/shared/json-list.http.js +3 -2
  130. package/build/shared/json-new.http.d.ts +2 -1
  131. package/build/shared/json-new.http.js +3 -2
  132. package/build/shared/json-protocol.http.d.ts +2 -1
  133. package/build/shared/json-protocol.http.js +3 -2
  134. package/build/shared/json-version.http.d.ts +2 -1
  135. package/build/shared/json-version.http.js +3 -2
  136. package/build/shared/page.ws.d.ts +2 -1
  137. package/build/shared/page.ws.js +3 -2
  138. package/build/shared/pdf.http.d.ts +2 -1
  139. package/build/shared/pdf.http.js +3 -2
  140. package/build/shared/performance.http.d.ts +1 -0
  141. package/build/shared/performance.http.js +2 -1
  142. package/build/shared/scrape.http.d.ts +2 -1
  143. package/build/shared/scrape.http.js +3 -2
  144. package/build/shared/screenshot.http.d.ts +1 -0
  145. package/build/shared/screenshot.http.js +2 -1
  146. package/build/types.d.ts +91 -0
  147. package/build/types.js +54 -0
  148. package/build/utils.d.ts +1 -1
  149. package/build/utils.js +11 -6
  150. package/docker/chrome/Dockerfile +0 -2
  151. package/docker/chromium/Dockerfile +1 -4
  152. package/docker/firefox/Dockerfile +1 -4
  153. package/docker/multi/Dockerfile +2 -6
  154. package/docker/webkit/Dockerfile +1 -4
  155. package/package.json +11 -10
  156. package/scripts/build-open-api.js +150 -141
  157. package/scripts/build-schemas.js +3 -2
  158. package/src/browserless.ts +43 -30
  159. package/src/browsers/chrome.cdp.ts +1 -1
  160. package/src/browsers/chrome.playwright.ts +1 -1
  161. package/src/browsers/index.ts +5 -1
  162. package/src/exports.ts +25 -49
  163. package/src/limiter.ts +7 -3
  164. package/src/routes/chrome/http/content.post.ts +7 -2
  165. package/src/routes/chrome/http/download.post.ts +7 -2
  166. package/src/routes/chrome/http/function.post.ts +7 -2
  167. package/src/routes/chrome/http/json-list.get.ts +7 -1
  168. package/src/routes/chrome/http/json-new.put.ts +7 -1
  169. package/src/routes/chrome/http/json-protocol.get.ts +7 -1
  170. package/src/routes/chrome/http/json-version.get.ts +7 -1
  171. package/src/routes/chrome/http/pdf.post.ts +7 -2
  172. package/src/routes/chrome/http/performance.post.ts +7 -2
  173. package/src/routes/chrome/http/scrape.post.ts +7 -2
  174. package/src/routes/chrome/http/screenshot.post.ts +7 -2
  175. package/src/routes/chrome/ws/browser.ts +3 -2
  176. package/src/routes/chrome/ws/cdp.ts +7 -2
  177. package/src/routes/chrome/ws/page.ts +3 -2
  178. package/src/routes/chrome/ws/playwright.ts +6 -1
  179. package/src/routes/firefox/ws/playwright.ts +3 -1
  180. package/src/routes/management/http/config.get.ts +2 -0
  181. package/src/routes/management/http/metrics-total.get.ts +2 -0
  182. package/src/routes/management/http/metrics.get.ts +2 -0
  183. package/src/routes/management/http/sessions.get.ts +2 -0
  184. package/src/routes/management/http/static.get.ts +2 -0
  185. package/src/routes/webkit/ws/playwright.ts +3 -1
  186. package/src/shared/browser.ws.ts +3 -1
  187. package/src/shared/chromium.playwright.ws.ts +3 -1
  188. package/src/shared/chromium.ws.ts +3 -1
  189. package/src/shared/content.http.ts +3 -1
  190. package/src/shared/download.http.ts +3 -1
  191. package/src/shared/function.http.ts +3 -1
  192. package/src/shared/json-list.http.ts +3 -1
  193. package/src/shared/json-new.http.ts +3 -1
  194. package/src/shared/json-protocol.http.ts +3 -1
  195. package/src/shared/json-version.http.ts +3 -1
  196. package/src/shared/page.ws.ts +3 -1
  197. package/src/shared/pdf.http.ts +3 -1
  198. package/src/shared/performance.http.ts +2 -0
  199. package/src/shared/scrape.http.ts +3 -1
  200. package/src/shared/screenshot.http.ts +2 -0
  201. package/src/types.ts +66 -0
  202. package/src/utils.ts +13 -7
  203. package/static/docs/swagger.json +2511 -1520
  204. package/static/docs/swagger.min.json +6697 -0
  205. package/static/function/client.js +323 -323
  206. package/build/exports.core.d.ts +0 -24
  207. package/build/exports.core.js +0 -26
  208. package/src/exports.core.ts +0 -26
@@ -3,17 +3,21 @@
3
3
  'use strict';
4
4
 
5
5
  import { join, parse } from 'path';
6
- import { Config } from '../build/config.js';
7
6
  import { dirname } from 'path';
8
- import { errorCodes } from '../build/http.js';
9
7
  import { fileURLToPath } from 'url';
10
8
  import fs from 'fs/promises';
11
- import { getRouteFiles } from '../build/utils.js';
12
9
  import { marked } from 'marked';
13
10
 
14
11
  const __dirname = dirname(fileURLToPath(import.meta.url));
15
12
  const moduleMain = import.meta.url.endsWith(process.argv[1]);
16
13
  const swaggerJSONPath = join(__dirname, '..', 'static', 'docs', 'swagger.json');
14
+ const swaggerJSONMinimal = join(
15
+ __dirname,
16
+ '..',
17
+ 'static',
18
+ 'docs',
19
+ 'swagger.min.json',
20
+ );
17
21
  const packageJSONPath = join(__dirname, '..', 'package.json');
18
22
 
19
23
  const readFileOrNull = async (path) => {
@@ -42,17 +46,18 @@ const sortSwaggerRequiredAlpha = (prop, otherProp) => {
42
46
  return Number(otherProp.required) - Number(prop.required);
43
47
  };
44
48
 
45
- const routeIsDisabled = (Route, DisabledRoutes) => {
46
- const stringified = Route.toString();
47
- return DisabledRoutes.some((r) => r.toString() === stringified);
48
- };
49
-
50
49
  const buildOpenAPI = async (
51
50
  externalHTTPRoutes = [],
52
51
  externalWebSocketRoutes = [],
53
- DisabledRoutes = [],
52
+ disabledRoutes = [],
54
53
  ) => {
55
- const packageJSON = await fs.readFile(packageJSONPath);
54
+ const [{ getRouteFiles }, { Config }, { errorCodes }, packageJSON] =
55
+ await Promise.all([
56
+ import('../build/utils.js'),
57
+ import('../build/config.js'),
58
+ import('../build/http.js'),
59
+ fs.readFile(packageJSONPath),
60
+ ]);
56
61
 
57
62
  const isWin = process.platform === 'win32';
58
63
  const readme = (await fs.readFile('README.md').catch(() => '')).toString();
@@ -65,8 +70,6 @@ const buildOpenAPI = async (
65
70
  customSiteTitle: 'Browserless Documentation',
66
71
  definitions: {},
67
72
  info: {
68
- // Concatenation necessary for Changelog to show up in sidebar
69
- description: readme + `\n# Changelog\n` + changelog,
70
73
  title: 'Browserless',
71
74
  version: JSON.parse(packageJSON.toString()).version,
72
75
  'x-logo': {
@@ -93,14 +96,14 @@ const buildOpenAPI = async (
93
96
  const routeImport = `${isWin ? 'file:///' : ''}${routeModule}`;
94
97
  const { default: Route } = await import(routeImport);
95
98
  if (!Route) {
96
- throw new Error(
97
- `Invalid route file found while building OpenAPI JSON: "${routeModule}"`,
98
- );
99
+ throw new Error(`Invalid route file to import docs ${routeModule}`);
99
100
  }
100
- if (routeIsDisabled(Route, DisabledRoutes)) {
101
+ const route = new Route();
102
+
103
+ if (disabledRoutes.includes(route.name)) {
101
104
  return null;
102
105
  }
103
- const route = new Route();
106
+
104
107
  const { name } = parse(routeModule);
105
108
  const body = routeModule.replace('.js', '.body.json');
106
109
  const query = routeModule.replace('.js', '.query.json');
@@ -108,7 +111,7 @@ const buildOpenAPI = async (
108
111
  const isWebSocket = routeModule.includes('/ws/') || name.endsWith('ws');
109
112
  const path = Array.isArray(route.path)
110
113
  ? route.path.join(' ')
111
- : [route.path];
114
+ : route.path;
112
115
  const {
113
116
  tags,
114
117
  description,
@@ -135,149 +138,155 @@ const buildOpenAPI = async (
135
138
  tags,
136
139
  title,
137
140
  };
138
- })
139
- .filter((r) => r !== null),
141
+ }),
140
142
  );
141
143
 
142
- const paths = routeMetaData.reduce((accum, r) => {
143
- const swaggerRoute = {
144
- definitions: {},
145
- description: r.description,
146
- parameters: [],
147
- requestBody: {
148
- content: {},
149
- },
150
- responses: {
151
- ...errorCodes,
152
- },
153
- summary: r.path,
154
- tags: r.tags,
155
- };
144
+ const paths = routeMetaData
145
+ .filter((_) => !!_)
146
+ .reduce((accum, r) => {
147
+ const swaggerRoute = {
148
+ definitions: {},
149
+ description: r.description,
150
+ parameters: [],
151
+ requestBody: {
152
+ content: {},
153
+ },
154
+ responses: {
155
+ ...errorCodes,
156
+ },
157
+ summary: r.path,
158
+ tags: r.tags,
159
+ };
156
160
 
157
- r.method = r.isWebSocket ? 'get' : r.method;
161
+ r.method = r.isWebSocket ? 'get' : r.method;
158
162
 
159
- // Find all the swagger definitions and merge them into the
160
- // definitions object
161
- const allDefs = {
162
- ...(r?.body?.definitions || {}),
163
- ...(r?.query?.definitions || {}),
164
- ...(r?.response?.definitions || {}),
165
- };
163
+ // Find all the swagger definitions and merge them into the
164
+ // definitions object
165
+ const allDefs = {
166
+ ...(r?.body?.definitions || {}),
167
+ ...(r?.query?.definitions || {}),
168
+ ...(r?.response?.definitions || {}),
169
+ };
166
170
 
167
- Object.entries(allDefs).forEach(([defName, definition]) => {
168
- // @ts-ignore
169
- swaggerJSON.definitions[defName] =
171
+ Object.entries(allDefs).forEach(([defName, definition]) => {
170
172
  // @ts-ignore
171
- swaggerJSON.definitions[defName] ?? definition;
172
- });
173
-
174
- if (r.isWebSocket) {
175
- swaggerRoute.responses['101'] = {
176
- description: 'Indicates successful WebSocket upgrade.',
177
- };
178
- }
173
+ swaggerJSON.definitions[defName] =
174
+ // @ts-ignore
175
+ swaggerJSON.definitions[defName] ?? definition;
176
+ });
179
177
 
180
- // Does a best-attempt at configuring multiple response types
181
- // Won't figure out APIs that return mixed response types like
182
- // JSON and binary blobs
183
- if (r.response) {
184
- if (r.contentTypes.length === 1) {
185
- const [type] = r.contentTypes;
186
- swaggerRoute.responses['200'] = {
187
- content: {
188
- [type]: {
189
- schema: r.response,
190
- },
191
- },
192
- description: r.response.description,
178
+ if (r.isWebSocket) {
179
+ swaggerRoute.responses['101'] = {
180
+ description: 'Indicates successful WebSocket upgrade.',
193
181
  };
194
- } else {
195
- const okResponses = r.contentTypes.reduce(
196
- (accum, c) => {
197
- // @ts-ignore
198
- accum.content[c] = {
199
- schema: {
200
- type: 'text',
182
+ }
183
+
184
+ // Does a best-attempt at configuring multiple response types
185
+ // Won't figure out APIs that return mixed response types like
186
+ // JSON and binary blobs
187
+ if (r.response) {
188
+ if (r.contentTypes.length === 1) {
189
+ const [type] = r.contentTypes;
190
+ swaggerRoute.responses['200'] = {
191
+ content: {
192
+ [type]: {
193
+ schema: r.response,
201
194
  },
202
- };
203
- return accum;
204
- },
205
- {
206
- content: {},
195
+ },
207
196
  description: r.response.description,
208
- },
209
- );
210
- swaggerRoute.responses['200'] = okResponses;
197
+ };
198
+ } else {
199
+ const okResponses = r.contentTypes.reduce(
200
+ (accum, c) => {
201
+ // @ts-ignore
202
+ accum.content[c] = {
203
+ schema: {
204
+ type: 'text',
205
+ },
206
+ };
207
+ return accum;
208
+ },
209
+ {
210
+ content: {},
211
+ description: r.response.description,
212
+ },
213
+ );
214
+ swaggerRoute.responses['200'] = okResponses;
215
+ }
211
216
  }
212
- }
213
217
 
214
- // Does a best-attempt at configuring multiple body types and
215
- // ignores the "accepts" properties on routes since we can't
216
- // yet correlate the accepted types to the proper body
217
- if (r.body) {
218
- const { properties, type, anyOf } = r.body;
219
- if (anyOf) {
220
- // @ts-ignore
221
- anyOf.forEach((anyType) => {
222
- if (anyType.type === 'string') {
223
- const type = r.accepts.filter(
224
- // @ts-ignore
225
- (accept) => accept !== 'application/json',
226
- );
227
- swaggerRoute.requestBody.content[type] = {
228
- schema: {
229
- type: 'string',
230
- },
231
- };
232
- }
218
+ // Does a best-attempt at configuring multiple body types and
219
+ // ignores the "accepts" properties on routes since we can't
220
+ // yet correlate the accepted types to the proper body
221
+ if (r.body) {
222
+ const { properties, type, anyOf } = r.body;
223
+ if (anyOf) {
224
+ // @ts-ignore
225
+ anyOf.forEach((anyType) => {
226
+ if (anyType.type === 'string') {
227
+ const type = r.accepts.filter(
228
+ // @ts-ignore
229
+ (accept) => accept !== 'application/json',
230
+ );
231
+ swaggerRoute.requestBody.content[type] = {
232
+ schema: {
233
+ type: 'string',
234
+ },
235
+ };
236
+ }
233
237
 
234
- if (anyType['$ref']) {
235
- swaggerRoute.requestBody.content['application/json'] = {
236
- schema: {
237
- $ref: anyType['$ref'],
238
- },
239
- };
240
- }
241
- });
242
- }
238
+ if (anyType['$ref']) {
239
+ swaggerRoute.requestBody.content['application/json'] = {
240
+ schema: {
241
+ $ref: anyType['$ref'],
242
+ },
243
+ };
244
+ }
245
+ });
246
+ }
243
247
 
244
- // Handle JSON
245
- if (type === 'object') {
246
- swaggerRoute.requestBody.content['application/json'] = {
247
- schema: {
248
- properties,
249
- type: 'object',
250
- },
251
- };
248
+ // Handle JSON
249
+ if (type === 'object') {
250
+ swaggerRoute.requestBody.content['application/json'] = {
251
+ schema: {
252
+ properties,
253
+ type: 'object',
254
+ },
255
+ };
256
+ }
252
257
  }
253
- }
254
258
 
255
- // Queries are easy in comparison, but still have to be iterated
256
- // over and made open-api-able
257
- if (r.query) {
258
- const { properties, required } = r.query;
259
- const props = Object.keys(properties || {});
260
- if (props.length) {
261
- swaggerRoute.parameters = props
262
- .map((prop) => ({
263
- in: 'query',
264
- name: prop,
265
- required: required?.includes(prop),
266
- schema: properties[prop],
267
- }))
268
- .sort(sortSwaggerRequiredAlpha);
259
+ // Queries are easy in comparison, but still have to be iterated
260
+ // over and made open-api-able
261
+ if (r.query) {
262
+ const { properties, required } = r.query;
263
+ const props = Object.keys(properties || {});
264
+ if (props.length) {
265
+ swaggerRoute.parameters = props
266
+ .map((prop) => ({
267
+ in: 'query',
268
+ name: prop,
269
+ required: required?.includes(prop),
270
+ schema: properties[prop],
271
+ }))
272
+ .sort(sortSwaggerRequiredAlpha);
273
+ }
269
274
  }
270
- }
271
275
 
272
- // @ts-ignore
273
- accum[r.path] = accum[r.path] || {};
274
- // @ts-ignore
275
- accum[r.path][r.method] = swaggerRoute;
276
+ // @ts-ignore
277
+ accum[r.path] = accum[r.path] || {};
278
+ // @ts-ignore
279
+ accum[r.path][r.method] = swaggerRoute;
276
280
 
277
- return accum;
278
- }, {});
281
+ return accum;
282
+ }, {});
279
283
  swaggerJSON.paths = paths;
280
- fs.writeFile(swaggerJSONPath, JSON.stringify(swaggerJSON, null, ' '));
284
+ await fs.writeFile(
285
+ swaggerJSONMinimal,
286
+ JSON.stringify(swaggerJSON, null, ' '),
287
+ );
288
+ swaggerJSON.info.description = readme + `\n# Changelog\n` + changelog;
289
+ await fs.writeFile(swaggerJSONPath, JSON.stringify(swaggerJSON, null, ' '));
281
290
  };
282
291
 
283
292
  export default buildOpenAPI;
@@ -2,8 +2,6 @@
2
2
  /* global console, process */
3
3
  'use strict';
4
4
 
5
- import { getRouteFiles, tsExtension } from '../build/utils.js';
6
- import { Config } from '../build/config.js';
7
5
  import TJS from 'typescript-json-schema';
8
6
  import fs from 'fs/promises';
9
7
  import path from 'path';
@@ -14,6 +12,8 @@ const buildSchemas = async (
14
12
  externalHTTPRoutes = [],
15
13
  externalWebSocketRoutes = [],
16
14
  ) => {
15
+ const { getRouteFiles, tsExtension } = await import('../build/utils.js');
16
+
17
17
  const schemas = ['BodySchema', 'QuerySchema', 'ResponseSchema'];
18
18
  const settings = {
19
19
  ignoreErrors: true,
@@ -25,6 +25,7 @@ const buildSchemas = async (
25
25
  await fs.readFile('tsconfig.json', 'utf-8'),
26
26
  );
27
27
 
28
+ const { Config } = await import('../build/config.js');
28
29
  const [httpRoutes, wsRoutes] = await getRouteFiles(new Config());
29
30
 
30
31
  // Depending on if we're parsing an external projects routes,
@@ -36,11 +36,11 @@ type Implements<T> = {
36
36
  new (...args: unknown[]): T;
37
37
  };
38
38
 
39
- type RouteTypes =
40
- | typeof HTTPRoute
41
- | typeof BrowserHTTPRoute
42
- | typeof WebSocketRoute
43
- | typeof BrowserWebsocketRoute;
39
+ type routeInstances =
40
+ | HTTPRoute
41
+ | BrowserHTTPRoute
42
+ | WebSocketRoute
43
+ | BrowserWebsocketRoute;
44
44
 
45
45
  export class Browserless {
46
46
  protected debug: debug.Debugger = createLogger('index');
@@ -54,7 +54,7 @@ export class Browserless {
54
54
  protected token: Token;
55
55
  protected webhooks: WebHooks;
56
56
 
57
- DisabledRoutes: RouteTypes[] = [];
57
+ disabledRouteNames: string[] = [];
58
58
  webSocketRouteFiles: string[] = [];
59
59
  httpRouteFiles: string[] = [];
60
60
  server?: HTTPServer;
@@ -145,13 +145,12 @@ export class Browserless {
145
145
  );
146
146
  };
147
147
 
148
- private routeIsDisabled(Route: RouteTypes) {
149
- const Stringified = Route.toString();
150
- return this.DisabledRoutes.some((r) => r.toString() === Stringified);
148
+ private routeIsDisabled(route: routeInstances) {
149
+ return this.disabledRouteNames.some((name) => name === route.name);
151
150
  }
152
151
 
153
- public disableRoute(Route: RouteTypes) {
154
- this.DisabledRoutes.push(Route);
152
+ public disableRoutes(...routeNames: string[]) {
153
+ this.disabledRouteNames.push(...routeNames);
155
154
  }
156
155
 
157
156
  public addHTTPRoute(httpRouteFilePath: string) {
@@ -220,15 +219,16 @@ export class Browserless {
220
219
  default: Route,
221
220
  }: { default: Implements<HTTPRoute> | Implements<BrowserHTTPRoute> } =
222
221
  await import(routeImport + `?cb=${Date.now()}`);
223
- if (!this.routeIsDisabled(Route)) {
224
- const route = new Route(
225
- this.browserManager,
226
- this.config,
227
- this.fileSystem,
228
- logger,
229
- this.metrics,
230
- this.monitoring,
231
- );
222
+ const route = new Route(
223
+ this.browserManager,
224
+ this.config,
225
+ this.fileSystem,
226
+ logger,
227
+ this.metrics,
228
+ this.monitoring,
229
+ );
230
+
231
+ if (!this.routeIsDisabled(route)) {
232
232
  route.bodySchema = safeParse(bodySchema);
233
233
  route.querySchema = safeParse(querySchema);
234
234
  route.config = () => this.config;
@@ -270,15 +270,16 @@ export class Browserless {
270
270
  | Implements<WebSocketRoute>
271
271
  | Implements<BrowserWebsocketRoute>;
272
272
  } = await import(wsImport + `?cb=${Date.now()}`);
273
- if (!this.routeIsDisabled(Route)) {
274
- const route = new Route(
275
- this.browserManager,
276
- this.config,
277
- this.fileSystem,
278
- logger,
279
- this.metrics,
280
- this.monitoring,
281
- );
273
+ const route = new Route(
274
+ this.browserManager,
275
+ this.config,
276
+ this.fileSystem,
277
+ logger,
278
+ this.metrics,
279
+ this.monitoring,
280
+ );
281
+
282
+ if (!this.routeIsDisabled(route)) {
282
283
  route.querySchema = safeParse(querySchema);
283
284
  route.config = () => this.config;
284
285
  route.metrics = () => this.metrics;
@@ -291,8 +292,9 @@ export class Browserless {
291
292
  }
292
293
  }
293
294
 
295
+ const allRoutes = [...httpRoutes, ...wsRoutes];
294
296
  // Validate that we have the browsers they are asking for
295
- [...httpRoutes, ...wsRoutes].forEach((route) => {
297
+ allRoutes.forEach((route) => {
296
298
  if (
297
299
  'browser' in route &&
298
300
  route.browser &&
@@ -305,6 +307,17 @@ export class Browserless {
305
307
  }
306
308
  });
307
309
 
310
+ const duplicateNamedRoutes = allRoutes
311
+ .filter((e, i, a) => a.findIndex((r) => r.name === e.name) !== i)
312
+ .map((r) => r.name);
313
+
314
+ if (duplicateNamedRoutes.length) {
315
+ this.debug(
316
+ `Found duplicate routing names. Route names must be unique:`,
317
+ duplicateNamedRoutes,
318
+ );
319
+ }
320
+
308
321
  httpRoutes.forEach((r) => this.router.registerHTTPRoute(r));
309
322
  wsRoutes.forEach((r) => this.router.registerWebSocketRoute(r));
310
323
 
@@ -5,6 +5,6 @@ import {
5
5
  import { ChromiumCDP } from './chromium.cdp.js';
6
6
 
7
7
  export class ChromeCDP extends ChromiumCDP {
8
- protected executablePath = chromeExecutablePath;
8
+ protected executablePath = chromeExecutablePath();
9
9
  protected debug = createLogger('browsers:chrome:cdp');
10
10
  }
@@ -5,6 +5,6 @@ import {
5
5
  import { ChromiumPlaywright } from './chromium.playwright.js';
6
6
 
7
7
  export class ChromePlaywright extends ChromiumPlaywright {
8
- protected executablePath = chromeExecutablePath;
8
+ protected executablePath = chromeExecutablePath();
9
9
  protected debug = createLogger('browsers:chrome:playwright');
10
10
  }
@@ -63,6 +63,10 @@ export class BrowserManager {
63
63
  }
64
64
  };
65
65
 
66
+ protected onNewPage = async (req: Request, page: unknown) => {
67
+ await pageHook({ meta: req.parsed, page });
68
+ };
69
+
66
70
  /**
67
71
  * Returns the /json/protocol API contents from Chromium or Chrome, whichever is installed,
68
72
  * and modifies URLs to set them to the appropriate addresses configured.
@@ -466,7 +470,7 @@ export class BrowserManager {
466
470
  await browserHook({ browser, meta: req.parsed });
467
471
 
468
472
  browser.on('newPage', async (page) => {
469
- await pageHook({ meta: req.parsed, page });
473
+ await this.onNewPage(req, page);
470
474
  (router.onNewPage || noop)(req.parsed || '', page);
471
475
  });
472
476
 
package/src/exports.ts CHANGED
@@ -1,49 +1,25 @@
1
- // Core
2
- export * from './exports.core.js';
3
-
4
- // Chrome
5
- export { default as ChromeContentPostRoute } from './routes/chrome/http/content.post.js';
6
- export { default as ChromeDownloadPostRoute } from './routes/chrome/http/download.post.js';
7
- export { default as ChromeFunctionPostRoute } from './routes/chrome/http/function.post.js';
8
- export { default as ChromeJSONListGetRoute } from './routes/chrome/http/json-list.get.js';
9
- export { default as ChromeJSONNewPutRoute } from './routes/chrome/http/json-new.put.js';
10
- export { default as ChromeJSONProtocolGetRoute } from './routes/chrome/http/json-protocol.get.js';
11
- export { default as ChromeJSONVersionGetRoute } from './routes/chrome/http/json-version.get.js';
12
- export { default as ChromePDFPostRoute } from './routes/chrome/http/pdf.post.js';
13
- export { default as ChromePerformancePostRoute } from './routes/chrome/http/performance.post.js';
14
- export { default as ChromeScrapePostRoute } from './routes/chrome/http/scrape.post.js';
15
- export { default as ChromeScreenshotPostRoute } from './routes/chrome/http/screenshot.post.js';
16
- export { default as ChromeBrowserWebSocketRoute } from './routes/chrome/ws/browser.js';
17
- export { default as ChromeCDPWebSocketRoute } from './routes/chrome/ws/cdp.js';
18
- export { default as ChromePageWebSocketRoute } from './routes/chrome/ws/page.js';
19
- export { default as ChromePlaywrightWebSocketRoute } from './routes/chrome/ws/playwright.js';
20
-
21
- // Chromium
22
- export { default as ChromiumContentPostRoute } from './routes/chromium/http/content.post.js';
23
- export { default as ChromiumDownloadPostRoute } from './routes/chromium/http/download.post.js';
24
- export { default as ChromiumFunctionPostRoute } from './routes/chromium/http/function.post.js';
25
- export { default as ChromiumJSONListGetRoute } from './routes/chromium/http/json-list.get.js';
26
- export { default as ChromiumJSONNewPutRoute } from './routes/chromium/http/json-new.put.js';
27
- export { default as ChromiumJSONProtocolGetRoute } from './routes/chromium/http/json-protocol.get.js';
28
- export { default as ChromiumJSONVersionGetRoute } from './routes/chromium/http/json-version.get.js';
29
- export { default as ChromiumPDFPostRoute } from './routes/chromium/http/pdf.post.js';
30
- export { default as ChromiumPerformancePostRoute } from './routes/chromium/http/performance.post.js';
31
- export { default as ChromiumScrapePostRoute } from './routes/chromium/http/scrape.post.js';
32
- export { default as ChromiumScreenshotPostRoute } from './routes/chromium/http/screenshot.post.js';
33
- export { default as ChromiumBrowserWebSocketRoute } from './routes/chromium/ws/browser.js';
34
- export { default as ChromiumCDPWebSocketRoute } from './routes/chromium/ws/cdp.js';
35
- export { default as ChromiumPageWebSocketRoute } from './routes/chromium/ws/page.js';
36
- export { default as ChromiumPlaywrightWebSocketRoute } from './routes/chromium/ws/playwright.js';
37
-
38
- // Firefox
39
- export { default as FirefoxPlaywrightWebSocketRoute } from './routes/firefox/ws/playwright.js';
40
-
41
- // WebKit
42
- export { default as WebKitPlaywrightWebSocketRoute } from './routes/webkit/ws/playwright.js';
43
-
44
- // Management
45
- export { default as ConfigGetRoute } from './routes/management/http/config.get.js';
46
- export { default as MetricsTotalGetRoute } from './routes/management/http/metrics-total.get.js';
47
- export { default as MetricsGetRoute } from './routes/management/http/metrics.get.js';
48
- export { default as SessionsGetGetRoute } from './routes/management/http/sessions.get.js';
49
- export { default as StaticGetRoute } from './routes/management/http/static.get.js';
1
+ // Export all them goods...
2
+ export * from './browserless.js';
3
+ export * from './config.js';
4
+ export * from './constants.js';
5
+ export * from './file-system.js';
6
+ export * from './hooks.js';
7
+ export * from './http.js';
8
+ export * from './limiter.js';
9
+ export * from './metrics.js';
10
+ export * from './mime-types.js';
11
+ export * from './monitoring.js';
12
+ export * from './router.js';
13
+ export * from './server.js';
14
+ export * from './shim.js';
15
+ export * from './token.js';
16
+ export * from './types.js';
17
+ export * from './utils.js';
18
+ export * from './webhooks.js';
19
+ export * from './browsers/index.js';
20
+ export * from './browsers/chrome.cdp.js';
21
+ export * from './browsers/chrome.playwright.js';
22
+ export * from './browsers/chromium.cdp.js';
23
+ export * from './browsers/chromium.playwright.js';
24
+ export * from './browsers/firefox.playwright.js';
25
+ export * from './browsers/webkit.playwright.js';