@browserless.io/browserless 2.24.3 → 2.25.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/README.md +1 -1
  3. package/build/browserless.js +3 -1
  4. package/build/browsers/browsers.cdp.d.ts +3 -0
  5. package/build/browsers/browsers.cdp.js +4 -1
  6. package/build/browsers/browsers.playwright.d.ts +4 -0
  7. package/build/browsers/browsers.playwright.js +5 -1
  8. package/build/browsers/index.js +3 -2
  9. package/build/http.d.ts +9 -0
  10. package/build/http.js +9 -0
  11. package/build/routes/chrome/http/content.post.body.json +8 -8
  12. package/build/routes/chrome/http/pdf.post.body.json +8 -8
  13. package/build/routes/chrome/http/scrape.post.body.json +8 -8
  14. package/build/routes/chrome/http/screenshot.post.body.json +8 -8
  15. package/build/routes/chrome/tests/kill-sessions.spec.js +1 -1
  16. package/build/routes/chromium/http/content.post.body.json +8 -8
  17. package/build/routes/chromium/http/pdf.post.body.json +8 -8
  18. package/build/routes/chromium/http/scrape.post.body.json +8 -8
  19. package/build/routes/chromium/http/screenshot.post.body.json +8 -8
  20. package/build/routes/chromium/tests/kill-sessions.spec.js +1 -1
  21. package/build/routes/edge/http/content.post.body.json +579 -0
  22. package/build/routes/edge/http/content.post.d.ts +8 -0
  23. package/build/routes/edge/http/content.post.js +7 -0
  24. package/build/routes/edge/http/content.post.query.json +183 -0
  25. package/build/routes/edge/http/content.post.response.json +5 -0
  26. package/build/routes/edge/http/download.post.body.json +32 -0
  27. package/build/routes/edge/http/download.post.d.ts +8 -0
  28. package/build/routes/edge/http/download.post.js +7 -0
  29. package/build/routes/edge/http/download.post.query.json +120 -0
  30. package/build/routes/edge/http/download.post.response.json +4 -0
  31. package/build/routes/edge/http/function.post.body.json +32 -0
  32. package/build/routes/edge/http/function.post.d.ts +8 -0
  33. package/build/routes/edge/http/function.post.js +7 -0
  34. package/build/routes/edge/http/function.post.query.json +120 -0
  35. package/build/routes/edge/http/function.post.response.json +4 -0
  36. package/build/routes/edge/http/json-list.get.d.ts +5 -0
  37. package/build/routes/edge/http/json-list.get.js +5 -0
  38. package/build/routes/edge/http/json-list.get.response.json +52 -0
  39. package/build/routes/edge/http/json-new.put.d.ts +5 -0
  40. package/build/routes/edge/http/json-new.put.js +5 -0
  41. package/build/routes/edge/http/json-new.put.response.json +44 -0
  42. package/build/routes/edge/http/json-protocol.get.d.ts +5 -0
  43. package/build/routes/edge/http/json-protocol.get.js +5 -0
  44. package/build/routes/edge/http/json-protocol.get.response.json +6 -0
  45. package/build/routes/edge/http/json-version.get.d.ts +5 -0
  46. package/build/routes/edge/http/json-version.get.js +5 -0
  47. package/build/routes/edge/http/json-version.get.response.json +44 -0
  48. package/build/routes/edge/http/pdf.post.body.json +724 -0
  49. package/build/routes/edge/http/pdf.post.d.ts +8 -0
  50. package/build/routes/edge/http/pdf.post.js +7 -0
  51. package/build/routes/edge/http/pdf.post.query.json +120 -0
  52. package/build/routes/edge/http/pdf.post.response.json +5 -0
  53. package/build/routes/edge/http/performance.post.body.json +26 -0
  54. package/build/routes/edge/http/performance.post.d.ts +8 -0
  55. package/build/routes/edge/http/performance.post.js +7 -0
  56. package/build/routes/edge/http/performance.post.query.json +120 -0
  57. package/build/routes/edge/http/performance.post.response.json +7 -0
  58. package/build/routes/edge/http/scrape.post.body.json +626 -0
  59. package/build/routes/edge/http/scrape.post.d.ts +8 -0
  60. package/build/routes/edge/http/scrape.post.js +7 -0
  61. package/build/routes/edge/http/scrape.post.query.json +183 -0
  62. package/build/routes/edge/http/scrape.post.response.json +334 -0
  63. package/build/routes/edge/http/screenshot.post.body.json +669 -0
  64. package/build/routes/edge/http/screenshot.post.d.ts +8 -0
  65. package/build/routes/edge/http/screenshot.post.js +7 -0
  66. package/build/routes/edge/http/screenshot.post.query.json +120 -0
  67. package/build/routes/edge/http/screenshot.post.response.json +5 -0
  68. package/build/routes/edge/tests/content.spec.d.ts +1 -0
  69. package/build/routes/edge/tests/content.spec.js +312 -0
  70. package/build/routes/edge/tests/download.spec.d.ts +1 -0
  71. package/build/routes/edge/tests/download.spec.js +67 -0
  72. package/build/routes/edge/tests/function.spec.d.ts +1 -0
  73. package/build/routes/edge/tests/function.spec.js +277 -0
  74. package/build/routes/edge/tests/json-version.spec.d.ts +1 -0
  75. package/build/routes/edge/tests/json-version.spec.js +37 -0
  76. package/build/routes/edge/tests/kill-sessions.spec.d.ts +1 -0
  77. package/build/routes/edge/tests/kill-sessions.spec.js +80 -0
  78. package/build/routes/edge/tests/page-websocket.spec.d.ts +1 -0
  79. package/build/routes/edge/tests/page-websocket.spec.js +97 -0
  80. package/build/routes/edge/tests/pdf.spec.d.ts +1 -0
  81. package/build/routes/edge/tests/pdf.spec.js +345 -0
  82. package/build/routes/edge/tests/performance.spec.d.ts +1 -0
  83. package/build/routes/edge/tests/performance.spec.js +124 -0
  84. package/build/routes/edge/tests/scrape.spec.d.ts +1 -0
  85. package/build/routes/edge/tests/scrape.spec.js +354 -0
  86. package/build/routes/edge/tests/screenshot.spec.d.ts +1 -0
  87. package/build/routes/edge/tests/screenshot.spec.js +339 -0
  88. package/build/routes/edge/tests/websocket.spec.d.ts +1 -0
  89. package/build/routes/edge/tests/websocket.spec.js +384 -0
  90. package/build/routes/edge/ws/browser.d.ts +7 -0
  91. package/build/routes/edge/ws/browser.js +6 -0
  92. package/build/routes/edge/ws/browser.query.json +120 -0
  93. package/build/routes/edge/ws/cdp.d.ts +8 -0
  94. package/build/routes/edge/ws/cdp.js +7 -0
  95. package/build/routes/edge/ws/cdp.query.json +120 -0
  96. package/build/routes/edge/ws/page.d.ts +8 -0
  97. package/build/routes/edge/ws/page.js +7 -0
  98. package/build/routes/edge/ws/page.query.json +120 -0
  99. package/build/routes/edge/ws/playwright.d.ts +8 -0
  100. package/build/routes/edge/ws/playwright.js +7 -0
  101. package/build/routes/edge/ws/playwright.query.json +100 -0
  102. package/build/routes/firefox/tests/kill-sessions.spec.js +1 -1
  103. package/build/routes/webkit/tests/kill-sessions.spec.js +1 -1
  104. package/build/sdk-utils.js +1 -1
  105. package/build/shared/scrape.http.js +2 -2
  106. package/build/types.d.ts +32 -0
  107. package/build/types.js +18 -0
  108. package/build/utils.d.ts +1 -0
  109. package/build/utils.js +16 -2
  110. package/docker/chrome/Dockerfile +14 -14
  111. package/docker/chromium/Dockerfile +14 -14
  112. package/docker/edge/.dockerignore +16 -0
  113. package/docker/edge/Dockerfile +43 -0
  114. package/docker/firefox/Dockerfile +14 -14
  115. package/docker/multi/Dockerfile +18 -18
  116. package/docker/sdk/Dockerfile +10 -0
  117. package/package.json +18 -18
  118. package/src/browserless.ts +4 -0
  119. package/src/browsers/browsers.cdp.ts +5 -0
  120. package/src/browsers/browsers.playwright.ts +6 -0
  121. package/src/browsers/index.ts +4 -1
  122. package/src/http.ts +9 -0
  123. package/src/routes/chrome/tests/kill-sessions.spec.ts +1 -1
  124. package/src/routes/chromium/tests/kill-sessions.spec.ts +1 -1
  125. package/src/routes/edge/http/content.post.ts +20 -0
  126. package/src/routes/edge/http/download.post.ts +20 -0
  127. package/src/routes/edge/http/function.post.ts +20 -0
  128. package/src/routes/edge/http/json-list.get.ts +7 -0
  129. package/src/routes/edge/http/json-new.put.ts +7 -0
  130. package/src/routes/edge/http/json-protocol.get.ts +7 -0
  131. package/src/routes/edge/http/json-version.get.ts +7 -0
  132. package/src/routes/edge/http/pdf.post.ts +20 -0
  133. package/src/routes/edge/http/performance.post.ts +20 -0
  134. package/src/routes/edge/http/scrape.post.ts +20 -0
  135. package/src/routes/edge/http/screenshot.post.ts +20 -0
  136. package/src/routes/edge/tests/content.spec.ts +376 -0
  137. package/src/routes/edge/tests/download.spec.ts +77 -0
  138. package/src/routes/edge/tests/function.spec.ts +317 -0
  139. package/src/routes/edge/tests/json-version.spec.ts +52 -0
  140. package/src/routes/edge/tests/kill-sessions.spec.ts +99 -0
  141. package/src/routes/edge/tests/page-websocket.spec.ts +129 -0
  142. package/src/routes/edge/tests/pdf.spec.ts +389 -0
  143. package/src/routes/edge/tests/performance.spec.ts +155 -0
  144. package/src/routes/edge/tests/scrape.spec.ts +417 -0
  145. package/src/routes/edge/tests/screenshot.spec.ts +387 -0
  146. package/src/routes/edge/tests/websocket.spec.ts +510 -0
  147. package/src/routes/edge/ws/browser.ts +10 -0
  148. package/src/routes/edge/ws/cdp.ts +17 -0
  149. package/src/routes/edge/ws/page.ts +10 -0
  150. package/src/routes/edge/ws/playwright.ts +17 -0
  151. package/src/routes/firefox/tests/kill-sessions.spec.ts +1 -1
  152. package/src/routes/webkit/tests/kill-sessions.spec.ts +1 -1
  153. package/src/sdk-utils.ts +1 -1
  154. package/src/shared/scrape.http.ts +2 -2
  155. package/src/types.ts +19 -0
  156. package/src/utils.ts +38 -16
  157. package/static/docs/swagger.json +2097 -10
  158. package/static/docs/swagger.min.json +2096 -9
  159. package/static/function/client.js +76 -68
  160. package/static/function/index.html +76 -68
