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