@checkly/playwright-core 1.41.2-beta.1 → 1.41.2-beta.3

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.
@@ -8,6 +8,7 @@ var _helper = require("../helper");
8
8
  var _eventsHelper = require("../../utils/eventsHelper");
9
9
  var network = _interopRequireWildcard(require("../network"));
10
10
  var _utils = require("../../utils");
11
+ var _protocolError = require("../protocolError");
11
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
14
  /**
@@ -543,30 +544,44 @@ class RouteImpl {
543
544
  method: overrides.method,
544
545
  postData: overrides.postData ? overrides.postData.toString('base64') : undefined
545
546
  };
546
- await this._session.send('Fetch.continueRequest', this._alreadyContinuedParams);
547
+ await catchDisallowedErrors(async () => {
548
+ await this._session.send('Fetch.continueRequest', this._alreadyContinuedParams);
549
+ });
547
550
  }
548
551
  async fulfill(response) {
549
552
  const body = response.isBase64 ? response.body : Buffer.from(response.body).toString('base64');
550
553
  const responseHeaders = splitSetCookieHeader(response.headers);
551
- await this._session.send('Fetch.fulfillRequest', {
552
- requestId: this._interceptionId,
553
- responseCode: response.status,
554
- responsePhrase: network.STATUS_TEXTS[String(response.status)],
555
- responseHeaders,
556
- body
554
+ await catchDisallowedErrors(async () => {
555
+ await this._session.send('Fetch.fulfillRequest', {
556
+ requestId: this._interceptionId,
557
+ responseCode: response.status,
558
+ responsePhrase: network.STATUS_TEXTS[String(response.status)],
559
+ responseHeaders,
560
+ body
561
+ });
557
562
  });
558
563
  }
559
564
  async abort(errorCode = 'failed') {
560
565
  const errorReason = errorReasons[errorCode];
561
566
  (0, _utils.assert)(errorReason, 'Unknown error code: ' + errorCode);
562
- // In certain cases, protocol will return error if the request was already canceled
563
- // or the page was closed. We should tolerate these errors.
564
- await this._session._sendMayFail('Fetch.failRequest', {
565
- requestId: this._interceptionId,
566
- errorReason
567
+ await catchDisallowedErrors(async () => {
568
+ await this._session.send('Fetch.failRequest', {
569
+ requestId: this._interceptionId,
570
+ errorReason
571
+ });
567
572
  });
568
573
  }
569
574
  }
575
+
576
+ // In certain cases, protocol will return error if the request was already canceled
577
+ // or the page was closed. We should tolerate these errors but propagate other.
578
+ async function catchDisallowedErrors(callback) {
579
+ try {
580
+ return await callback();
581
+ } catch (e) {
582
+ if ((0, _protocolError.isProtocolError)(e) && e.message.includes('Invalid http status code or phrase')) throw e;
583
+ }
584
+ }
570
585
  function splitSetCookieHeader(headers) {
571
586
  const index = headers.findIndex(({
572
587
  name
@@ -281,6 +281,12 @@ class FrameDispatcher extends _dispatcher.Dispatcher {
281
281
  expectedValue
282
282
  });
283
283
  if (result.received !== undefined) result.received = (0, _jsHandleDispatcher.serializeResult)(result.received);
284
+ if (result.matches === params.isNot) metadata.error = {
285
+ error: {
286
+ name: 'Expect',
287
+ message: 'Expect failed'
288
+ }
289
+ };
284
290
  return result;
285
291
  }
286
292
  }
@@ -126,15 +126,6 @@ class Request extends _instrumentation.SdkObject {
126
126
  this._failureText = failureText;
127
127
  this._waitForResponsePromise.resolve(null);
128
128
  }
129
- async _waitForRequestFailure() {
130
- const response = await this._waitForResponsePromise;
131
- // If response is null it was a failure an we are done.
132
- if (!response) return;
133
- await response._finishedPromise;
134
- if (this.failure()) return;
135
- // If request finished without errors, we stall.
136
- await new Promise(() => {});
137
- }
138
129
  _setOverrides(overrides) {
139
130
  this._overrides = overrides;
140
131
  this._updateHeadersMap();
@@ -241,10 +232,7 @@ class Route extends _instrumentation.SdkObject {
241
232
  async abort(errorCode = 'failed') {
242
233
  this._startHandling();
243
234
  this._request._context.emit(_browserContext.BrowserContext.Events.RequestAborted, this._request);
244
- await Promise.race([this._delegate.abort(errorCode),
245
- // If the request is already cancelled by the page before we handle the route,
246
- // we'll receive loading failed event and will ignore route handling error.
247
- this._request._waitForRequestFailure()]);
235
+ await this._delegate.abort(errorCode);
248
236
  this._endHandling();
249
237
  }
250
238
  async redirectNavigationRequest(url) {
@@ -270,15 +258,12 @@ class Route extends _instrumentation.SdkObject {
270
258
  const headers = [...(overrides.headers || [])];
271
259
  this._maybeAddCorsHeaders(headers);
272
260
  this._request._context.emit(_browserContext.BrowserContext.Events.RequestFulfilled, this._request);
273
- await Promise.race([this._delegate.fulfill({
261
+ await this._delegate.fulfill({
274
262
  status: overrides.status || 200,
275
263
  headers,
276
- body,
264
+ body: body,
277
265
  isBase64
278
- }),
279
- // If the request is already cancelled by the page before we handle the route,
280
- // we'll receive loading failed event and will ignore route handling error.
281
- this._request._waitForRequestFailure()]);
266
+ });
282
267
  this._endHandling();
283
268
  }
284
269
 
@@ -315,10 +300,7 @@ class Route extends _instrumentation.SdkObject {
315
300
  }
316
301
  this._request._setOverrides(overrides);
317
302
  if (!overrides.isFallback) this._request._context.emit(_browserContext.BrowserContext.Events.RequestContinued, this._request);
318
- await Promise.race([this._delegate.continue(this._request, overrides),
319
- // If the request is already cancelled by the page before we handle the route,
320
- // we'll receive loading failed event and will ignore route handling error.
321
- this._request._waitForRequestFailure()]);
303
+ await this._delegate.continue(this._request, overrides);
322
304
  this._endHandling();
323
305
  }
324
306
  _startHandling() {