@percy/core 1.32.8-beta.1 → 1.32.8-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.
package/dist/browser.js CHANGED
@@ -9,7 +9,7 @@ import rimraf from 'rimraf';
9
9
  import logger from '@percy/logger';
10
10
  import install from './install.js';
11
11
  import { MAX_CDP_PAYLOAD } from './network.js';
12
- import Session from './session.js';
12
+ import Session, { cdpTimeout, cdpTimeoutMessage } from './session.js';
13
13
  import Page from './page.js';
14
14
 
15
15
  // Chrome features Percy disables for v143 new-headless asset discovery.
@@ -156,6 +156,7 @@ export class Browser extends EventEmitter {
156
156
  // Reset state for fresh launch
157
157
  this.readyState = null;
158
158
  this._closed = null;
159
+ // close() above already cleared every pending callback and its deadline
159
160
  this.#callbacks.clear();
160
161
  this.sessions.clear();
161
162
 
@@ -202,6 +203,7 @@ export class Browser extends EventEmitter {
202
203
 
203
204
  // reject any pending callbacks
204
205
  for (let callback of this.#callbacks.values()) {
206
+ clearTimeout(callback.timer);
205
207
  callback.reject(Object.assign(callback.error, {
206
208
  message: `Protocol error (${callback.method}): Browser closed.`
207
209
  }));
@@ -311,14 +313,28 @@ export class Browser extends EventEmitter {
311
313
  params
312
314
  }));
313
315
 
314
- // will resolve or reject when a matching response is received
316
+ // will resolve or reject when a matching response is received, or when
317
+ // the deadline below expires because no response is ever coming. The
318
+ // browser process can go silent the same way a renderer can - target
319
+ // creation and attachment strand here otherwise, before any page exists.
315
320
  return new Promise((resolve, reject) => {
316
- this.#callbacks.set(id, {
321
+ let callback = {
317
322
  error: new Error(),
318
323
  resolve,
319
324
  reject,
320
325
  method
321
- });
326
+ };
327
+ let timeout = cdpTimeout();
328
+ if (timeout > 0) {
329
+ callback.timer = setTimeout(() => {
330
+ this.#callbacks.delete(id);
331
+ this.log.debug(`Protocol timeout (${method}) after ${timeout}ms`);
332
+ reject(Object.assign(callback.error, {
333
+ message: cdpTimeoutMessage(method, timeout)
334
+ }));
335
+ }, timeout);
336
+ }
337
+ this.#callbacks.set(id, callback);
322
338
  });
323
339
  }
324
340
  }
