@browserless.io/browserless 2.25.0-beta-2 → 2.25.1
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/CHANGELOG.md +43 -3
- package/README.md +4 -5
- package/build/browserless.js +3 -1
- package/build/browsers/browsers.cdp.d.ts +3 -0
- package/build/browsers/browsers.cdp.js +4 -1
- package/build/browsers/browsers.playwright.d.ts +4 -0
- package/build/browsers/browsers.playwright.js +11 -2
- package/build/browsers/index.js +4 -3
- package/build/http.d.ts +9 -0
- package/build/http.js +9 -0
- package/build/routes/chrome/http/content.post.body.json +8 -8
- package/build/routes/chrome/http/pdf.post.body.json +8 -8
- package/build/routes/chrome/http/scrape.post.body.json +8 -8
- package/build/routes/chrome/http/screenshot.post.body.json +8 -8
- package/build/routes/chrome/tests/kill-sessions.spec.js +1 -1
- package/build/routes/chromium/http/content.post.body.json +8 -8
- package/build/routes/chromium/http/pdf.post.body.json +8 -8
- package/build/routes/chromium/http/scrape.post.body.json +8 -8
- package/build/routes/chromium/http/screenshot.post.body.json +8 -8
- package/build/routes/chromium/tests/kill-sessions.spec.js +1 -1
- package/build/routes/edge/http/content.post.body.json +579 -0
- package/build/routes/edge/http/content.post.d.ts +8 -0
- package/build/routes/edge/http/content.post.js +7 -0
- package/build/routes/edge/http/content.post.query.json +183 -0
- package/build/routes/edge/http/content.post.response.json +5 -0
- package/build/routes/edge/http/download.post.body.json +32 -0
- package/build/routes/edge/http/download.post.d.ts +8 -0
- package/build/routes/edge/http/download.post.js +7 -0
- package/build/routes/edge/http/download.post.query.json +120 -0
- package/build/routes/edge/http/download.post.response.json +4 -0
- package/build/routes/edge/http/function.post.body.json +32 -0
- package/build/routes/edge/http/function.post.d.ts +8 -0
- package/build/routes/edge/http/function.post.js +7 -0
- package/build/routes/edge/http/function.post.query.json +120 -0
- package/build/routes/edge/http/function.post.response.json +4 -0
- package/build/routes/edge/http/json-list.get.d.ts +5 -0
- package/build/routes/edge/http/json-list.get.js +5 -0
- package/build/routes/edge/http/json-list.get.response.json +52 -0
- package/build/routes/edge/http/json-new.put.d.ts +5 -0
- package/build/routes/edge/http/json-new.put.js +5 -0
- package/build/routes/edge/http/json-new.put.response.json +44 -0
- package/build/routes/edge/http/json-protocol.get.d.ts +5 -0
- package/build/routes/edge/http/json-protocol.get.js +5 -0
- package/build/routes/edge/http/json-protocol.get.response.json +6 -0
- package/build/routes/edge/http/json-version.get.d.ts +5 -0
- package/build/routes/edge/http/json-version.get.js +5 -0
- package/build/routes/edge/http/json-version.get.response.json +44 -0
- package/build/routes/edge/http/pdf.post.body.json +724 -0
- package/build/routes/edge/http/pdf.post.d.ts +8 -0
- package/build/routes/edge/http/pdf.post.js +7 -0
- package/build/routes/edge/http/pdf.post.query.json +120 -0
- package/build/routes/edge/http/pdf.post.response.json +5 -0
- package/build/routes/edge/http/performance.post.body.json +26 -0
- package/build/routes/edge/http/performance.post.d.ts +8 -0
- package/build/routes/edge/http/performance.post.js +7 -0
- package/build/routes/edge/http/performance.post.query.json +120 -0
- package/build/routes/edge/http/performance.post.response.json +7 -0
- package/build/routes/edge/http/scrape.post.body.json +626 -0
- package/build/routes/edge/http/scrape.post.d.ts +8 -0
- package/build/routes/edge/http/scrape.post.js +7 -0
- package/build/routes/edge/http/scrape.post.query.json +183 -0
- package/build/routes/edge/http/scrape.post.response.json +334 -0
- package/build/routes/edge/http/screenshot.post.body.json +669 -0
- package/build/routes/edge/http/screenshot.post.d.ts +8 -0
- package/build/routes/edge/http/screenshot.post.js +7 -0
- package/build/routes/edge/http/screenshot.post.query.json +120 -0
- package/build/routes/edge/http/screenshot.post.response.json +5 -0
- package/build/routes/edge/tests/content.spec.d.ts +1 -0
- package/build/routes/edge/tests/content.spec.js +312 -0
- package/build/routes/edge/tests/download.spec.d.ts +1 -0
- package/build/routes/edge/tests/download.spec.js +67 -0
- package/build/routes/edge/tests/function.spec.d.ts +1 -0
- package/build/routes/edge/tests/function.spec.js +277 -0
- package/build/routes/edge/tests/json-version.spec.d.ts +1 -0
- package/build/routes/edge/tests/json-version.spec.js +37 -0
- package/build/routes/edge/tests/kill-sessions.spec.d.ts +1 -0
- package/build/routes/edge/tests/kill-sessions.spec.js +80 -0
- package/build/routes/edge/tests/page-websocket.spec.d.ts +1 -0
- package/build/routes/edge/tests/page-websocket.spec.js +97 -0
- package/build/routes/edge/tests/pdf.spec.d.ts +1 -0
- package/build/routes/edge/tests/pdf.spec.js +345 -0
- package/build/routes/edge/tests/performance.spec.d.ts +1 -0
- package/build/routes/edge/tests/performance.spec.js +124 -0
- package/build/routes/edge/tests/scrape.spec.d.ts +1 -0
- package/build/routes/edge/tests/scrape.spec.js +354 -0
- package/build/routes/edge/tests/screenshot.spec.d.ts +1 -0
- package/build/routes/edge/tests/screenshot.spec.js +339 -0
- package/build/routes/edge/tests/websocket.spec.d.ts +1 -0
- package/build/routes/edge/tests/websocket.spec.js +384 -0
- package/build/routes/edge/ws/browser.d.ts +7 -0
- package/build/routes/edge/ws/browser.js +6 -0
- package/build/routes/edge/ws/browser.query.json +120 -0
- package/build/routes/edge/ws/cdp.d.ts +8 -0
- package/build/routes/edge/ws/cdp.js +7 -0
- package/build/routes/edge/ws/cdp.query.json +120 -0
- package/build/routes/edge/ws/page.d.ts +8 -0
- package/build/routes/edge/ws/page.js +7 -0
- package/build/routes/edge/ws/page.query.json +120 -0
- package/build/routes/edge/ws/playwright.d.ts +8 -0
- package/build/routes/edge/ws/playwright.js +7 -0
- package/build/routes/edge/ws/playwright.query.json +100 -0
- package/build/routes/firefox/tests/kill-sessions.spec.js +1 -1
- package/build/routes/management/http/meta.get.js +3 -1
- package/build/routes/webkit/tests/kill-sessions.spec.js +1 -1
- package/build/sdk-utils.js +1 -1
- package/build/shared/scrape.http.js +2 -2
- package/build/types.d.ts +32 -0
- package/build/types.js +18 -0
- package/build/utils.d.ts +1 -0
- package/build/utils.js +16 -2
- package/docker/chrome/Dockerfile +14 -14
- package/docker/chromium/Dockerfile +14 -14
- package/docker/edge/.dockerignore +16 -0
- package/docker/edge/Dockerfile +43 -0
- package/docker/firefox/Dockerfile +14 -14
- package/docker/multi/Dockerfile +18 -18
- package/docker/sdk/Dockerfile +10 -0
- package/extensions/ublock/_locales/ar/messages.json +3 -3
- package/extensions/ublock/_locales/bg/messages.json +1 -1
- package/extensions/ublock/_locales/br_FR/messages.json +2 -2
- package/extensions/ublock/_locales/cy/messages.json +11 -11
- package/extensions/ublock/_locales/el/messages.json +2 -2
- package/extensions/ublock/_locales/hu/messages.json +1 -1
- package/extensions/ublock/_locales/id/messages.json +1 -1
- package/extensions/ublock/_locales/lv/messages.json +4 -4
- package/extensions/ublock/_locales/mk/messages.json +130 -130
- package/extensions/ublock/_locales/oc/messages.json +1 -1
- package/extensions/ublock/_locales/pt_BR/messages.json +1 -1
- package/extensions/ublock/_locales/pt_PT/messages.json +2 -2
- package/extensions/ublock/_locales/si/messages.json +100 -100
- package/extensions/ublock/_locales/sr/messages.json +4 -4
- package/extensions/ublock/_locales/vi/messages.json +19 -19
- package/extensions/ublock/_locales/zh_TW/messages.json +28 -28
- package/extensions/ublock/assets/assets.json +33 -29
- package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +2984 -3287
- package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +150 -171
- package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +37 -27
- package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +802 -888
- package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +2355 -2071
- package/extensions/ublock/assets/ublock/badlists.txt +9 -1
- package/extensions/ublock/assets/ublock/badware.min.txt +354 -243
- package/extensions/ublock/assets/ublock/filters.min.txt +5837 -5737
- package/extensions/ublock/assets/ublock/privacy.min.txt +151 -38
- package/extensions/ublock/assets/ublock/quick-fixes.min.txt +83 -127
- package/extensions/ublock/assets/ublock/unbreak.min.txt +66 -50
- package/extensions/ublock/css/codemirror.css +4 -0
- package/extensions/ublock/document-blocked.html +3 -1
- package/extensions/ublock/js/arglist-parser.js +116 -0
- package/extensions/ublock/js/background.js +1 -1
- package/extensions/ublock/js/logger-ui.js +1 -1
- package/extensions/ublock/js/messaging.js +9 -2
- package/extensions/ublock/js/pagestore.js +3 -1
- package/extensions/ublock/js/redirect-engine.js +3 -1
- package/extensions/ublock/{assets/resources/set-attr.js → js/resources/attribute.js} +115 -11
- package/extensions/ublock/js/resources/base.js +38 -0
- package/extensions/ublock/js/resources/cookie.js +419 -0
- package/extensions/ublock/js/resources/href-sanitizer.js +188 -0
- package/extensions/ublock/js/resources/localstorage.js +235 -0
- package/extensions/ublock/js/resources/parse-replace.js +54 -0
- package/extensions/ublock/js/resources/prevent-settimeout.js +236 -0
- package/extensions/ublock/js/resources/proxy-apply.js +109 -0
- package/extensions/ublock/js/resources/replace-argument.js +120 -0
- package/extensions/ublock/{assets → js}/resources/run-at.js +20 -4
- package/extensions/ublock/{assets → js}/resources/safe-self.js +5 -4
- package/extensions/ublock/{assets → js}/resources/scriptlets.js +90 -1589
- package/extensions/ublock/js/resources/set-constant.js +287 -0
- package/extensions/ublock/js/resources/shared.js +44 -0
- package/extensions/ublock/js/resources/spoof-css.js +163 -0
- package/extensions/ublock/js/s14e-serializer.js +2 -1
- package/extensions/ublock/js/scriptlet-filtering-core.js +1 -1
- package/extensions/ublock/js/scriptlet-filtering.js +1 -31
- package/extensions/ublock/js/static-dnr-filtering.js +143 -129
- package/extensions/ublock/js/static-filtering-parser.js +27 -117
- package/extensions/ublock/js/static-net-filtering.js +53 -141
- package/extensions/ublock/js/traffic.js +1 -1
- package/extensions/ublock/js/urlskip.js +166 -0
- package/extensions/ublock/js/vapi-background-ext.js +38 -14
- package/extensions/ublock/manifest.json +1 -1
- package/package.json +22 -22
- package/src/browserless.ts +4 -0
- package/src/browsers/browsers.cdp.ts +5 -0
- package/src/browsers/browsers.playwright.ts +14 -1
- package/src/browsers/index.ts +5 -2
- package/src/http.ts +9 -0
- package/src/routes/chrome/tests/kill-sessions.spec.ts +1 -1
- package/src/routes/chromium/tests/kill-sessions.spec.ts +1 -1
- package/src/routes/edge/http/content.post.ts +20 -0
- package/src/routes/edge/http/download.post.ts +20 -0
- package/src/routes/edge/http/function.post.ts +20 -0
- package/src/routes/edge/http/json-list.get.ts +7 -0
- package/src/routes/edge/http/json-new.put.ts +7 -0
- package/src/routes/edge/http/json-protocol.get.ts +7 -0
- package/src/routes/edge/http/json-version.get.ts +7 -0
- package/src/routes/edge/http/pdf.post.ts +20 -0
- package/src/routes/edge/http/performance.post.ts +20 -0
- package/src/routes/edge/http/scrape.post.ts +20 -0
- package/src/routes/edge/http/screenshot.post.ts +20 -0
- package/src/routes/edge/tests/content.spec.ts +376 -0
- package/src/routes/edge/tests/download.spec.ts +77 -0
- package/src/routes/edge/tests/function.spec.ts +317 -0
- package/src/routes/edge/tests/json-version.spec.ts +52 -0
- package/src/routes/edge/tests/kill-sessions.spec.ts +99 -0
- package/src/routes/edge/tests/page-websocket.spec.ts +129 -0
- package/src/routes/edge/tests/pdf.spec.ts +389 -0
- package/src/routes/edge/tests/performance.spec.ts +155 -0
- package/src/routes/edge/tests/scrape.spec.ts +417 -0
- package/src/routes/edge/tests/screenshot.spec.ts +387 -0
- package/src/routes/edge/tests/websocket.spec.ts +510 -0
- package/src/routes/edge/ws/browser.ts +10 -0
- package/src/routes/edge/ws/cdp.ts +17 -0
- package/src/routes/edge/ws/page.ts +10 -0
- package/src/routes/edge/ws/playwright.ts +17 -0
- package/src/routes/firefox/tests/kill-sessions.spec.ts +1 -1
- package/src/routes/management/http/meta.get.ts +6 -1
- package/src/routes/management/http/static.get.ts +1 -1
- package/src/routes/webkit/tests/kill-sessions.spec.ts +1 -1
- package/src/sdk-utils.ts +1 -1
- package/src/shared/scrape.http.ts +2 -2
- package/src/types.ts +19 -0
- package/src/utils.ts +38 -16
- package/static/docs/swagger.json +2097 -10
- package/static/docs/swagger.min.json +2096 -9
- package/static/function/client.js +141 -253
- package/static/function/index.html +141 -253
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { Browserless, Config, Metrics } from '@browserless.io/browserless';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
describe('/edge/pdf API', function () {
|
|
4
|
+
let browserless;
|
|
5
|
+
const start = ({ config = new Config(), metrics = new Metrics(), } = {}) => {
|
|
6
|
+
browserless = new Browserless({ config, metrics });
|
|
7
|
+
return browserless.start();
|
|
8
|
+
};
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
await browserless.stop();
|
|
11
|
+
});
|
|
12
|
+
it('allows requests', async () => {
|
|
13
|
+
const config = new Config();
|
|
14
|
+
config.setToken('browserless');
|
|
15
|
+
const metrics = new Metrics();
|
|
16
|
+
await start({ config, metrics });
|
|
17
|
+
const body = {
|
|
18
|
+
url: 'https://example.com',
|
|
19
|
+
};
|
|
20
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
21
|
+
body: JSON.stringify(body),
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
method: 'POST',
|
|
26
|
+
}).then(async (res) => {
|
|
27
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
28
|
+
expect(res.headers.get('x-response-code')).to.not.be.undefined;
|
|
29
|
+
expect(res.headers.get('x-response-url')).to.not.be.undefined;
|
|
30
|
+
expect(res.headers.get('x-response-ip')).to.not.be.undefined;
|
|
31
|
+
expect(res.headers.get('x-response-por')).to.not.be.undefined;
|
|
32
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
33
|
+
expect(res.status).to.equal(200);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
it('404s GET requests', async () => {
|
|
37
|
+
const config = new Config();
|
|
38
|
+
config.setToken('browserless');
|
|
39
|
+
const metrics = new Metrics();
|
|
40
|
+
await start({ config, metrics });
|
|
41
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless').then((res) => {
|
|
42
|
+
expect(res.headers.get('content-type')).to.equal('text/plain; charset=UTF-8');
|
|
43
|
+
expect(res.status).not.to.equal(200);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
it('handles `waitForFunction` properties', async () => {
|
|
47
|
+
const config = new Config();
|
|
48
|
+
config.setToken('browserless');
|
|
49
|
+
const metrics = new Metrics();
|
|
50
|
+
await start({ config, metrics });
|
|
51
|
+
const body = {
|
|
52
|
+
url: 'https://example.com',
|
|
53
|
+
waitForFunction: {
|
|
54
|
+
fn: '() => 5 + 5',
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
58
|
+
body: JSON.stringify(body),
|
|
59
|
+
headers: {
|
|
60
|
+
'content-type': 'application/json',
|
|
61
|
+
},
|
|
62
|
+
method: 'POST',
|
|
63
|
+
}).then(async (res) => {
|
|
64
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
65
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
66
|
+
expect(res.status).to.equal(200);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
it('handles async `waitForFunction` properties', async () => {
|
|
70
|
+
const config = new Config();
|
|
71
|
+
config.setToken('browserless');
|
|
72
|
+
const metrics = new Metrics();
|
|
73
|
+
await start({ config, metrics });
|
|
74
|
+
const body = {
|
|
75
|
+
url: 'https://example.com',
|
|
76
|
+
waitForFunction: {
|
|
77
|
+
fn: 'async () => new Promise(resolve => resolve(5))',
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
81
|
+
body: JSON.stringify(body),
|
|
82
|
+
headers: {
|
|
83
|
+
'content-type': 'application/json',
|
|
84
|
+
},
|
|
85
|
+
method: 'POST',
|
|
86
|
+
}).then(async (res) => {
|
|
87
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
88
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
89
|
+
expect(res.status).to.equal(200);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
it('handles `waitForSelector` properties', async () => {
|
|
93
|
+
const config = new Config();
|
|
94
|
+
config.setToken('browserless');
|
|
95
|
+
const metrics = new Metrics();
|
|
96
|
+
await start({ config, metrics });
|
|
97
|
+
const body = {
|
|
98
|
+
url: 'https://example.com',
|
|
99
|
+
waitForSelector: {
|
|
100
|
+
selector: 'h1',
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
104
|
+
body: JSON.stringify(body),
|
|
105
|
+
headers: {
|
|
106
|
+
'content-type': 'application/json',
|
|
107
|
+
},
|
|
108
|
+
method: 'POST',
|
|
109
|
+
}).then(async (res) => {
|
|
110
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
111
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
112
|
+
expect(res.status).to.equal(200);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
it('handles `waitForEvent` properties', async () => {
|
|
116
|
+
const config = new Config();
|
|
117
|
+
config.setToken('browserless');
|
|
118
|
+
const metrics = new Metrics();
|
|
119
|
+
await start({ config, metrics });
|
|
120
|
+
const body = {
|
|
121
|
+
html: `<script type="text/javascript">
|
|
122
|
+
const event = new Event("customEvent");
|
|
123
|
+
setTimeout(() => document.dispatchEvent(event), 1500);
|
|
124
|
+
</script>`,
|
|
125
|
+
waitForEvent: {
|
|
126
|
+
event: 'customEvent',
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
130
|
+
body: JSON.stringify(body),
|
|
131
|
+
headers: {
|
|
132
|
+
'content-type': 'application/json',
|
|
133
|
+
},
|
|
134
|
+
method: 'POST',
|
|
135
|
+
}).then(async (res) => {
|
|
136
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
137
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
138
|
+
expect(res.status).to.equal(200);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
it('allows cookies', async () => {
|
|
142
|
+
const config = new Config();
|
|
143
|
+
config.setToken('browserless');
|
|
144
|
+
const metrics = new Metrics();
|
|
145
|
+
await start({ config, metrics });
|
|
146
|
+
const body = {
|
|
147
|
+
cookies: [{ domain: 'example.com', name: 'foo', value: 'bar' }],
|
|
148
|
+
url: 'https://example.com',
|
|
149
|
+
};
|
|
150
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
151
|
+
body: JSON.stringify(body),
|
|
152
|
+
headers: {
|
|
153
|
+
'content-type': 'application/json',
|
|
154
|
+
},
|
|
155
|
+
method: 'POST',
|
|
156
|
+
}).then(async (res) => {
|
|
157
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
158
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
159
|
+
expect(res.status).to.equal(200);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
it('times out requests', async () => {
|
|
163
|
+
const config = new Config();
|
|
164
|
+
config.setToken('browserless');
|
|
165
|
+
const metrics = new Metrics();
|
|
166
|
+
await start({ config, metrics });
|
|
167
|
+
const body = {
|
|
168
|
+
url: 'https://example.com',
|
|
169
|
+
};
|
|
170
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless&timeout=10', {
|
|
171
|
+
body: JSON.stringify(body),
|
|
172
|
+
headers: {
|
|
173
|
+
'content-type': 'application/json',
|
|
174
|
+
},
|
|
175
|
+
method: 'POST',
|
|
176
|
+
}).then((res) => {
|
|
177
|
+
expect(res.status).to.equal(408);
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
it('rejects requests', async () => {
|
|
181
|
+
const config = new Config();
|
|
182
|
+
const metrics = new Metrics();
|
|
183
|
+
config.setConcurrent(0);
|
|
184
|
+
config.setQueued(0);
|
|
185
|
+
config.setToken('browserless');
|
|
186
|
+
await start({ config, metrics });
|
|
187
|
+
const body = {
|
|
188
|
+
url: 'https://example.com',
|
|
189
|
+
};
|
|
190
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
191
|
+
body: JSON.stringify(body),
|
|
192
|
+
headers: {
|
|
193
|
+
'content-type': 'application/json',
|
|
194
|
+
},
|
|
195
|
+
method: 'POST',
|
|
196
|
+
}).then((res) => {
|
|
197
|
+
expect(res.status).to.equal(429);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
it('allows for providing http response payloads', async () => {
|
|
201
|
+
const config = new Config();
|
|
202
|
+
const metrics = new Metrics();
|
|
203
|
+
config.setConcurrent(10);
|
|
204
|
+
config.setQueued(10);
|
|
205
|
+
config.setTimeout(30000);
|
|
206
|
+
config.setToken('browserless');
|
|
207
|
+
await start({ config, metrics });
|
|
208
|
+
const body = {
|
|
209
|
+
requestInterceptors: [
|
|
210
|
+
{
|
|
211
|
+
pattern: '.*data.json',
|
|
212
|
+
response: {
|
|
213
|
+
body: '{"data": 123}',
|
|
214
|
+
contentType: 'application/json',
|
|
215
|
+
status: 200,
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
url: 'https://example.com',
|
|
220
|
+
};
|
|
221
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
222
|
+
body: JSON.stringify(body),
|
|
223
|
+
headers: {
|
|
224
|
+
'content-type': 'application/json',
|
|
225
|
+
},
|
|
226
|
+
method: 'POST',
|
|
227
|
+
}).then(async (res) => {
|
|
228
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
229
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
230
|
+
expect(res.status).to.equal(200);
|
|
231
|
+
});
|
|
232
|
+
});
|
|
233
|
+
it('allows setting goto options', async () => {
|
|
234
|
+
const config = new Config();
|
|
235
|
+
config.setToken('browserless');
|
|
236
|
+
const metrics = new Metrics();
|
|
237
|
+
await start({ config, metrics });
|
|
238
|
+
const body = {
|
|
239
|
+
gotoOptions: {
|
|
240
|
+
waitUntil: `networkidle2`,
|
|
241
|
+
},
|
|
242
|
+
url: 'https://example.com',
|
|
243
|
+
};
|
|
244
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
245
|
+
body: JSON.stringify(body),
|
|
246
|
+
headers: {
|
|
247
|
+
'content-type': 'application/json',
|
|
248
|
+
},
|
|
249
|
+
method: 'POST',
|
|
250
|
+
}).then(async (res) => {
|
|
251
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
252
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
253
|
+
expect(res.status).to.equal(200);
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
it('allows setting HTML body', async () => {
|
|
257
|
+
const config = new Config();
|
|
258
|
+
config.setToken('browserless');
|
|
259
|
+
const metrics = new Metrics();
|
|
260
|
+
await start({ config, metrics });
|
|
261
|
+
const body = {
|
|
262
|
+
html: '<h1>Hello!</h1>',
|
|
263
|
+
};
|
|
264
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
265
|
+
body: JSON.stringify(body),
|
|
266
|
+
headers: {
|
|
267
|
+
'content-type': 'application/json',
|
|
268
|
+
},
|
|
269
|
+
method: 'POST',
|
|
270
|
+
}).then(async (res) => {
|
|
271
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
272
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
273
|
+
expect(res.status).to.equal(200);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
it('allows setting PDF options', async () => {
|
|
277
|
+
const config = new Config();
|
|
278
|
+
config.setToken('browserless');
|
|
279
|
+
const metrics = new Metrics();
|
|
280
|
+
await start({ config, metrics });
|
|
281
|
+
const body = {
|
|
282
|
+
options: {
|
|
283
|
+
landscape: true,
|
|
284
|
+
},
|
|
285
|
+
url: 'https://example.com',
|
|
286
|
+
};
|
|
287
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
288
|
+
body: JSON.stringify(body),
|
|
289
|
+
headers: {
|
|
290
|
+
'content-type': 'application/json',
|
|
291
|
+
},
|
|
292
|
+
method: 'POST',
|
|
293
|
+
}).then(async (res) => {
|
|
294
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
295
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
296
|
+
expect(res.status).to.equal(200);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
it('allows custom viewports', async () => {
|
|
300
|
+
const config = new Config();
|
|
301
|
+
config.setToken('browserless');
|
|
302
|
+
const metrics = new Metrics();
|
|
303
|
+
await start({ config, metrics });
|
|
304
|
+
const body = {
|
|
305
|
+
url: 'https://example.com',
|
|
306
|
+
viewport: {
|
|
307
|
+
deviceScaleFactor: 3,
|
|
308
|
+
height: 100,
|
|
309
|
+
width: 100,
|
|
310
|
+
},
|
|
311
|
+
};
|
|
312
|
+
await fetch('http://localhost:3000/edge/pdf?token=browserless', {
|
|
313
|
+
body: JSON.stringify(body),
|
|
314
|
+
headers: {
|
|
315
|
+
'content-type': 'application/json',
|
|
316
|
+
},
|
|
317
|
+
method: 'POST',
|
|
318
|
+
}).then(async (res) => {
|
|
319
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
320
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
321
|
+
expect(res.status).to.equal(200);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
it('allows requests without token when auth token is not set', async () => {
|
|
325
|
+
await start();
|
|
326
|
+
const body = {
|
|
327
|
+
url: 'https://example.com',
|
|
328
|
+
};
|
|
329
|
+
await fetch('http://localhost:3000/edge/pdf', {
|
|
330
|
+
body: JSON.stringify(body),
|
|
331
|
+
headers: {
|
|
332
|
+
'content-type': 'application/json',
|
|
333
|
+
},
|
|
334
|
+
method: 'POST',
|
|
335
|
+
}).then(async (res) => {
|
|
336
|
+
await res.body?.pipeTo(new WritableStream({}));
|
|
337
|
+
expect(res.headers.get('x-response-code')).to.not.be.undefined;
|
|
338
|
+
expect(res.headers.get('x-response-url')).to.not.be.undefined;
|
|
339
|
+
expect(res.headers.get('x-response-ip')).to.not.be.undefined;
|
|
340
|
+
expect(res.headers.get('x-response-por')).to.not.be.undefined;
|
|
341
|
+
expect(res.headers.get('content-type')).to.equal('application/pdf');
|
|
342
|
+
expect(res.status).to.equal(200);
|
|
343
|
+
});
|
|
344
|
+
});
|
|
345
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Browserless, Config, Metrics } from '@browserless.io/browserless';
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
describe('/edge/performance API', function () {
|
|
4
|
+
let browserless;
|
|
5
|
+
const start = ({ config = new Config(), metrics = new Metrics(), } = {}) => {
|
|
6
|
+
browserless = new Browserless({ config, metrics });
|
|
7
|
+
return browserless.start();
|
|
8
|
+
};
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
await browserless.stop();
|
|
11
|
+
});
|
|
12
|
+
it('allows requests', async () => {
|
|
13
|
+
const config = new Config();
|
|
14
|
+
config.setToken('browserless');
|
|
15
|
+
const metrics = new Metrics();
|
|
16
|
+
await start({ config, metrics });
|
|
17
|
+
const body = {
|
|
18
|
+
url: 'https://example.com',
|
|
19
|
+
};
|
|
20
|
+
await fetch('http://localhost:3000/edge/performance?token=browserless', {
|
|
21
|
+
body: JSON.stringify(body),
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/json',
|
|
24
|
+
},
|
|
25
|
+
method: 'POST',
|
|
26
|
+
}).then((res) => {
|
|
27
|
+
expect(res.headers.get('content-type')).to.equal('application/json; charset=UTF-8');
|
|
28
|
+
expect(res.status).to.equal(200);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
it('404s GET requests', async () => {
|
|
32
|
+
const config = new Config();
|
|
33
|
+
config.setToken('browserless');
|
|
34
|
+
const metrics = new Metrics();
|
|
35
|
+
await start({ config, metrics });
|
|
36
|
+
await fetch('http://localhost:3000/edge/performance?token=browserless').then((res) => {
|
|
37
|
+
expect(res.headers.get('content-type')).to.equal('text/plain; charset=UTF-8');
|
|
38
|
+
expect(res.status).not.to.equal(200);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
it('allows setting config', async () => {
|
|
42
|
+
const config = new Config();
|
|
43
|
+
config.setToken('browserless');
|
|
44
|
+
const metrics = new Metrics();
|
|
45
|
+
await start({ config, metrics });
|
|
46
|
+
const body = {
|
|
47
|
+
config: {
|
|
48
|
+
extends: 'lighthouse:default',
|
|
49
|
+
settings: {
|
|
50
|
+
onlyAudits: ['unminified-css'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
url: 'https://browserless.io',
|
|
54
|
+
};
|
|
55
|
+
await fetch('http://localhost:3000/edge/performance?token=browserless', {
|
|
56
|
+
body: JSON.stringify(body),
|
|
57
|
+
headers: {
|
|
58
|
+
'content-type': 'application/json',
|
|
59
|
+
},
|
|
60
|
+
method: 'POST',
|
|
61
|
+
}).then(async (res) => {
|
|
62
|
+
expect(res.headers.get('content-type')).to.equal('application/json; charset=UTF-8');
|
|
63
|
+
expect(res.status).to.equal(200);
|
|
64
|
+
const json = await res.json();
|
|
65
|
+
expect(json).to.have.property('data');
|
|
66
|
+
expect(json.data.audits).to.have.all.keys('unminified-css');
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
it('times out request', async () => {
|
|
70
|
+
const config = new Config();
|
|
71
|
+
config.setTimeout(10);
|
|
72
|
+
config.setToken('browserless');
|
|
73
|
+
const metrics = new Metrics();
|
|
74
|
+
await start({ config, metrics });
|
|
75
|
+
const body = {
|
|
76
|
+
url: 'https://example.com',
|
|
77
|
+
};
|
|
78
|
+
await fetch('http://localhost:3000/edge/performance?token=browserless', {
|
|
79
|
+
body: JSON.stringify(body),
|
|
80
|
+
headers: {
|
|
81
|
+
'content-type': 'application/json',
|
|
82
|
+
},
|
|
83
|
+
method: 'POST',
|
|
84
|
+
}).then((res) => {
|
|
85
|
+
expect(res.status).to.equal(408);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
it('rejects requests', async () => {
|
|
89
|
+
const config = new Config();
|
|
90
|
+
const metrics = new Metrics();
|
|
91
|
+
config.setConcurrent(0);
|
|
92
|
+
config.setQueued(0);
|
|
93
|
+
config.setToken('browserless');
|
|
94
|
+
await start({ config, metrics });
|
|
95
|
+
const body = {
|
|
96
|
+
url: 'https://example.com',
|
|
97
|
+
};
|
|
98
|
+
await fetch('http://localhost:3000/edge/performance?token=browserless', {
|
|
99
|
+
body: JSON.stringify(body),
|
|
100
|
+
headers: {
|
|
101
|
+
'content-type': 'application/json',
|
|
102
|
+
},
|
|
103
|
+
method: 'POST',
|
|
104
|
+
}).then((res) => {
|
|
105
|
+
expect(res.status).to.equal(429);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
it('allows requests without token when auth token is not set', async () => {
|
|
109
|
+
await start();
|
|
110
|
+
const body = {
|
|
111
|
+
url: 'https://example.com',
|
|
112
|
+
};
|
|
113
|
+
await fetch('http://localhost:3000/edge/performance', {
|
|
114
|
+
body: JSON.stringify(body),
|
|
115
|
+
headers: {
|
|
116
|
+
'content-type': 'application/json',
|
|
117
|
+
},
|
|
118
|
+
method: 'POST',
|
|
119
|
+
}).then((res) => {
|
|
120
|
+
expect(res.headers.get('content-type')).to.equal('application/json; charset=UTF-8');
|
|
121
|
+
expect(res.status).to.equal(200);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|