@browserless.io/browserless 2.25.0-beta-2 → 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 (224) hide show
  1. package/CHANGELOG.md +39 -3
  2. package/README.md +4 -5
  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 +11 -2
  8. package/build/browsers/index.js +4 -3
  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/management/http/meta.get.js +3 -1
  104. package/build/routes/webkit/tests/kill-sessions.spec.js +1 -1
  105. package/build/sdk-utils.js +1 -1
  106. package/build/shared/scrape.http.js +2 -2
  107. package/build/types.d.ts +32 -0
  108. package/build/types.js +18 -0
  109. package/build/utils.d.ts +1 -0
  110. package/build/utils.js +16 -2
  111. package/docker/chrome/Dockerfile +14 -14
  112. package/docker/chromium/Dockerfile +14 -14
  113. package/docker/edge/.dockerignore +16 -0
  114. package/docker/edge/Dockerfile +43 -0
  115. package/docker/firefox/Dockerfile +14 -14
  116. package/docker/multi/Dockerfile +18 -18
  117. package/docker/sdk/Dockerfile +10 -0
  118. package/extensions/ublock/_locales/ar/messages.json +3 -3
  119. package/extensions/ublock/_locales/bg/messages.json +1 -1
  120. package/extensions/ublock/_locales/br_FR/messages.json +2 -2
  121. package/extensions/ublock/_locales/cy/messages.json +11 -11
  122. package/extensions/ublock/_locales/el/messages.json +2 -2
  123. package/extensions/ublock/_locales/hu/messages.json +1 -1
  124. package/extensions/ublock/_locales/id/messages.json +1 -1
  125. package/extensions/ublock/_locales/lv/messages.json +4 -4
  126. package/extensions/ublock/_locales/mk/messages.json +130 -130
  127. package/extensions/ublock/_locales/oc/messages.json +1 -1
  128. package/extensions/ublock/_locales/pt_BR/messages.json +1 -1
  129. package/extensions/ublock/_locales/pt_PT/messages.json +2 -2
  130. package/extensions/ublock/_locales/si/messages.json +100 -100
  131. package/extensions/ublock/_locales/sr/messages.json +4 -4
  132. package/extensions/ublock/_locales/vi/messages.json +19 -19
  133. package/extensions/ublock/_locales/zh_TW/messages.json +28 -28
  134. package/extensions/ublock/assets/assets.json +33 -29
  135. package/extensions/ublock/assets/thirdparties/easylist/easylist.txt +2984 -3287
  136. package/extensions/ublock/assets/thirdparties/easylist/easyprivacy.txt +150 -171
  137. package/extensions/ublock/assets/thirdparties/pgl.yoyo.org/as/serverlist +37 -27
  138. package/extensions/ublock/assets/thirdparties/publicsuffix.org/list/effective_tld_names.dat +802 -888
  139. package/extensions/ublock/assets/thirdparties/urlhaus-filter/urlhaus-filter-online.txt +2355 -2071
  140. package/extensions/ublock/assets/ublock/badlists.txt +9 -1
  141. package/extensions/ublock/assets/ublock/badware.min.txt +354 -243
  142. package/extensions/ublock/assets/ublock/filters.min.txt +5837 -5737
  143. package/extensions/ublock/assets/ublock/privacy.min.txt +151 -38
  144. package/extensions/ublock/assets/ublock/quick-fixes.min.txt +83 -127
  145. package/extensions/ublock/assets/ublock/unbreak.min.txt +66 -50
  146. package/extensions/ublock/css/codemirror.css +4 -0
  147. package/extensions/ublock/document-blocked.html +3 -1
  148. package/extensions/ublock/js/arglist-parser.js +116 -0
  149. package/extensions/ublock/js/background.js +1 -1
  150. package/extensions/ublock/js/logger-ui.js +1 -1
  151. package/extensions/ublock/js/messaging.js +9 -2
  152. package/extensions/ublock/js/pagestore.js +3 -1
  153. package/extensions/ublock/js/redirect-engine.js +3 -1
  154. package/extensions/ublock/{assets/resources/set-attr.js → js/resources/attribute.js} +115 -11
  155. package/extensions/ublock/js/resources/base.js +38 -0
  156. package/extensions/ublock/js/resources/cookie.js +419 -0
  157. package/extensions/ublock/js/resources/href-sanitizer.js +188 -0
  158. package/extensions/ublock/js/resources/localstorage.js +235 -0
  159. package/extensions/ublock/js/resources/parse-replace.js +54 -0
  160. package/extensions/ublock/js/resources/prevent-settimeout.js +236 -0
  161. package/extensions/ublock/js/resources/proxy-apply.js +109 -0
  162. package/extensions/ublock/js/resources/replace-argument.js +120 -0
  163. package/extensions/ublock/{assets → js}/resources/run-at.js +20 -4
  164. package/extensions/ublock/{assets → js}/resources/safe-self.js +5 -4
  165. package/extensions/ublock/{assets → js}/resources/scriptlets.js +90 -1589
  166. package/extensions/ublock/js/resources/set-constant.js +287 -0
  167. package/extensions/ublock/js/resources/shared.js +44 -0
  168. package/extensions/ublock/js/resources/spoof-css.js +163 -0
  169. package/extensions/ublock/js/s14e-serializer.js +2 -1
  170. package/extensions/ublock/js/scriptlet-filtering-core.js +1 -1
  171. package/extensions/ublock/js/scriptlet-filtering.js +1 -31
  172. package/extensions/ublock/js/static-dnr-filtering.js +143 -129
  173. package/extensions/ublock/js/static-filtering-parser.js +27 -117
  174. package/extensions/ublock/js/static-net-filtering.js +53 -141
  175. package/extensions/ublock/js/traffic.js +1 -1
  176. package/extensions/ublock/js/urlskip.js +166 -0
  177. package/extensions/ublock/js/vapi-background-ext.js +38 -14
  178. package/extensions/ublock/manifest.json +1 -1
  179. package/package.json +22 -22
  180. package/src/browserless.ts +4 -0
  181. package/src/browsers/browsers.cdp.ts +5 -0
  182. package/src/browsers/browsers.playwright.ts +14 -1
  183. package/src/browsers/index.ts +5 -2
  184. package/src/http.ts +9 -0
  185. package/src/routes/chrome/tests/kill-sessions.spec.ts +1 -1
  186. package/src/routes/chromium/tests/kill-sessions.spec.ts +1 -1
  187. package/src/routes/edge/http/content.post.ts +20 -0
  188. package/src/routes/edge/http/download.post.ts +20 -0
  189. package/src/routes/edge/http/function.post.ts +20 -0
  190. package/src/routes/edge/http/json-list.get.ts +7 -0
  191. package/src/routes/edge/http/json-new.put.ts +7 -0
  192. package/src/routes/edge/http/json-protocol.get.ts +7 -0
  193. package/src/routes/edge/http/json-version.get.ts +7 -0
  194. package/src/routes/edge/http/pdf.post.ts +20 -0
  195. package/src/routes/edge/http/performance.post.ts +20 -0
  196. package/src/routes/edge/http/scrape.post.ts +20 -0
  197. package/src/routes/edge/http/screenshot.post.ts +20 -0
  198. package/src/routes/edge/tests/content.spec.ts +376 -0
  199. package/src/routes/edge/tests/download.spec.ts +77 -0
  200. package/src/routes/edge/tests/function.spec.ts +317 -0
  201. package/src/routes/edge/tests/json-version.spec.ts +52 -0
  202. package/src/routes/edge/tests/kill-sessions.spec.ts +99 -0
  203. package/src/routes/edge/tests/page-websocket.spec.ts +129 -0
  204. package/src/routes/edge/tests/pdf.spec.ts +389 -0
  205. package/src/routes/edge/tests/performance.spec.ts +155 -0
  206. package/src/routes/edge/tests/scrape.spec.ts +417 -0
  207. package/src/routes/edge/tests/screenshot.spec.ts +387 -0
  208. package/src/routes/edge/tests/websocket.spec.ts +510 -0
  209. package/src/routes/edge/ws/browser.ts +10 -0
  210. package/src/routes/edge/ws/cdp.ts +17 -0
  211. package/src/routes/edge/ws/page.ts +10 -0
  212. package/src/routes/edge/ws/playwright.ts +17 -0
  213. package/src/routes/firefox/tests/kill-sessions.spec.ts +1 -1
  214. package/src/routes/management/http/meta.get.ts +6 -1
  215. package/src/routes/management/http/static.get.ts +1 -1
  216. package/src/routes/webkit/tests/kill-sessions.spec.ts +1 -1
  217. package/src/sdk-utils.ts +1 -1
  218. package/src/shared/scrape.http.ts +2 -2
  219. package/src/types.ts +19 -0
  220. package/src/utils.ts +38 -16
  221. package/static/docs/swagger.json +2097 -10
  222. package/static/docs/swagger.min.json +2096 -9
  223. package/static/function/client.js +141 -253
  224. package/static/function/index.html +141 -253
