@browserless.io/browserless 2.15.0 → 2.16.0-beta-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.
@@ -27,8 +27,10 @@ class BasePlaywright extends EventEmitter {
27
27
  protected proxy = httpProxy.createProxyServer();
28
28
  protected browser: playwright.BrowserServer | null = null;
29
29
  protected browserWSEndpoint: string | null = null;
30
- protected playwrightBrowserType: PlaywrightBrowserTypes = PlaywrightBrowserTypes.chromium;
31
- protected executablePath = () => playwright[this.playwrightBrowserType].executablePath();
30
+ protected playwrightBrowserType: PlaywrightBrowserTypes =
31
+ PlaywrightBrowserTypes.chromium;
32
+ protected executablePath = () =>
33
+ playwright[this.playwrightBrowserType].executablePath();
32
34
 
33
35
  constructor({
34
36
  config,
@@ -107,17 +109,22 @@ class BasePlaywright extends EventEmitter {
107
109
  `${this.constructor.name} hasn't been launched yet!`,
108
110
  );
109
111
  }
110
- const browser = await playwright[this.playwrightBrowserType].connect(this.browserWSEndpoint);
112
+ const browser = await playwright[this.playwrightBrowserType].connect(
113
+ this.browserWSEndpoint,
114
+ );
111
115
  return await browser.newPage();
112
116
  }
113
117
 
114
- public async launch(laucherOpts: BrowserLauncherOptions): Promise<playwright.BrowserServer> {
118
+ public async launch(
119
+ laucherOpts: BrowserLauncherOptions,
120
+ ): Promise<playwright.BrowserServer> {
115
121
  const { options, pwVersion } = laucherOpts;
116
122
  this.logger.info(`Launching ${this.constructor.name} Handler`);
117
123
 
118
124
  const opts = this.makeLaunchOptions(options);
119
125
  const versionedPw = await this.config.loadPwVersion(pwVersion!);
120
- const browser = await versionedPw[this.playwrightBrowserType].launchServer(opts);
126
+ const browser =
127
+ await versionedPw[this.playwrightBrowserType].launchServer(opts);
121
128
  const browserWSEndpoint = browser.wsEndpoint();
122
129
 
123
130
  this.logger.info(
@@ -535,7 +535,7 @@ export class BrowserManager {
535
535
  options: launchOptions as BrowserServerOptions,
536
536
  pwVersion,
537
537
  req,
538
- stealth: launchOptions?.stealth
538
+ stealth: launchOptions?.stealth,
539
539
  });
540
540
  await this.hooks.browser({ browser, req });
541
541
 
@@ -22,6 +22,7 @@ describe(`Limiter`, () => {
22
22
  webHooks.callRejectAlertURL.resetHistory();
23
23
  webHooks.callTimeoutAlertURL.resetHistory();
24
24
  webHooks.callErrorAlertURL.resetHistory();
25
+
25
26
  hooks.before.resetHistory();
26
27
  hooks.after.resetHistory();
27
28
  hooks.browser.resetHistory();
@@ -119,6 +120,32 @@ describe(`Limiter`, () => {
119
120
  expect(handlerTwo.calledOnce).to.be.true;
120
121
  });
121
122
 
123
+ it('continues to process jobs even if an earlier job errors', (d) => {
124
+ const config = new Config();
125
+ const monitoring = new Monitoring(config);
126
+ const metrics = new Metrics();
127
+
128
+ config.setConcurrent(1);
129
+ config.setQueued(1);
130
+ config.setTimeout(-1);
131
+
132
+ const limiter = new Limiter(config, metrics, monitoring, webHooks, hooks);
133
+ const errorJob = () =>
134
+ Promise.reject(new Error('Danger, danger. High voltage!'));
135
+ const okJob = spy();
136
+
137
+ const jobOne = limiter.limit(errorJob, asyncNoop, asyncNoop, noop);
138
+ const jobTwo = limiter.limit(okJob, asyncNoop, asyncNoop, noop);
139
+
140
+ jobOne();
141
+ jobTwo();
142
+
143
+ limiter.addEventListener('end', () => {
144
+ expect(okJob.calledOnce).to.be.true;
145
+ d(undefined);
146
+ });
147
+ });
148
+
122
149
  it('bubbles up errors', async () => {
123
150
  const config = new Config();
124
151
  const monitoring = new Monitoring(config);
package/src/utils.ts CHANGED
@@ -23,6 +23,7 @@ import { Page } from 'puppeteer-core';
23
23
  import { ServerResponse } from 'http';
24
24
  import crypto from 'crypto';
25
25
  import debug from 'debug';
26
+ import { fileURLToPath } from 'url';
26
27
  import gradient from 'gradient-string';
27
28
  import { homedir } from 'os';
28
29
  import path from 'path';
@@ -33,6 +34,8 @@ const isHTTP = (
33
34
  return (writeable as ServerResponse).writeHead !== undefined;
34
35
  };
35
36
 
37
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
38
+
36
39
  const getAuthHeaderToken = (header: string) => {
37
40
  if (header.startsWith('Basic')) {
38
41
  const username = header.split(/\s+/).pop() || '';
@@ -475,10 +478,11 @@ export const queryParamsToObject = (
475
478
  ): Record<string, unknown> =>
476
479
  [...params.entries()].reduce(
477
480
  (accum, [key, value]) => {
478
- accum[key] = value;
481
+ accum[key] =
482
+ value === '' || value === undefined || value === null ? true : value;
479
483
  return accum;
480
484
  },
481
- {} as Record<string, string>,
485
+ {} as ReturnType<typeof queryParamsToObject>,
482
486
  );
483
487
 
484
488
  // eslint-disable-next-line @typescript-eslint/no-empty-function
@@ -844,3 +848,5 @@ export const getCDPClient = (page: Page): CDPSession => {
844
848
 
845
849
  return typeof c === 'function' ? c.call(page) : c;
846
850
  };
851
+
852
+ export const ublockPath = path.join(__dirname, '..', 'extensions', 'ublock');