@@ -374,6 +390,7 @@ export class Browser extends EventEmitter {
374
390
  // resolve or reject a pending promise created with #send()
375
391
  let callback = this.#callbacks.get(data.id);
376
392
  this.#callbacks.delete(data.id);
393
+ clearTimeout(callback.timer);
377
394
 
378
395
  /* istanbul ignore next: races with page._handleMessage() */
379
396
  if (data.error) {
package/dist/config.js CHANGED
@@ -425,6 +425,10 @@ export const configSchema = {
425
425
  minLength: 1
426
426
  }
427
427
  },
428
+ enablePseudoClassSerialization: {
429
+ type: 'boolean',
430
+ default: false
431
+ },
428
432
  pseudoClassEnabledElements: {
429
433
  type: 'object',
430
434
  additionalProperties: false,
@@ -753,6 +757,9 @@ export const snapshotSchema = {
753
757
  ignoreIframeSelectors: {
754
758
  $ref: '/config/snapshot#/properties/ignoreIframeSelectors'
755
759
  },
760
+ enablePseudoClassSerialization: {
761
+ $ref: '/config/snapshot#/properties/enablePseudoClassSerialization'
762
+ },
756
763
  pseudoClassEnabledElements: {
757
764
  $ref: '/config/snapshot#/properties/pseudoClassEnabledElements'
758
765
  },
package/dist/discovery.js CHANGED
@@ -60,6 +60,7 @@ function debugSnapshotOptions(snapshot) {
60
60
  debugProp(snapshot, 'ignoreCanvasSerializationErrors');
61
61
  debugProp(snapshot, 'ignoreStyleSheetSerializationErrors');
62
62
  debugProp(snapshot, 'pseudoClassEnabledElements', JSON.stringify);
63
+ debugProp(snapshot, 'enablePseudoClassSerialization');
63
64
  debugProp(snapshot, 'discovery.autoConfigureAllowedHostnames');
64
65
  if (Array.isArray(snapshot.domSnapshot)) {
65
66
  debugProp(snapshot, 'domSnapshot.0.userAgent');
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { ServerError } from './server.js';
4
+ const MAX_SEARCH_DEPTH = 15;
4
5
 
5
6
  // Root under which BrowserStack App Automate hosts write Maestro session
6
7
  // artifacts (screenshots + debug output). Historically /tmp; hosts that
@@ -14,6 +15,12 @@ export function appAutomateTmpDir() {
14
15
  let dir = (process.env.PERCY_APP_AUTOMATE_TMP_DIR || '/tmp').replace(/[/\\]+$/, '');
15
16
  return path.isAbsolute(dir) ? dir : '/tmp';
16
17
  }
18
+ export function bsScopeRootOverride() {
19
+ let raw = process.env.PERCY_MAESTRO_BS_SCOPE_ROOT;
20
+ if (!raw) return null;
21
+ let dir = raw.replace(/[/\\]+$/, '');
22
+ return path.isAbsolute(dir) ? dir : null;
23
+ }
17
24
 
18
25
  /* istanbul ignore next — defensive manual directory walker invoked only when
19
26
  fast-glob import fails (broken install / FS corruption). Unit tests
@@ -21,31 +28,35 @@ export function appAutomateTmpDir() {
21
28
  the walker against real session layouts. Path-traversal sinks inside this
22
29
  function are suppressed at file level in .semgrepignore with the same
23
30
  rationale (upstream SAFE_ID validation, depth cap, exact filename match). */
24
- async function manualScreenshotWalk(platform, sessionId, name) {
31
+ async function manualScreenshotWalk(platform, sessionId, name, scopeRoot) {
25
32
  const files = [];
26
- try {
27
- if (platform === 'ios') {
28
- const sessionDir = `${appAutomateTmpDir()}/${sessionId}`;
29
- const walk = async (dir, depth) => {
30
- if (depth > 15) return; // sanity cap
31
- let entries;
32
- try {
33
- entries = await fs.promises.readdir(dir, {
34
- withFileTypes: true
35
- });
36
- } catch {
37
- return;
38
- }
39
- for (const entry of entries) {
40
- const full = path.join(dir, entry.name);
41
- if (entry.isDirectory()) {
42
- await walk(full, depth + 1);
43
- } else if (entry.isFile() && entry.name === `${name}.png` && full.includes('_maestro_debug_')) {
44
- files.push(full);
45
- }
33
+ const walkFrom = async (root, accept) => {
34
+ const walk = async (dir, depth) => {
35
+ if (depth > MAX_SEARCH_DEPTH) return;
36
+ let entries;
37
+ try {
38
+ entries = await fs.promises.readdir(dir, {
39
+ withFileTypes: true
40
+ });
41
+ } catch {
42
+ return;
43
+ }
44
+ for (const entry of entries) {
45
+ const full = path.join(dir, entry.name);
46
+ if (entry.isDirectory()) {
47
+ await walk(full, depth + 1);
48
+ } else if (entry.isFile() && entry.name === `${name}.png` && accept(full)) {
49
+ files.push(full);
46
50
  }
47
- };
48
- await walk(sessionDir, 0);
51
+ }
52
+ };
53
+ await walk(root, 0);
54
+ };
55
+ try {
56
+ if (scopeRoot) {
57
+ await walkFrom(scopeRoot, () => true);
58
+ } else if (platform === 'ios') {
59
+ await walkFrom(`${appAutomateTmpDir()}/${sessionId}`, full => full.includes('_maestro_debug_'));
49
60
  } else {
50
61
  const baseDir = `${appAutomateTmpDir()}/${sessionId}_test_suite/logs`;
51
62
  const logDirs = await fs.promises.readdir(baseDir);
@@ -78,8 +89,10 @@ export async function locateScreenshot({
78
89
  name,
79
90
  filePath,
80
91
  scopeRoot,
81
- selfHosted
92
+ selfHosted,
93
+ recursiveScope
82
94
  }) {
95
+ let scopedGlob = selfHosted || !!recursiveScope;
83
96
  let chosenFile;
84
97
  if (filePath) {
85
98
  chosenFile = filePath;
@@ -94,7 +107,7 @@ export async function locateScreenshot({
94
107
  // (scopeRoot = PERCY_MAESTRO_SCREENSHOT_DIR). `name` is SAFE_ID-validated
95
108
  // by the caller, so it cannot contain separators or traversal chars.
96
109
  let searchPattern;
97
- if (selfHosted) {
110
+ if (scopedGlob) {
98
111
  // fast-glob requires forward-slashes in patterns on every platform; on
99
112
  // Windows scopeRoot contains backslashes, so normalize before embedding.
100
113
  // Production-code Windows portability — verified by the CI Windows runner.
@@ -111,12 +124,9 @@ export async function locateScreenshot({
111
124
  let {
112
125
  default: glob
113
126
  } = await import('fast-glob');
114
- // Self-hosted needs `dot: true` because Maestro's default output dir is
115
- // `.maestro/` — a dot-prefixed entry fast-glob hides by default. BS
116
- // layouts have no dot-prefixed segments, so omitting it there keeps the
117
- // byte-identical behavior.
118
- files = await glob(searchPattern, selfHosted ? {
119
- dot: true
127
+ files = await glob(searchPattern, scopedGlob ? {
128
+ dot: true,
129
+ deep: MAX_SEARCH_DEPTH
120
130
  } : undefined);
121
131
  } catch {
122
132
  // Fast-glob import / glob call failed — fall back to manual walker (BS
@@ -125,7 +135,7 @@ export async function locateScreenshot({
125
135
  // See manualScreenshotWalk() at file top + the file-level .semgrepignore.
126
136
  /* istanbul ignore next — only fires when fast-glob import throws
127
137
  (broken install / FS corruption); integration-test territory. */
128
- files = selfHosted ? [] : await manualScreenshotWalk(platform, sessionId, name);
138
+ files = selfHosted ? [] : await manualScreenshotWalk(platform, sessionId, name, recursiveScope ? scopeRoot : null);
129
139
  }
130
140
  if (!files || files.length === 0) {
131
141
  throw new ServerError(404, `Screenshot not found: ${name}.png (searched ${searchPattern})`);
@@ -177,7 +187,8 @@ export async function locateScreenshot({
177
187
  const realPathFwd = realPath.replace(/\\/g, '/');
178
188
  const realPrefixFwd = realPrefix.replace(/\\/g, '/');
179
189
  if (!realPathFwd.startsWith(`${realPrefixFwd}/`)) {
180
- throw new ServerError(404, `Screenshot not found: ${name}.png (resolved outside ${selfHosted ? 'PERCY_MAESTRO_SCREENSHOT_DIR' : 'session dir'})`);
190
+ const scopeLabel = selfHosted ? 'PERCY_MAESTRO_SCREENSHOT_DIR' : recursiveScope ? 'PERCY_MAESTRO_BS_SCOPE_ROOT' : 'session dir';
191
+ throw new ServerError(404, `Screenshot not found: ${name}.png (resolved outside ${scopeLabel})`);
181
192
  }
182
193
  return realPath;
183
194
  }
@@ -4,7 +4,7 @@ import { normalize } from '@percy/config/utils';
4
4
  import { ServerError } from './server.js';
5
5
  import { encodeURLSearchParams } from './utils.js';
6
6
  import { handleSyncJob } from './snapshot.js';
7
- import { locateScreenshot, appAutomateTmpDir } from './maestro-screenshot-file.js';
7
+ import { locateScreenshot, appAutomateTmpDir, bsScopeRootOverride } from './maestro-screenshot-file.js';
8
8
  import { validateRegionInputs, resolveRegions } from './maestro-regions.js';
9
9
  import { deriveDeviceInsets } from './maestro-hierarchy.js';
10
10
 
@@ -103,6 +103,7 @@ export async function handleMaestroScreenshot(req, res, percy) {
103
103
  // realpath + prefix check inside locateScreenshot enforces the security
104
104
  // invariant at whichever root applies; the boundary is relocated, not removed.
105
105
  let scopeRoot;
106
+ let recursiveScope = false;
106
107
  if (selfHosted) {
107
108
  // Reject filePath outright in self-hosted mode. The SDK never emits it (it
108
109
  // sends a relative SCREENSHOT_NAME); honoring an absolute filePath against
@@ -133,8 +134,24 @@ export async function handleMaestroScreenshot(req, res, percy) {
133
134
  throw new ServerError(400, `PERCY_MAESTRO_SCREENSHOT_DIR is not an existing directory: ${dir}`);
134
135
  }
135
136
  scopeRoot = dir;
137
+ recursiveScope = true;
136
138
  } else {
137
- scopeRoot = platform === 'ios' ? `${appAutomateTmpDir()}/${sessionId}` : `${appAutomateTmpDir()}/${sessionId}_test_suite`;
139
+ let overrideRoot = bsScopeRootOverride();
140
+ if (overrideRoot) {
141
+ var _sessionStat;
142
+ recursiveScope = true;
143
+ let sessionScoped = `${overrideRoot}/${sessionId}`;
144
+ let sessionStat;
145
+ try {
146
+ sessionStat = await fs.promises.stat(sessionScoped);
147
+ } catch {
148
+ sessionStat = null;
149
+ }
150
+ scopeRoot = (_sessionStat = sessionStat) !== null && _sessionStat !== void 0 && _sessionStat.isDirectory() ? sessionScoped : overrideRoot;
151
+ percy.log.debug(`maestro screenshot scope root: ${scopeRoot}`);
152
+ } else {
153
+ scopeRoot = platform === 'ios' ? `${appAutomateTmpDir()}/${sessionId}` : `${appAutomateTmpDir()}/${sessionId}_test_suite`;
154
+ }
138
155
  }
139
156
 
140
157
  // Validate regions input shape early (before file I/O and ADB work) so
@@ -150,7 +167,8 @@ export async function handleMaestroScreenshot(req, res, percy) {
150
167
  name,
151
168
  filePath: suppliedFilePath,
152
169
  scopeRoot,
153
- selfHosted
170
+ selfHosted,
171
+ recursiveScope
154
172
  });
155
173
 
156
174
  // Read and base64-encode the screenshot
package/dist/page.js CHANGED
@@ -262,7 +262,8 @@ export class Page {
262
262
  ignoreCanvasSerializationErrors,
263
263
  ignoreStyleSheetSerializationErrors,
264
264
  ignoreIframeSelectors,
265
- pseudoClassEnabledElements
265
+ pseudoClassEnabledElements,
266
+ enablePseudoClassSerialization
266
267
  } = snapshot;
267
268
  this.log.debug(`Taking snapshot: ${name}${width ? ` @${width}px` : ''}`, this.meta);
268
269
 
@@ -337,7 +338,8 @@ export class Page {
337
338
  ignoreCanvasSerializationErrors,
338
339
  ignoreStyleSheetSerializationErrors,
339
340
  ignoreIframeSelectors,
340
- pseudoClassEnabledElements
341
+ pseudoClassEnabledElements,
342
+ enablePseudoClassSerialization
341
343
  });
342
344
 
343
345
  // Attach readiness diagnostics onto the captured DOM snapshot so the backend/UI can surface
package/dist/session.js CHANGED
@@ -1,6 +1,39 @@
1
1
  import EventEmitter from 'events';
2
2
  import logger from '@percy/logger';
3
+
4
+ // Node-side ceiling on a single CDP round trip. Chrome does not always answer:
5
+ // a renderer that is frozen, starved of CPU, or swapped out keeps its target
6
+ // attached and simply never replies. In-page deadlines cannot rescue that case
7
+ // — their timers live in the very renderer that stopped running — so with no
8
+ // deadline here `send()` never settles and the whole CLI blocks forever with
9
+ // no error, no log and an unfinalized build. Reproducible by freezing the
10
+ // renderer (`Page.setWebLifecycleState`) or descheduling it (SIGSTOP), both of
11
+ // which a small, memory-pressured CI agent can do on its own.
12
+ export const DEFAULT_CDP_TIMEOUT = 120000;
13
+
14
+ // The longest wait a caller could legitimately be running *inside* the page,
15
+ // doubled. Keeps the deadline above those so raising one of them can never
16
+ // turn into a spurious protocol timeout.
17
+ function inPageCeiling() {
18
+ return Math.max(parseInt(process.env.PERCY_PAGE_LOAD_TIMEOUT, 10) || 0, parseInt(process.env.PERCY_STORY_RENDER_TIMEOUT, 10) || 0) * 2;
19
+ }
20
+
21
+ // Resolved once per process, and memoized so a mid-run env change cannot make
22
+ // concurrent sessions disagree. `PERCY_CDP_TIMEOUT=0` disables the deadline.
23
+ export function cdpTimeout() {
24
+ if (Session.TIMEOUT !== undefined) return Session.TIMEOUT;
25
+ let configured = parseInt(process.env.PERCY_CDP_TIMEOUT, 10);
26
+ Session.TIMEOUT = Number.isNaN(configured) ? Math.max(DEFAULT_CDP_TIMEOUT, inPageCeiling()) : Math.max(0, configured);
27
+ return Session.TIMEOUT;
28
+ }
29
+
30
+ // Shared by both CDP deadlines - the session-scoped one below and the
31
+ // browser-scoped one in browser.js.
32
+ export function cdpTimeoutMessage(method, timeout) {
33
+ return `Protocol error (${method}): Timed out after ${timeout}ms ` + 'waiting for a response from the browser. The browser stopped responding — a ' + 'renderer or browser process that is frozen, starved of CPU, or swapped out ' + 'never replies and never runs its own timers. Raise PERCY_CDP_TIMEOUT if this ' + 'command is legitimately slower than that, or set it to 0 to disable the deadline.';
34
+ }
3
35
  export class Session extends EventEmitter {
36
+ static TIMEOUT = undefined;
4
37
  #callbacks = new Map();
5
38
  log = logger('core:session');
6
39
  children = new Map();
@@ -45,14 +78,26 @@ export class Session extends EventEmitter {
45
78
  params
46
79
  });
47
80
 
48
- // will resolve or reject when a matching response is received
81
+ // will resolve or reject when a matching response is received, or when the
82
+ // deadline below expires because no response is ever coming
49
83
  return new Promise((resolve, reject) => {
50
- this.#callbacks.set(id, {
84
+ let callback = {
51
85
  error: new Error(),
52
86
  resolve,
53
87
  reject,
54
88
  method
55
- });
89
+ };
90
+ let timeout = cdpTimeout();
91
+ if (timeout > 0) {
92
+ callback.timer = setTimeout(() => {
93
+ this.#callbacks.delete(id);
94
+ this.log.debug(`Protocol timeout (${method}) after ${timeout}ms`);
95
+ reject(Object.assign(callback.error, {
96
+ message: cdpTimeoutMessage(method, timeout)
97
+ }));
98
+ }, timeout);
99
+ }
100
+ this.#callbacks.set(id, callback);
56
101
  });
57
102
  }
58
103
  _handleMessage(data) {
@@ -60,6 +105,7 @@ export class Session extends EventEmitter {
60
105
  // resolve or reject a pending promise created with #send()
61
106
  let callback = this.#callbacks.get(data.id);
62
107
  this.#callbacks.delete(data.id);
108
+ clearTimeout(callback.timer);
63
109
 
64
110
  /* istanbul ignore next: races with browser._handleMessage() */
65
111
  if (data.error) {
@@ -80,6 +126,7 @@ export class Session extends EventEmitter {
80
126
 
81
127
  // reject any pending callbacks
82
128
  for (let callback of this.#callbacks.values()) {
129
+ clearTimeout(callback.timer);
83
130
  callback.reject(Object.assign(callback.error, {
84
131
  message: `Protocol error (${callback.method}): ${this.closedReason}`
85
132
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.32.8-beta.1",
3
+ "version": "1.32.8-beta.3",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,12 +46,12 @@
46
46
  "dependencies": {
47
47
  "@grpc/grpc-js": "^1.14.3",
48
48
  "@grpc/proto-loader": "^0.8.0",
49
- "@percy/client": "1.32.8-beta.1",
50
- "@percy/config": "1.32.8-beta.1",
51
- "@percy/dom": "1.32.8-beta.1",
52
- "@percy/logger": "1.32.8-beta.1",
53
- "@percy/monitoring": "1.32.8-beta.1",
54
- "@percy/webdriver-utils": "1.32.8-beta.1",
49
+ "@percy/client": "1.32.8-beta.3",
50
+ "@percy/config": "1.32.8-beta.3",
51
+ "@percy/dom": "1.32.8-beta.3",
52
+ "@percy/logger": "1.32.8-beta.3",
53
+ "@percy/monitoring": "1.32.8-beta.3",
54
+ "@percy/webdriver-utils": "1.32.8-beta.3",
55
55
  "adm-zip": "^0.6.0",
56
56
  "busboy": "^1.6.0",
57
57
  "content-disposition": "^0.5.4",
@@ -67,7 +67,7 @@
67
67
  "yaml": "^2.4.1"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@percy/cli-doctor": "1.32.8-beta.1"
70
+ "@percy/cli-doctor": "1.32.8-beta.3"
71
71
  },
72
- "gitHead": "1d2b91de85fe3e2d64c43d0ca7cb4d51facfa918"
72
+ "gitHead": "719021a0565d18a6b47d9d494961eaccb6d63009"
73
73
  }