@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/LICENSE
CHANGED
|
@@ -3,4 +3,6 @@
|
|
|
3
3
|
This work is dual-licensed under the MongoDB Server-Side Public License OR the browserless commercial license.
|
|
4
4
|
You can choose between one of them if you use this work.
|
|
5
5
|
|
|
6
|
+
If you want to use browserless to build commercial sites, applications, or in a continuous-integration system that's closed-source then you'll need to purchase a commercial license. This allows you to keep your software proprietary whilst still using browserless. [You can purchase a commercial license here](https://www.browserless.io/contact).
|
|
7
|
+
|
|
6
8
|
`SPDX-License-Identifier: SSPL-1.0 OR Browserless Commercial License`
|
package/README.md
CHANGED
|
@@ -8,14 +8,14 @@
|
|
|
8
8
|

|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
> [Looking for
|
|
12
|
-
> NOTE: Version 1 is the version we currently still have running on browserless' hosted services.
|
|
11
|
+
> [Looking for v2.x.x of browserless? Check it out here](https://github.com/browserless/browserless).
|
|
12
|
+
> NOTE: Version 1 is the version we currently still have running on browserless' hosted services, we would recommend self-hosted users migrate to v2.
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
Browserless allows remote clients to connect and execute headless work, all inside of docker. It supports the standard, unforked Puppeteer and Playwright libraries, as well offering REST-based APIs for common actions like data collection, PDF generation and more.
|
|
15
15
|
|
|
16
|
-
We
|
|
16
|
+
We take care of common issues such as missing system-fonts, missing external libraries, and performance improvements, along with edge-cases like downloading files and managing sessions. For details, check out the documentation site built into the project which includes Open API docs.
|
|
17
17
|
|
|
18
|
-
If you've been struggling to
|
|
18
|
+
If you've been struggling to deploy headless browsers without running into issues or bloated resource requirements, then Browserless was built for you. Run the browsers in [our cloud](https://browserless.io/) or your own, [free for non-commercial uses](https://github.com/browserless/browserless#licensing).
|
|
19
19
|
# Table of Contents
|
|
20
20
|
|
|
21
21
|
1. [Features](#features)
|
|
@@ -40,14 +40,14 @@ If you've been struggling to get a browser up and running docker, or scaling out
|
|
|
40
40
|
- Fonts and emoji's working out-of-the-box.
|
|
41
41
|
- Debug Viewer for actively viewing/debugging running sessions.
|
|
42
42
|
- An interactive puppeteer debugger, so you can see what the headless browser is doing and use its DevTools.
|
|
43
|
-
- Works with
|
|
43
|
+
- Works with unforked Puppeteer and Playwright.
|
|
44
44
|
- Configurable session timers and health-checks to keep things running smoothly.
|
|
45
45
|
- Error tolerant: if Chrome dies it won't.
|
|
46
46
|
- [Support for running and development on Apple's M1 machines](#building-for-arm64-apple-m1-machines)
|
|
47
47
|
|
|
48
48
|
# How it works
|
|
49
49
|
|
|
50
|
-
|
|
50
|
+
Browserless listens for both incoming websocket requests, generally issued by most libraries, as well as pre-build REST APIs to do common functions (PDF generation, images and so on). When a websocket connects to Browserless it starts Chrome and proxies your request into it. Once the session is done then it closes and awaits for more connections. Some libraries use Chrome's HTTP endpoints, like `/json` to inspect debug-able targets, which Browserless also supports.
|
|
51
51
|
|
|
52
52
|
You still execute the script itself which gives you total control over what library you want to choose and when to do upgrades. This also comes with the benefit of keep your code proprietary and able to run on numerous platforms. We simply take care of all the browser-aspects and offer a management layer on top of the browser.
|
|
53
53
|
|
|
@@ -71,7 +71,7 @@ If you're interested in using this image for commercial aspects, then please rea
|
|
|
71
71
|
|
|
72
72
|
# Puppeteer
|
|
73
73
|
|
|
74
|
-
Puppeteer allows you to specify a remote location for chrome via the `browserWSEndpoint` option. Setting this for
|
|
74
|
+
Puppeteer allows you to specify a remote location for chrome via the `browserWSEndpoint` option. Setting this for Browserless is a single line of code change.
|
|
75
75
|
|
|
76
76
|
**Before**
|
|
77
77
|
```js
|
|
@@ -114,13 +114,13 @@ Running Chrome on lambda or on your own is a fantastic idea but in practice is q
|
|
|
114
114
|
|
|
115
115
|
Getting Chrome running well in docker is also a challenge as there's quiet a few packages you need in order to get Chrome running. Once that's done then there's still missing fonts, getting libraries to work with it, and having limitations on service reliability. This is also ignoring CVEs, access-controls, and scaling strategies.
|
|
116
116
|
|
|
117
|
-
All of these issues prompted us to build a first-class image and workflow for interacting with Chrome in a more streamlined way. With
|
|
117
|
+
All of these issues prompted us to build a first-class image and workflow for interacting with Chrome in a more streamlined way. With Browserless you never have to worry about fonts, extra packages, library support, security, or anything else. It just works reliably like any other modern web service. On top of that it comes with a prescribed approach on how you interact with Chrome, which is through socket connections (similar to a database or any other external appliance). What this means is that you get the ability to drive Chrome remotely without having to do updates/releases to the thing that runs Chrome since it's divorced from your application.
|
|
118
118
|
|
|
119
119
|
# Licensing
|
|
120
120
|
|
|
121
121
|
SPDX-License-Identifier: SSPL-1.0 OR Browserless Commercial License.
|
|
122
122
|
|
|
123
|
-
If you want to use
|
|
123
|
+
If you want to use Browserless to build commercial sites, applications, or in a continuous-integration system that's closed-source then you'll need to purchase a commercial license. This allows you to keep your software proprietary whilst still using browserless. [You can purchase a commercial license here](https://www.browserless.io/contact). A commercial license grants you:
|
|
124
124
|
|
|
125
125
|
- Priority support on issues and features.
|
|
126
126
|
- On-premise running as well as running on public cloud providers for commercial/CI purposes for proprietary systems.
|
|
@@ -129,4 +129,4 @@ If you want to use browserless to build commercial sites, applications, or in a
|
|
|
129
129
|
|
|
130
130
|
Not only does it grant you a license to run such a critical piece of infrastructure, but you are also supporting further innovation in this space and our ability to contribute to it.
|
|
131
131
|
|
|
132
|
-
If you are creating an open source application under a license compatible with the Server Side License 1.0, you may use
|
|
132
|
+
If you are creating an open source application under a license compatible with the Server Side License 1.0, you may use Browserless under those terms.
|
package/bin/browserless.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/* eslint-disable no-undef */
|
|
3
3
|
'use strict';
|
|
4
|
+
process.env.DEBUG = process.env.DEBUG || 'browserless*';
|
|
5
|
+
|
|
6
|
+
import { readFile, writeFile } from 'fs/promises';
|
|
4
7
|
import { Browserless } from '@browserless.io/browserless';
|
|
5
8
|
import buildOpenAPI from '../scripts/build-open-api.js';
|
|
6
9
|
import buildSchemas from '../scripts/build-schemas.js';
|
|
7
10
|
|
|
8
11
|
import { createInterface } from 'readline';
|
|
9
12
|
import debug from 'debug';
|
|
13
|
+
import { dedent } from '../build/utils.js';
|
|
10
14
|
import { fileURLToPath } from 'url';
|
|
11
15
|
import fs from 'fs/promises';
|
|
12
16
|
import path from 'path';
|
|
@@ -17,9 +21,13 @@ const promptLog = debug('browserless:prompt');
|
|
|
17
21
|
|
|
18
22
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
19
23
|
const cmd = process.argv[2];
|
|
24
|
+
const subCMD = process.argv[3];
|
|
20
25
|
const cwd = process.cwd();
|
|
21
|
-
const allowedCMDs = ['build', 'dev', 'docker', 'start'];
|
|
26
|
+
const allowedCMDs = ['build', 'dev', 'docker', 'start', 'create', 'help'];
|
|
22
27
|
const srcDir = path.join(cwd, 'build');
|
|
28
|
+
const packageJSON = readFile(path.join(__dirname, '..', 'package.json')).then(
|
|
29
|
+
(r) => JSON.parse(r.toString()),
|
|
30
|
+
);
|
|
23
31
|
|
|
24
32
|
if (!allowedCMDs.includes(cmd)) {
|
|
25
33
|
throw new Error(
|
|
@@ -60,6 +68,22 @@ const importClassOverride = async (files, className) => {
|
|
|
60
68
|
return (await import(classModuleFullFilePath)).default;
|
|
61
69
|
};
|
|
62
70
|
|
|
71
|
+
const installDependencies = async (workingDirectory) =>
|
|
72
|
+
new Promise((resolve, reject) => {
|
|
73
|
+
spawn('npm', ['i'], {
|
|
74
|
+
cwd: workingDirectory,
|
|
75
|
+
stdio: 'inherit',
|
|
76
|
+
}).once('close', (code) => {
|
|
77
|
+
if (code === 0) {
|
|
78
|
+
log(`Successfully installed Dependencies.`);
|
|
79
|
+
return resolve();
|
|
80
|
+
}
|
|
81
|
+
return reject(
|
|
82
|
+
`Error when installing dependencies, see output for more details`,
|
|
83
|
+
);
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
63
87
|
const buildDockerImage = async (cmd) => {
|
|
64
88
|
new Promise((resolve, reject) => {
|
|
65
89
|
const [docker, ...args] = cmd.split(' ');
|
|
@@ -94,7 +118,7 @@ const buildTypeScript = async () =>
|
|
|
94
118
|
});
|
|
95
119
|
|
|
96
120
|
const getSourceFiles = async () => {
|
|
97
|
-
const files = await fs.readdir(srcDir);
|
|
121
|
+
const files = await fs.readdir(srcDir, { recursive: true });
|
|
98
122
|
const [httpRoutes, webSocketRoutes] = files.reduce(
|
|
99
123
|
([httpRoutes, webSocketRoutes], file) => {
|
|
100
124
|
const parsed = path.parse(file);
|
|
@@ -210,25 +234,25 @@ const start = async (dev = false) => {
|
|
|
210
234
|
|
|
211
235
|
log(`Starting Browserless`);
|
|
212
236
|
|
|
213
|
-
const config = isConstructor(Config) ? new Config() :
|
|
214
|
-
const metrics = isConstructor(Metrics) ? new Metrics() :
|
|
215
|
-
const token = isConstructor(Token) ? new Token(config) :
|
|
216
|
-
const webhooks = isConstructor(Webhooks) ? new Webhooks(config) :
|
|
237
|
+
const config = isConstructor(Config) ? new Config() : Config;
|
|
238
|
+
const metrics = isConstructor(Metrics) ? new Metrics() : Metrics;
|
|
239
|
+
const token = isConstructor(Token) ? new Token(config) : Token;
|
|
240
|
+
const webhooks = isConstructor(Webhooks) ? new Webhooks(config) : Webhooks;
|
|
217
241
|
const browserManager = isConstructor(BrowserManager)
|
|
218
242
|
? new BrowserManager(config)
|
|
219
|
-
:
|
|
243
|
+
: BrowserManager;
|
|
220
244
|
const monitoring = isConstructor(Monitoring)
|
|
221
245
|
? new Monitoring(config)
|
|
222
|
-
:
|
|
246
|
+
: Monitoring;
|
|
223
247
|
const fileSystem = isConstructor(FileSystem)
|
|
224
248
|
? new FileSystem(config)
|
|
225
|
-
:
|
|
249
|
+
: FileSystem;
|
|
226
250
|
const limiter = isConstructor(Limiter)
|
|
227
251
|
? new Limiter(config, metrics, monitoring, webhooks)
|
|
228
|
-
:
|
|
252
|
+
: Limiter;
|
|
229
253
|
const router = isConstructor(Router)
|
|
230
254
|
? new Router(config, browserManager, limiter)
|
|
231
|
-
:
|
|
255
|
+
: Router;
|
|
232
256
|
|
|
233
257
|
const browserless = new Browserless({
|
|
234
258
|
browserManager,
|
|
@@ -350,6 +374,132 @@ const buildDocker = async () => {
|
|
|
350
374
|
}
|
|
351
375
|
};
|
|
352
376
|
|
|
377
|
+
const create = async () => {
|
|
378
|
+
const validNameRegex = /^[a-zA-Z0-9-_]+$/gi;
|
|
379
|
+
const directory = (
|
|
380
|
+
await prompt('What should we name this project (hyphens are ok)?')
|
|
381
|
+
).trim();
|
|
382
|
+
const scaffoldLocation = path.join(__dirname, 'scaffold');
|
|
383
|
+
|
|
384
|
+
if (!directory) {
|
|
385
|
+
throw new Error(`A valid name is required.`);
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const isValidDirectory = validNameRegex.test(directory);
|
|
389
|
+
|
|
390
|
+
if (!isValidDirectory) {
|
|
391
|
+
throw new Error(`Name must not include special characters.`);
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const installPath = path.join(cwd, directory);
|
|
395
|
+
log(`Creating folder "${installPath}"...`);
|
|
396
|
+
await fs.mkdir(installPath);
|
|
397
|
+
|
|
398
|
+
log(`Copying Project Dependencies...`);
|
|
399
|
+
const sdkFiles = await fs.readdir(scaffoldLocation, { recursive: true });
|
|
400
|
+
for (const sdkFile of sdkFiles) {
|
|
401
|
+
const from = path.join(scaffoldLocation, sdkFile);
|
|
402
|
+
const to = path.join(installPath, sdkFile);
|
|
403
|
+
if (sdkFile === 'package.json') {
|
|
404
|
+
const sdkPackageJSONTemplate = (await readFile(from)).toString();
|
|
405
|
+
const { version } = await packageJSON;
|
|
406
|
+
const sdkPackageJSON = sdkPackageJSONTemplate.replace(
|
|
407
|
+
'${BROWSERLESS_VERSION}',
|
|
408
|
+
version,
|
|
409
|
+
);
|
|
410
|
+
await writeFile(to, sdkPackageJSON);
|
|
411
|
+
} else if ((await fs.lstat(from)).isDirectory()) {
|
|
412
|
+
await fs.mkdir(to);
|
|
413
|
+
} else {
|
|
414
|
+
await fs.copyFile(from, to);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
log(`Installing npm modules...`);
|
|
419
|
+
await installDependencies(installPath);
|
|
420
|
+
|
|
421
|
+
log(
|
|
422
|
+
`Done! You can now open "${installPath}" in an editor of your choice. Make sure to check out the README and update the package.json file!`,
|
|
423
|
+
);
|
|
424
|
+
};
|
|
425
|
+
|
|
426
|
+
const help = () => {
|
|
427
|
+
if (subCMD) {
|
|
428
|
+
if (!allowedCMDs.includes(subCMD)) {
|
|
429
|
+
throw new Error(`Unknown command of "${subCMD}" passed.`);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
switch (subCMD) {
|
|
433
|
+
case 'start':
|
|
434
|
+
console.log(dedent`
|
|
435
|
+
Usage: npx @browserless.io/browserless start
|
|
436
|
+
|
|
437
|
+
Description: Starts the HTTP server without building source.
|
|
438
|
+
Useful for restarting a prior build, testing quickly, or
|
|
439
|
+
running without packaging into a docker image.
|
|
440
|
+
`);
|
|
441
|
+
break;
|
|
442
|
+
|
|
443
|
+
case 'dev':
|
|
444
|
+
console.log(dedent`
|
|
445
|
+
Usage: npx @browserless.io/browserless dev
|
|
446
|
+
|
|
447
|
+
Description: Builds the TypeScript files, compiles runtime
|
|
448
|
+
route validation, generates the OpenAPI JSON document,
|
|
449
|
+
and starts the development server at localhost:3000.
|
|
450
|
+
`);
|
|
451
|
+
break;
|
|
452
|
+
|
|
453
|
+
case 'build':
|
|
454
|
+
console.log(dedent`
|
|
455
|
+
Usage: npx @browserless.io/browserless build
|
|
456
|
+
|
|
457
|
+
Description: Builds the TypeScript files, compiles runtime
|
|
458
|
+
route validation, generates the OpenAPI JSON document,
|
|
459
|
+
and exits. Useful for testing full compilation.
|
|
460
|
+
`);
|
|
461
|
+
break;
|
|
462
|
+
|
|
463
|
+
case 'docker':
|
|
464
|
+
console.log(dedent`
|
|
465
|
+
Usage: npx @browserless.io/browserless docker
|
|
466
|
+
|
|
467
|
+
Description: Builds a docker image from source. This command is hybrid
|
|
468
|
+
in that it can be either interactive or use the switches listed below.
|
|
469
|
+
|
|
470
|
+
Options:
|
|
471
|
+
--from The Browserless docker image to extend from (ghcr.io/browserless/multi:latest).
|
|
472
|
+
--action One of "push" or "load" to load or push to a registry.
|
|
473
|
+
--tag The full tag, including version, to name the image (IE: my-bless/chrome:latest).
|
|
474
|
+
--platform A comma-separated list of platforms to build for.
|
|
475
|
+
--proceed Proceed with building the image without prompting.
|
|
476
|
+
`);
|
|
477
|
+
break;
|
|
478
|
+
|
|
479
|
+
case 'create':
|
|
480
|
+
console.log(dedent`
|
|
481
|
+
Usage: npx @browserless.io/browserless create
|
|
482
|
+
|
|
483
|
+
Description: Creates a new project with interactive prompts.
|
|
484
|
+
`);
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
console.log(dedent`
|
|
492
|
+
Usage: npx @browserless.io/browserless [command] [arguments]
|
|
493
|
+
|
|
494
|
+
Options:
|
|
495
|
+
create Creates a new scaffold project, installs dependencies, and exits.
|
|
496
|
+
dev Compiles TypeScript, generates build assets and starts the server.
|
|
497
|
+
build Compiles TypeScript, generates build assets and exits.
|
|
498
|
+
docker Generates a docker image.
|
|
499
|
+
start Starts the http server with already-built assets.
|
|
500
|
+
`);
|
|
501
|
+
};
|
|
502
|
+
|
|
353
503
|
switch (cmd) {
|
|
354
504
|
case 'start':
|
|
355
505
|
start(false);
|
|
@@ -366,4 +516,12 @@ switch (cmd) {
|
|
|
366
516
|
case 'docker':
|
|
367
517
|
buildDocker();
|
|
368
518
|
break;
|
|
519
|
+
|
|
520
|
+
case 'create':
|
|
521
|
+
create();
|
|
522
|
+
break;
|
|
523
|
+
|
|
524
|
+
default:
|
|
525
|
+
help();
|
|
526
|
+
break;
|
|
369
527
|
}
|