@percy/core 1.31.4 → 1.31.5-alpha.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.
package/dist/browser.js CHANGED
@@ -123,6 +123,26 @@ export class Browser extends EventEmitter {
123
123
  var _this$ws;
124
124
  return ((_this$ws = this.ws) === null || _this$ws === void 0 ? void 0 : _this$ws.readyState) === WebSocket.OPEN;
125
125
  }
126
+ async restart() {
127
+ this.log.info('Restarting browser after disconnection');
128
+
129
+ // Force close the existing browser instance
130
+ if (this.readyState !== null) {
131
+ await this.close(true).catch(err => {
132
+ this.log.debug('Error during force close:', err);
133
+ });
134
+ }
135
+
136
+ // Reset state for fresh launch
137
+ this.readyState = null;
138
+ this._closed = null;
139
+ this.#callbacks.clear();
140
+ this.sessions.clear();
141
+
142
+ // Launch a new browser instance
143
+ await this.launch();
144
+ this.log.info('Browser restarted successfully');
145
+ }
126
146
  async close(force = false) {
127
147
  var _this$percy$config$di, _this$process, _this$ws2;
128
148
  // Check for the new closeBrowser option
@@ -194,6 +214,11 @@ export class Browser extends EventEmitter {
194
214
  return this._closed;
195
215
  }
196
216
  async page(options = {}) {
217
+ // Check if browser is connected, restart if needed
218
+ if (!this.isConnected()) {
219
+ this.log.warn('Browser disconnected, attempting restart');
220
+ await this.restart();
221
+ }
197
222
  let {
198
223
  targetId
199
224
  } = await this.send('Target.createTarget', {
package/dist/discovery.js CHANGED
@@ -539,8 +539,19 @@ export function createDiscoveryQueue(percy) {
539
539
  }
540
540
  }, {
541
541
  count: snapshot.discovery.retry ? 3 : 1,
542
- onRetry: () => {
542
+ onRetry: async error => {
543
+ var _error$message, _error$message2, _error$message3, _error$message4;
543
544
  percy.log.info(`Retrying snapshot: ${snapshotLogName(snapshot.name, snapshot.meta)}`, snapshot.meta);
545
+ // If browser disconnected or crashed, restart it before retrying
546
+ if (error !== null && error !== void 0 && (_error$message = error.message) !== null && _error$message !== void 0 && _error$message.includes('Browser not connected') || error !== null && error !== void 0 && (_error$message2 = error.message) !== null && _error$message2 !== void 0 && _error$message2.includes('Browser closed') || error !== null && error !== void 0 && (_error$message3 = error.message) !== null && _error$message3 !== void 0 && _error$message3.includes('Session closed') || error !== null && error !== void 0 && (_error$message4 = error.message) !== null && _error$message4 !== void 0 && _error$message4.includes('Session crashed')) {
547
+ percy.log.warn('Detected browser disconnection, restarting browser before retry');
548
+ try {
549
+ await percy.browser.restart();
550
+ } catch (restartError) {
551
+ percy.log.error('Failed to restart browser:', restartError);
552
+ throw restartError;
553
+ }
554
+ }
544
555
  },
545
556
  signal: snapshot._ctrl.signal,
546
557
  throwOn: ['AbortError']
package/dist/utils.js CHANGED
@@ -363,7 +363,7 @@ export async function withRetries(fn, {
363
363
  // if this error should not be retried on, we want to skip errors
364
364
  let throwError = throwOn === null || throwOn === void 0 ? void 0 : throwOn.includes(e.name);
365
365
  if (!throwError && run < count) {
366
- await (onRetry === null || onRetry === void 0 ? void 0 : onRetry());
366
+ await (onRetry === null || onRetry === void 0 ? void 0 : onRetry(e));
367
367
  continue;
368
368
  }
369
369
  throw e;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.31.4",
3
+ "version": "1.31.5-alpha.0",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "publishConfig": {
11
11
  "access": "public",
12
- "tag": "latest"
12
+ "tag": "beta"
13
13
  },
14
14
  "engines": {
15
15
  "node": ">=14"
@@ -43,12 +43,12 @@
43
43
  "test:types": "tsd"
44
44
  },
45
45
  "dependencies": {
46
- "@percy/client": "1.31.4",
47
- "@percy/config": "1.31.4",
48
- "@percy/dom": "1.31.4",
49
- "@percy/logger": "1.31.4",
50
- "@percy/monitoring": "1.31.4",
51
- "@percy/webdriver-utils": "1.31.4",
46
+ "@percy/client": "1.31.5-alpha.0",
47
+ "@percy/config": "1.31.5-alpha.0",
48
+ "@percy/dom": "1.31.5-alpha.0",
49
+ "@percy/logger": "1.31.5-alpha.0",
50
+ "@percy/monitoring": "1.31.5-alpha.0",
51
+ "@percy/webdriver-utils": "1.31.5-alpha.0",
52
52
  "content-disposition": "^0.5.4",
53
53
  "cross-spawn": "^7.0.3",
54
54
  "extract-zip": "^2.0.1",
@@ -61,5 +61,5 @@
61
61
  "ws": "^8.17.1",
62
62
  "yaml": "^2.4.1"
63
63
  },
64
- "gitHead": "ae9af7043b17186a26e4b8c584faa45559260f9e"
64
+ "gitHead": "c9c7b1d09cc3568ff57f4444b732d1b3a3b65fe2"
65
65
  }