@@ -0,0 +1,376 @@
1
+ /* eslint-disable no-unused-expressions */
2
+ import {
3
+ Browserless,
4
+ Config,
5
+ Metrics,
6
+ sleep,
7
+ } from '@browserless.io/browserless';
8
+ import { expect } from 'chai';
9
+
10
+ describe('/edge/content API', function () {
11
+ let browserless: Browserless;
12
+
13
+ const start = ({
14
+ config = new Config(),
15
+ metrics = new Metrics(),
16
+ }: { config?: Config; metrics?: Metrics } = {}) => {
17
+ browserless = new Browserless({ config, metrics });
18
+ return browserless.start();
19
+ };
20
+
21
+ afterEach(async () => {
22
+ await browserless.stop();
23
+ });
24
+
25
+ it('allows requests', async () => {
26
+ const config = new Config();
27
+ config.setToken('browserless');
28
+ const metrics = new Metrics();
29
+ await start({ config, metrics });
30
+ const body = {
31
+ url: 'https://example.com',
32
+ };
33
+
34
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
35
+ body: JSON.stringify(body),
36
+ headers: {
37
+ 'content-type': 'application/json',
38
+ },
39
+ method: 'POST',
40
+ }).then((res) => {
41
+ expect(res.headers.get('x-response-code')).to.not.be.undefined;
42
+ expect(res.headers.get('x-response-url')).to.not.be.undefined;
43
+ expect(res.headers.get('x-response-ip')).to.not.be.undefined;
44
+ expect(res.headers.get('x-response-por')).to.not.be.undefined;
45
+ expect(res.headers.get('content-type')).to.equal(
46
+ 'text/html; charset=UTF-8',
47
+ );
48
+ expect(res.status).to.equal(200);
49
+ });
50
+ });
51
+
52
+ it('cancels request when they are closed early', async () => {
53
+ const config = new Config();
54
+ const metrics = new Metrics();
55
+ await start({ config, metrics });
56
+ const body = {
57
+ url: 'https://cnn.com',
58
+ };
59
+ const controller = new AbortController();
60
+ const signal = controller.signal;
61
+ const promise = fetch('http://localhost:3000/edge/content', {
62
+ body: JSON.stringify(body),
63
+ headers: {
64
+ 'content-type': 'application/json',
65
+ },
66
+ method: 'POST',
67
+ signal,
68
+ }).catch(async (error) => {
69
+ await sleep(100);
70
+ expect(error).to.have.property('name', 'AbortError');
71
+ expect(metrics.get().error).to.equal(1);
72
+ expect(metrics.get().successful).to.equal(0);
73
+ });
74
+ await sleep(1000);
75
+ controller.abort();
76
+ return promise;
77
+ });
78
+
79
+ it('404s GET requests', async () => {
80
+ const config = new Config();
81
+ config.setToken('browserless');
82
+ const metrics = new Metrics();
83
+ await start({ config, metrics });
84
+
85
+ await fetch('http://localhost:3000/edge/content?token=browserless').then(
86
+ (res) => {
87
+ expect(res.headers.get('content-type')).to.equal(
88
+ 'text/plain; charset=UTF-8',
89
+ );
90
+ expect(res.status).not.to.equal(200);
91
+ },
92
+ );
93
+ });
94
+
95
+ it('handles `waitForFunction` properties', async () => {
96
+ const config = new Config();
97
+ config.setToken('browserless');
98
+ const metrics = new Metrics();
99
+ await start({ config, metrics });
100
+ const body = {
101
+ url: 'https://example.com',
102
+ waitForFunction: {
103
+ fn: '() => 5 + 5',
104
+ },
105
+ };
106
+
107
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
108
+ body: JSON.stringify(body),
109
+ headers: {
110
+ 'content-type': 'application/json',
111
+ },
112
+ method: 'POST',
113
+ }).then((res) => {
114
+ expect(res.headers.get('content-type')).to.equal(
115
+ 'text/html; charset=UTF-8',
116
+ );
117
+ expect(res.status).to.equal(200);
118
+ });
119
+ });
120
+
121
+ it('handles async `waitForFunction` properties', async () => {
122
+ const config = new Config();
123
+ config.setToken('browserless');
124
+ const metrics = new Metrics();
125
+ await start({ config, metrics });
126
+ const body = {
127
+ url: 'https://example.com',
128
+ waitForFunction: {
129
+ fn: 'async () => new Promise(resolve => resolve(5))',
130
+ },
131
+ };
132
+
133
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
134
+ body: JSON.stringify(body),
135
+ headers: {
136
+ 'content-type': 'application/json',
137
+ },
138
+ method: 'POST',
139
+ }).then((res) => {
140
+ expect(res.headers.get('content-type')).to.equal(
141
+ 'text/html; charset=UTF-8',
142
+ );
143
+ expect(res.status).to.equal(200);
144
+ });
145
+ });
146
+
147
+ it('handles `waitForSelector` properties', async () => {
148
+ const config = new Config();
149
+ config.setToken('browserless');
150
+ const metrics = new Metrics();
151
+ await start({ config, metrics });
152
+ const body = {
153
+ url: 'https://example.com',
154
+ waitForSelector: {
155
+ selector: 'h1',
156
+ },
157
+ };
158
+
159
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
160
+ body: JSON.stringify(body),
161
+ headers: {
162
+ 'content-type': 'application/json',
163
+ },
164
+ method: 'POST',
165
+ }).then((res) => {
166
+ expect(res.headers.get('content-type')).to.equal(
167
+ 'text/html; charset=UTF-8',
168
+ );
169
+ expect(res.status).to.equal(200);
170
+ });
171
+ });
172
+
173
+ it('handles `waitForTimeout` properties', async () => {
174
+ const config = new Config();
175
+ config.setToken('browserless');
176
+ const metrics = new Metrics();
177
+ await start({ config, metrics });
178
+ const body = {
179
+ url: 'https://example.com',
180
+ waitForTimeout: 500,
181
+ };
182
+
183
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
184
+ body: JSON.stringify(body),
185
+ headers: {
186
+ 'content-type': 'application/json',
187
+ },
188
+ method: 'POST',
189
+ }).then((res) => {
190
+ expect(res.headers.get('content-type')).to.equal(
191
+ 'text/html; charset=UTF-8',
192
+ );
193
+ expect(res.status).to.equal(200);
194
+ });
195
+ });
196
+
197
+ it('handles `waitForEvent` properties', async () => {
198
+ const config = new Config();
199
+ config.setToken('browserless');
200
+ const metrics = new Metrics();
201
+ await start({ config, metrics });
202
+ const body = {
203
+ html: `<script type="text/javascript">
204
+ const event = new Event("customEvent");
205
+ setTimeout(() => document.dispatchEvent(event), 1500);
206
+ </script>`,
207
+ waitForEvent: {
208
+ event: 'customEvent',
209
+ },
210
+ };
211
+
212
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
213
+ body: JSON.stringify(body),
214
+ headers: {
215
+ 'content-type': 'application/json',
216
+ },
217
+ method: 'POST',
218
+ }).then((res) => {
219
+ expect(res.headers.get('content-type')).to.equal(
220
+ 'text/html; charset=UTF-8',
221
+ );
222
+ expect(res.status).to.equal(200);
223
+ });
224
+ });
225
+
226
+ it('allows cookies', async () => {
227
+ const config = new Config();
228
+ config.setToken('browserless');
229
+ const metrics = new Metrics();
230
+ await start({ config, metrics });
231
+ const body = {
232
+ cookies: [{ domain: 'example.com', name: 'foo', value: 'bar' }],
233
+ url: 'https://example.com',
234
+ };
235
+
236
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
237
+ body: JSON.stringify(body),
238
+ headers: {
239
+ 'content-type': 'application/json',
240
+ },
241
+ method: 'POST',
242
+ }).then((res) => {
243
+ expect(res.headers.get('content-type')).to.equal(
244
+ 'text/html; charset=UTF-8',
245
+ );
246
+ expect(res.status).to.equal(200);
247
+ });
248
+ });
249
+
250
+ it('times out requests', async () => {
251
+ const config = new Config();
252
+ config.setToken('browserless');
253
+ const metrics = new Metrics();
254
+ await start({ config, metrics });
255
+ const body = {
256
+ url: 'https://example.com',
257
+ };
258
+
259
+ await fetch(
260
+ 'http://localhost:3000/edge/content?token=browserless&timeout=10',
261
+ {
262
+ body: JSON.stringify(body),
263
+ headers: {
264
+ 'content-type': 'application/json',
265
+ },
266
+ method: 'POST',
267
+ },
268
+ ).then((res) => {
269
+ expect(res.status).to.equal(408);
270
+ });
271
+ });
272
+
273
+ it('rejects requests', async () => {
274
+ const config = new Config();
275
+ config.setConcurrent(0);
276
+ config.setQueued(0);
277
+ config.setToken('browserless');
278
+ const metrics = new Metrics();
279
+ await start({ config, metrics });
280
+
281
+ const body = {
282
+ url: 'https://example.com',
283
+ };
284
+
285
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
286
+ body: JSON.stringify(body),
287
+ headers: {
288
+ 'content-type': 'application/json',
289
+ },
290
+ method: 'POST',
291
+ }).then(async (res) => {
292
+ expect(await res.text()).to.equal('Too many requests\n');
293
+ expect(res.status).to.equal(429);
294
+ });
295
+ });
296
+
297
+ it('allows for providing http response payloads', async () => {
298
+ const config = new Config();
299
+ config.setToken('browserless');
300
+ config.setTimeout(30000);
301
+ const metrics = new Metrics();
302
+ await start({ config, metrics });
303
+
304
+ const body = {
305
+ requestInterceptors: [
306
+ {
307
+ pattern: '.*data.json',
308
+ response: {
309
+ body: '{"data": 123}',
310
+ contentType: 'application/json',
311
+ status: 200,
312
+ },
313
+ },
314
+ ],
315
+ url: 'https://example.com',
316
+ };
317
+
318
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
319
+ body: JSON.stringify(body),
320
+ headers: {
321
+ 'content-type': 'application/json',
322
+ },
323
+ method: 'POST',
324
+ }).then(async (res) => {
325
+ expect(res.status).to.equal(200);
326
+ });
327
+ });
328
+
329
+ it('allows goto options', async () => {
330
+ const config = new Config();
331
+ config.setToken('browserless');
332
+ const metrics = new Metrics();
333
+ await start({ config, metrics });
334
+
335
+ const body = {
336
+ gotoOptions: {
337
+ waitUntil: `networkidle2`,
338
+ },
339
+ url: 'https://example.com',
340
+ };
341
+
342
+ await fetch('http://localhost:3000/edge/content?token=browserless', {
343
+ body: JSON.stringify(body),
344
+ headers: {
345
+ 'content-type': 'application/json',
346
+ },
347
+ method: 'POST',
348
+ }).then(async (res) => {
349
+ expect(res.status).to.equal(200);
350
+ });
351
+ });
352
+
353
+ it('allows requests without token when auth token is not set', async () => {
354
+ await start();
355
+ const body = {
356
+ url: 'https://example.com',
357
+ };
358
+
359
+ await fetch('http://localhost:3000/edge/content', {
360
+ body: JSON.stringify(body),
361
+ headers: {
362
+ 'content-type': 'application/json',
363
+ },
364
+ method: 'POST',
365
+ }).then((res) => {
366
+ expect(res.headers.get('x-response-code')).to.not.be.undefined;
367
+ expect(res.headers.get('x-response-url')).to.not.be.undefined;
368
+ expect(res.headers.get('x-response-ip')).to.not.be.undefined;
369
+ expect(res.headers.get('x-response-por')).to.not.be.undefined;
370
+ expect(res.headers.get('content-type')).to.equal(
371
+ 'text/html; charset=UTF-8',
372
+ );
373
+ expect(res.status).to.equal(200);
374
+ });
375
+ });
376
+ });
@@ -0,0 +1,77 @@
1
+ import { Browserless, Config, Metrics } from '@browserless.io/browserless';
2
+ import { expect } from 'chai';
3
+
4
+ describe('/edge/download API', function () {
5
+ let browserless: Browserless;
6
+
7
+ const start = ({
8
+ config = new Config(),
9
+ metrics = new Metrics(),
10
+ }: { config?: Config; metrics?: Metrics } = {}) => {
11
+ browserless = new Browserless({ config, metrics });
12
+ return browserless.start();
13
+ };
14
+
15
+ afterEach(async () => {
16
+ await browserless.stop();
17
+ });
18
+
19
+ it('allows requests', async () => {
20
+ const config = new Config();
21
+ config.setToken('browserless');
22
+ const metrics = new Metrics();
23
+ await start({ config, metrics });
24
+
25
+ await fetch('http://localhost:3000/edge/download?token=browserless', {
26
+ body: `export default async ({ page }) => {
27
+ await page.evaluate(() => {
28
+ const txtContent = "data:text/plain;charset=utf-8,Hello world!";
29
+ const encodedUri = encodeURI(txtContent);
30
+ const link = document.createElement("a");
31
+ link.setAttribute("href", encodedUri);
32
+ link.setAttribute("download", "data.txt");
33
+ document.body.appendChild(link);
34
+
35
+ link.click();
36
+ });
37
+ await new Promise(r => setTimeout(r, 1000));
38
+ }`,
39
+ headers: {
40
+ 'content-type': 'application/javascript',
41
+ },
42
+ method: 'POST',
43
+ }).then(async (res) => {
44
+ expect(res.status).to.equal(200);
45
+ expect(res.headers.get('content-type')).to.equal('text/plain');
46
+ expect(await res.text()).to.equal('Hello world!');
47
+ });
48
+ });
49
+
50
+ it('allows requests without token when auth token is not set', async () => {
51
+ await start();
52
+
53
+ await fetch('http://localhost:3000/edge/download', {
54
+ body: `export default async ({ page }) => {
55
+ await page.evaluate(() => {
56
+ const txtContent = "data:text/plain;charset=utf-8,Hello world!";
57
+ const encodedUri = encodeURI(txtContent);
58
+ const link = document.createElement("a");
59
+ link.setAttribute("href", encodedUri);
60
+ link.setAttribute("download", "data.txt");
61
+ document.body.appendChild(link);
62
+
63
+ link.click();
64
+ });
65
+ await new Promise(r => setTimeout(r, 1000));
66
+ }`,
67
+ headers: {
68
+ 'content-type': 'application/javascript',
69
+ },
70
+ method: 'POST',
71
+ }).then(async (res) => {
72
+ expect(res.status).to.equal(200);
73
+ expect(res.headers.get('content-type')).to.equal('text/plain');
74
+ expect(await res.text()).to.equal('Hello world!');
75
+ });
76
+ });
77
+ });