@@ -6,6 +6,7 @@ import {
6
6
  Request,
7
7
  ServerError,
8
8
  chromeExecutablePath,
9
+ edgeExecutablePath,
9
10
  } from '@browserless.io/browserless';
10
11
  import playwright, { Page } from 'playwright-core';
11
12
  import { Duplex } from 'stream';
@@ -56,10 +57,17 @@ class BasePlaywright extends EventEmitter {
56
57
  }
57
58
 
58
59
  protected makeLaunchOptions(opts: BrowserServerOptions) {
60
+ // Strip headless=old as it'll cause issues with newer Chromium
61
+ const args = (opts.args ?? []).filter((a) => !a.includes('--headless=old'));
62
+
63
+ if (!args.some((a) => a.startsWith('--headless'))) {
64
+ args.push('--headless=new');
65
+ }
66
+
59
67
  return {
60
68
  ...opts,
61
69
  args: [
62
- ...(opts.args || []),
70
+ ...args,
63
71
  this.userDataDir ? `--user-data-dir=${this.userDataDir}` : '',
64
72
  ],
65
73
  executablePath: this.executablePath(),
@@ -216,6 +224,11 @@ export class ChromePlaywright extends ChromiumPlaywright {
216
224
  protected playwrightBrowserType = PlaywrightBrowserTypes.chromium;
217
225
  }
218
226
 
227
+ export class EdgePlaywright extends ChromiumPlaywright {
228
+ protected executablePath = () => edgeExecutablePath();
229
+ protected playwrightBrowserType = PlaywrightBrowserTypes.chromium;
230
+ }
231
+
219
232
  export class FirefoxPlaywright extends BasePlaywright {
220
233
  protected playwrightBrowserType = PlaywrightBrowserTypes.firefox;
221
234
 
@@ -14,6 +14,8 @@ import {
14
14
  ChromiumCDP,
15
15
  ChromiumPlaywright,
16
16
  Config,
17
+ EdgeCDP,
18
+ EdgePlaywright,
17
19
  FileSystem,
18
20
  FirefoxPlaywright,
19
21
  Hooks,
@@ -41,10 +43,11 @@ export class BrowserManager {
41
43
  protected browsers: Map<BrowserInstance, BrowserlessSession> = new Map();
42
44
  protected timers: Map<string, NodeJS.Timeout> = new Map();
43
45
  protected log = new Logger('browser-manager');
44
- protected chromeBrowsers = [ChromiumCDP, ChromeCDP];
46
+ protected chromeBrowsers = [ChromiumCDP, ChromeCDP, EdgeCDP];
45
47
  protected playwrightBrowserNames = [
46
48
  ChromiumPlaywright.name,
47
49
  ChromePlaywright.name,
50
+ EdgePlaywright.name,
48
51
  FirefoxPlaywright.name,
49
52
  WebKitPlaywright.name,
50
53
  ];
@@ -538,7 +541,7 @@ export class BrowserManager {
538
541
  if (
539
542
  launchOptions.args &&
540
543
  proxyServerArg &&
541
- req.parsed.pathname.startsWith('/playwright')
544
+ req.parsed.pathname.includes('/playwright')
542
545
  ) {
543
546
  (launchOptions as BrowserServerOptions).proxy = {
544
547
  server: proxyServerArg.split('=')[1],
package/src/http.ts CHANGED
@@ -83,7 +83,9 @@ export enum WebsocketRoutes {
83
83
  '/' = '?(/)',
84
84
  browser = '/devtools/browser/*',
85
85
  chrome = '/chrome?(/)',
86
+ edge = '/edge?(/)',
86
87
  chromePlaywright = '/chrome/playwright?(/)',
88
+ edgePlaywright = '/edge/playwright?(/)',
87
89
  chromium = '/chromium?(/)',
88
90
  chromiumPlaywright = '/chromium/playwright?(/)',
89
91
  firefoxPlaywright = '/firefox/playwright?(/)',
@@ -103,6 +105,13 @@ export enum HTTPRoutes {
103
105
  chromePerformance = '/chrome/performance?(/)',
104
106
  chromeScrape = '/chrome/scrape?(/)',
105
107
  chromeScreenshot = '/chrome/screenshot?(/)',
108
+ edgeContent = '/edge/content?(/)',
109
+ edgeDownload = '/edge/download?(/)',
110
+ edgeFunction = '/edge/function?(/)',
111
+ edgePdf = '/edge/pdf?(/)',
112
+ edgePerformance = '/edge/performance?(/)',
113
+ edgeScrape = '/edge/scrape?(/)',
114
+ edgeScreenshot = '/edge/screenshot?(/)',
106
115
  chromiumContent = '/chromium/content?(/)',
107
116
  chromiumDownload = '/chromium/download?(/)',
108
117
  chromiumFunction = '/chromium/function?(/)',
@@ -47,7 +47,7 @@ describe('/kill API', function () {
47
47
  }
48
48
  expect((errorThrown1 as Error).message).contains('closed');
49
49
  expect((errorThrown2 as Error).message).contains('closed');
50
- });
50
+ }).timeout(45000);
51
51
 
52
52
  it('Kill session by browserId', async () => {
53
53
  await start();
@@ -47,7 +47,7 @@ describe('/kill API', function () {
47
47
  }
48
48
  expect((errorThrown1 as Error).message).contains('closed');
49
49
  expect((errorThrown2 as Error).message).contains('closed');
50
- });
50
+ }).timeout(45000);
51
51
 
52
52
  it('Kill session by browserId', async () => {
53
53
  await start();
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ default as Content,
10
+ QuerySchema,
11
+ ResponseSchema,
12
+ } from '../../../shared/content.http.js';
13
+
14
+ export default class EdgeContentPostRoute extends Content {
15
+ name = BrowserlessRoutes.EdgeContentPostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgeContent];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ default as Download,
10
+ QuerySchema,
11
+ ResponseSchema,
12
+ } from '../../../shared/download.http.js';
13
+
14
+ export default class EdgeDownloadPostRoute extends Download {
15
+ name = BrowserlessRoutes.EdgeDownloadPostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgeDownload];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ default as Function,
10
+ QuerySchema,
11
+ ResponseSchema,
12
+ } from '../../../shared/function.http.js';
13
+
14
+ export default class EdgeFunctionPostRoute extends Function {
15
+ name = BrowserlessRoutes.EdgeFunctionPostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgeFunction];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,7 @@
1
+ import { BrowserlessRoutes } from '@browserless.io/browserless';
2
+ import { default as ChromiumJSONListGetRoute } from '../../../shared/json-list.http.js';
3
+ export { ResponseSchema } from '../../../shared/json-list.http.js';
4
+
5
+ export default class EdgeJSONListGetRoute extends ChromiumJSONListGetRoute {
6
+ name = BrowserlessRoutes.EdgeJSONListGetRoute;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { BrowserlessRoutes } from '@browserless.io/browserless';
2
+ import { default as ChromiumJSONNewPutRoute } from '../../../shared/json-new.http.js';
3
+ export { ResponseSchema } from '../../../shared/json-new.http.js';
4
+
5
+ export default class EdgeJSONNewPutRoute extends ChromiumJSONNewPutRoute {
6
+ name = BrowserlessRoutes.EdgeJSONNewPutRoute;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { BrowserlessRoutes } from '@browserless.io/browserless';
2
+ import { default as ChromiumJSONProtocolGetRoute } from '../../../shared/json-protocol.http.js';
3
+ export { ResponseSchema } from '../../../shared/json-protocol.http.js';
4
+
5
+ export default class EdgeJSONProtocolGetRoute extends ChromiumJSONProtocolGetRoute {
6
+ name = BrowserlessRoutes.EdgeJSONProtocolGetRoute;
7
+ }
@@ -0,0 +1,7 @@
1
+ import { BrowserlessRoutes } from '@browserless.io/browserless';
2
+ import { default as ChromiumJSONVersionGetRoute } from '../../../shared/json-version.http.js';
3
+ export { ResponseSchema } from '../../../shared/json-version.http.js';
4
+
5
+ export default class EdgeJSONVersionGetRoute extends ChromiumJSONVersionGetRoute {
6
+ name = BrowserlessRoutes.EdgeJSONVersionGetRoute;
7
+ }
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ default as PDF,
10
+ QuerySchema,
11
+ ResponseSchema,
12
+ } from '../../../shared/pdf.http.js';
13
+
14
+ export default class EdgePDFPostRoute extends PDF {
15
+ name = BrowserlessRoutes.EdgePDFPostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgePdf];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ default as Performance,
10
+ QuerySchema,
11
+ ResponseSchema,
12
+ } from '../../../shared/performance.http.js';
13
+
14
+ export default class EdgePerformancePostRoute extends Performance {
15
+ name = BrowserlessRoutes.EdgePerformancePostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgePerformance];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ QuerySchema,
10
+ ResponseSchema,
11
+ default as Scrape,
12
+ } from '../../../shared/scrape.http.js';
13
+
14
+ export default class EdgeScrapePostRoute extends Scrape {
15
+ name = BrowserlessRoutes.EdgeScrapePostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgeScrape];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -0,0 +1,20 @@
1
+ import {
2
+ BrowserlessRoutes,
3
+ EdgeCDP,
4
+ HTTPRoutes,
5
+ } from '@browserless.io/browserless';
6
+
7
+ import {
8
+ BodySchema,
9
+ QuerySchema,
10
+ ResponseSchema,
11
+ default as Screenshot,
12
+ } from '../../../shared/screenshot.http.js';
13
+
14
+ export default class EdgeScreenshotPostRoute extends Screenshot {
15
+ name = BrowserlessRoutes.EdgeScreenshotPostRoute;
16
+ browser = EdgeCDP;
17
+ path = [HTTPRoutes.edgeScreenshot];
18
+ }
19
+
20
+ export { BodySchema, QuerySchema, ResponseSchema };
@@ -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
+ });