@browserless.io/browserless 2.3.0-beta-1 → 2.3.0-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/bin/browserless.js +47 -18
- package/bin/scaffold/README.md +50 -0
- package/bin/scaffold/src/hello-world.http.ts +2 -1
- package/build/browserless.d.ts +3 -5
- package/build/browserless.js +17 -11
- package/build/browsers/chrome.cdp.js +1 -1
- package/build/browsers/chrome.playwright.js +1 -1
- package/build/browsers/index.d.ts +1 -0
- package/build/browsers/index.js +4 -1
- package/build/data/classes.json +1 -1
- package/build/data/selectors.json +1 -1
- package/build/exports.d.ts +24 -38
- package/build/exports.js +25 -44
- package/build/limiter.d.ts +2 -1
- package/build/limiter.js +6 -3
- package/build/routes/chrome/http/content.post.body.json +8 -8
- package/build/routes/chrome/http/content.post.d.ts +2 -1
- package/build/routes/chrome/http/content.post.js +3 -2
- package/build/routes/chrome/http/download.post.body.json +11 -489
- package/build/routes/chrome/http/download.post.d.ts +2 -1
- package/build/routes/chrome/http/download.post.js +3 -2
- package/build/routes/chrome/http/download.post.query.json +6 -69
- package/build/routes/chrome/http/download.post.response.json +0 -1
- package/build/routes/chrome/http/function.post.body.json +11 -489
- package/build/routes/chrome/http/function.post.d.ts +2 -1
- package/build/routes/chrome/http/function.post.js +3 -2
- package/build/routes/chrome/http/function.post.query.json +6 -69
- package/build/routes/chrome/http/function.post.response.json +0 -1
- package/build/routes/chrome/http/json-list.get.d.ts +5 -1
- package/build/routes/chrome/http/json-list.get.js +5 -1
- package/build/routes/chrome/http/json-list.get.response.json +49 -1
- package/build/routes/chrome/http/json-new.put.d.ts +5 -1
- package/build/routes/chrome/http/json-new.put.js +5 -1
- package/build/routes/chrome/http/json-new.put.response.json +41 -1
- package/build/routes/chrome/http/json-protocol.get.d.ts +5 -1
- package/build/routes/chrome/http/json-protocol.get.js +5 -1
- package/build/routes/chrome/http/json-protocol.get.response.json +3 -1
- package/build/routes/chrome/http/json-version.get.d.ts +5 -1
- package/build/routes/chrome/http/json-version.get.js +5 -1
- package/build/routes/chrome/http/json-version.get.response.json +41 -1
- package/build/routes/chrome/http/pdf.post.body.json +153 -9
- package/build/routes/chrome/http/pdf.post.d.ts +2 -1
- package/build/routes/chrome/http/pdf.post.js +3 -2
- package/build/routes/chrome/http/pdf.post.query.json +6 -69
- package/build/routes/chrome/http/performance.post.body.json +10 -494
- package/build/routes/chrome/http/performance.post.d.ts +2 -1
- package/build/routes/chrome/http/performance.post.js +3 -2
- package/build/routes/chrome/http/performance.post.query.json +6 -69
- package/build/routes/chrome/http/performance.post.response.json +3 -1
- package/build/routes/chrome/http/scrape.post.body.json +56 -9
- package/build/routes/chrome/http/scrape.post.d.ts +2 -1
- package/build/routes/chrome/http/scrape.post.js +3 -2
- package/build/routes/chrome/http/scrape.post.response.json +305 -1
- package/build/routes/chrome/http/screenshot.post.body.json +99 -9
- package/build/routes/chrome/http/screenshot.post.d.ts +2 -1
- package/build/routes/chrome/http/screenshot.post.js +3 -2
- package/build/routes/chrome/http/screenshot.post.query.json +6 -69
- package/build/routes/chrome/ws/browser.d.ts +2 -1
- package/build/routes/chrome/ws/browser.js +3 -2
- package/build/routes/chrome/ws/browser.query.json +6 -69
- package/build/routes/chrome/ws/cdp.d.ts +2 -1
- package/build/routes/chrome/ws/cdp.js +3 -2
- package/build/routes/chrome/ws/cdp.query.json +6 -69
- package/build/routes/chrome/ws/page.d.ts +3 -2
- package/build/routes/chrome/ws/page.js +3 -2
- package/build/routes/chrome/ws/page.query.json +6 -69
- package/build/routes/chrome/ws/playwright.d.ts +1 -0
- package/build/routes/chrome/ws/playwright.js +2 -1
- package/build/routes/chrome/ws/playwright.query.json +7 -90
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/download.post.body.json +11 -489
- package/build/routes/chromium/http/download.post.query.json +6 -69
- package/build/routes/chromium/http/download.post.response.json +0 -1
- package/build/routes/chromium/http/function.post.body.json +11 -489
- package/build/routes/chromium/http/function.post.query.json +6 -69
- package/build/routes/chromium/http/function.post.response.json +0 -1
- package/build/routes/chromium/http/json-list.get.response.json +49 -1
- package/build/routes/chromium/http/json-new.put.response.json +41 -1
- package/build/routes/chromium/http/json-protocol.get.response.json +3 -1
- package/build/routes/chromium/http/json-version.get.response.json +41 -1
- package/build/routes/chromium/http/pdf.post.body.json +153 -9
- package/build/routes/chromium/http/pdf.post.query.json +6 -69
- package/build/routes/chromium/http/performance.post.body.json +10 -494
- package/build/routes/chromium/http/performance.post.query.json +6 -69
- package/build/routes/chromium/http/performance.post.response.json +3 -1
- package/build/routes/chromium/http/scrape.post.body.json +56 -9
- package/build/routes/chromium/http/scrape.post.response.json +305 -1
- package/build/routes/chromium/http/screenshot.post.body.json +99 -9
- package/build/routes/chromium/http/screenshot.post.query.json +6 -69
- package/build/routes/chromium/ws/browser.query.json +6 -69
- package/build/routes/chromium/ws/cdp.query.json +6 -69
- package/build/routes/chromium/ws/page.query.json +6 -69
- package/build/routes/chromium/ws/playwright.query.json +7 -90
- package/build/routes/firefox/ws/playwright.d.ts +2 -1
- package/build/routes/firefox/ws/playwright.js +3 -2
- package/build/routes/firefox/ws/playwright.query.json +30 -115
- package/build/routes/management/http/config.get.d.ts +1 -0
- package/build/routes/management/http/config.get.js +2 -1
- package/build/routes/management/http/config.get.response.json +104 -1
- package/build/routes/management/http/metrics-total.get.d.ts +1 -0
- package/build/routes/management/http/metrics-total.get.js +2 -1
- package/build/routes/management/http/metrics-total.get.response.json +69 -1
- package/build/routes/management/http/metrics.get.d.ts +1 -0
- package/build/routes/management/http/metrics.get.js +2 -1
- package/build/routes/management/http/metrics.get.response.json +91 -1
- package/build/routes/management/http/sessions.get.d.ts +1 -0
- package/build/routes/management/http/sessions.get.js +2 -1
- package/build/routes/management/http/sessions.get.response.json +232 -1
- package/build/routes/management/http/static.get.d.ts +1 -0
- package/build/routes/management/http/static.get.js +2 -1
- package/build/routes/webkit/ws/playwright.d.ts +2 -1
- package/build/routes/webkit/ws/playwright.js +3 -2
- package/build/routes/webkit/ws/playwright.query.json +7 -90
- package/build/shared/browser.ws.d.ts +2 -1
- package/build/shared/browser.ws.js +3 -2
- package/build/shared/chromium.playwright.ws.d.ts +2 -1
- package/build/shared/chromium.playwright.ws.js +3 -2
- package/build/shared/chromium.ws.d.ts +2 -1
- package/build/shared/chromium.ws.js +3 -2
- package/build/shared/content.http.d.ts +2 -1
- package/build/shared/content.http.js +3 -2
- package/build/shared/download.http.d.ts +2 -1
- package/build/shared/download.http.js +3 -2
- package/build/shared/function.http.d.ts +2 -1
- package/build/shared/function.http.js +3 -2
- package/build/shared/json-list.http.d.ts +2 -1
- package/build/shared/json-list.http.js +3 -2
- package/build/shared/json-new.http.d.ts +2 -1
- package/build/shared/json-new.http.js +3 -2
- package/build/shared/json-protocol.http.d.ts +2 -1
- package/build/shared/json-protocol.http.js +3 -2
- package/build/shared/json-version.http.d.ts +2 -1
- package/build/shared/json-version.http.js +3 -2
- package/build/shared/page.ws.d.ts +2 -1
- package/build/shared/page.ws.js +3 -2
- package/build/shared/pdf.http.d.ts +2 -1
- package/build/shared/pdf.http.js +3 -2
- package/build/shared/performance.http.d.ts +1 -0
- package/build/shared/performance.http.js +2 -1
- package/build/shared/scrape.http.d.ts +2 -1
- package/build/shared/scrape.http.js +3 -2
- package/build/shared/screenshot.http.d.ts +1 -0
- package/build/shared/screenshot.http.js +2 -1
- package/build/types.d.ts +91 -0
- package/build/types.js +54 -0
- package/build/utils.d.ts +1 -1
- package/build/utils.js +11 -6
- package/docker/chrome/Dockerfile +0 -2
- package/docker/chromium/Dockerfile +1 -4
- package/docker/firefox/Dockerfile +1 -4
- package/docker/multi/Dockerfile +2 -6
- package/docker/webkit/Dockerfile +1 -4
- package/package.json +11 -10
- package/scripts/build-open-api.js +150 -141
- package/scripts/build-schemas.js +3 -2
- package/src/browserless.ts +43 -30
- package/src/browsers/chrome.cdp.ts +1 -1
- package/src/browsers/chrome.playwright.ts +1 -1
- package/src/browsers/index.ts +5 -1
- package/src/exports.ts +25 -49
- package/src/limiter.ts +7 -3
- package/src/routes/chrome/http/content.post.ts +7 -2
- package/src/routes/chrome/http/download.post.ts +7 -2
- package/src/routes/chrome/http/function.post.ts +7 -2
- package/src/routes/chrome/http/json-list.get.ts +7 -1
- package/src/routes/chrome/http/json-new.put.ts +7 -1
- package/src/routes/chrome/http/json-protocol.get.ts +7 -1
- package/src/routes/chrome/http/json-version.get.ts +7 -1
- package/src/routes/chrome/http/pdf.post.ts +7 -2
- package/src/routes/chrome/http/performance.post.ts +7 -2
- package/src/routes/chrome/http/scrape.post.ts +7 -2
- package/src/routes/chrome/http/screenshot.post.ts +7 -2
- package/src/routes/chrome/ws/browser.ts +3 -2
- package/src/routes/chrome/ws/cdp.ts +7 -2
- package/src/routes/chrome/ws/page.ts +3 -2
- package/src/routes/chrome/ws/playwright.ts +6 -1
- package/src/routes/firefox/ws/playwright.ts +3 -1
- package/src/routes/management/http/config.get.ts +2 -0
- package/src/routes/management/http/metrics-total.get.ts +2 -0
- package/src/routes/management/http/metrics.get.ts +2 -0
- package/src/routes/management/http/sessions.get.ts +2 -0
- package/src/routes/management/http/static.get.ts +2 -0
- package/src/routes/webkit/ws/playwright.ts +3 -1
- package/src/shared/browser.ws.ts +3 -1
- package/src/shared/chromium.playwright.ws.ts +3 -1
- package/src/shared/chromium.ws.ts +3 -1
- package/src/shared/content.http.ts +3 -1
- package/src/shared/download.http.ts +3 -1
- package/src/shared/function.http.ts +3 -1
- package/src/shared/json-list.http.ts +3 -1
- package/src/shared/json-new.http.ts +3 -1
- package/src/shared/json-protocol.http.ts +3 -1
- package/src/shared/json-version.http.ts +3 -1
- package/src/shared/page.ws.ts +3 -1
- package/src/shared/pdf.http.ts +3 -1
- package/src/shared/performance.http.ts +2 -0
- package/src/shared/scrape.http.ts +3 -1
- package/src/shared/screenshot.http.ts +2 -0
- package/src/types.ts +66 -0
- package/src/utils.ts +13 -7
- package/static/docs/swagger.json +2511 -1520
- package/static/docs/swagger.min.json +6697 -0
- package/static/function/client.js +323 -323
- package/build/exports.core.d.ts +0 -24
- package/build/exports.core.js +0 -26
- 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
|
-
|
|
52
|
+
disabledRoutes = [],
|
|
54
53
|
) => {
|
|
55
|
-
const packageJSON =
|
|
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
|
-
|
|
101
|
+
const route = new Route();
|
|
102
|
+
|
|
103
|
+
if (disabledRoutes.includes(route.name)) {
|
|
101
104
|
return null;
|
|
102
105
|
}
|
|
103
|
-
|
|
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
|
-
:
|
|
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
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
161
|
+
r.method = r.isWebSocket ? 'get' : r.method;
|
|
158
162
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
168
|
-
// @ts-ignore
|
|
169
|
-
swaggerJSON.definitions[defName] =
|
|
171
|
+
Object.entries(allDefs).forEach(([defName, definition]) => {
|
|
170
172
|
// @ts-ignore
|
|
171
|
-
swaggerJSON.definitions[defName]
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
-
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
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
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
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
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
+
// @ts-ignore
|
|
277
|
+
accum[r.path] = accum[r.path] || {};
|
|
278
|
+
// @ts-ignore
|
|
279
|
+
accum[r.path][r.method] = swaggerRoute;
|
|
276
280
|
|
|
277
|
-
|
|
278
|
-
|
|
281
|
+
return accum;
|
|
282
|
+
}, {});
|
|
279
283
|
swaggerJSON.paths = paths;
|
|
280
|
-
fs.writeFile(
|
|
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;
|
package/scripts/build-schemas.js
CHANGED
|
@@ -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,
|
package/src/browserless.ts
CHANGED
|
@@ -36,11 +36,11 @@ type Implements<T> = {
|
|
|
36
36
|
new (...args: unknown[]): T;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
type
|
|
40
|
-
|
|
|
41
|
-
|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
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
|
-
|
|
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(
|
|
149
|
-
|
|
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
|
|
154
|
-
this.
|
|
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
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/browsers/index.ts
CHANGED
|
@@ -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
|
|
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
|
-
//
|
|
2
|
-
export * from './
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
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';
|