@app-studio/qa-browser-darwin-arm64 0.11.3 → 0.11.6

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/bin/lightpanda CHANGED
@@ -1,4 +1,4 @@
1
1
  [diffend] Oversized file quarantined before diffing.
2
2
  name: package/bin/lightpanda
3
- size: 92614952 bytes
4
- sha256: 901f6b5c618e57a0a5d7e43dfb745146644936664810d5021756487963aa2299
3
+ size: 92796968 bytes
4
+ sha256: 224aa6364f4a4808b8db6468546087e1a0bafb012fe5d50beed700c37aa3eb74
@@ -5,6 +5,18 @@
5
5
  "arch": "arm64",
6
6
  "version": "1.1.0-dev.8814+46c56fa55",
7
7
  "rendering": "native-css",
8
+ "debugger": {
9
+ "revision": "qa-agent-debug-3-uncaught",
10
+ "pauseTransport": true,
11
+ "conditionalBreakpoints": true,
12
+ "steps": true,
13
+ "exceptionPause": true,
14
+ "exceptionPauseModes": [
15
+ "none",
16
+ "uncaught",
17
+ "all"
18
+ ]
19
+ },
8
20
  "formats": [
9
21
  "png",
10
22
  "mp4",
@@ -14,14 +26,14 @@
14
26
  "build": "release-fast",
15
27
  "source": {
16
28
  "commit": "46c56fa55fdb48b7fa30d83461c328c8a3635940",
17
- "dirty": false
29
+ "dirty": true
18
30
  },
19
31
  "files": {
20
- "lightpanda": "901f6b5c618e57a0a5d7e43dfb745146644936664810d5021756487963aa2299",
21
- "lightpanda-capture.mjs": "0e2511970a1552e0ff470ba1e5ed95da0ad75f2d121d6b659b41be552e7462a9",
32
+ "lightpanda": "224aa6364f4a4808b8db6468546087e1a0bafb012fe5d50beed700c37aa3eb74",
33
+ "lightpanda-capture.mjs": "91b5156c93b824a8b82817b81ad98c1373c61f99a030ce3a6d7b927a833fb071",
22
34
  "lightpanda-scenario.mjs": "ad41177bd602e93f2d12c0e30444ebf06e957e1215f67179defc8cc68e6839e6",
23
35
  "native-scenario.mjs": "b3efd2d0ad9eccff29f6d432e4eaa7eb9b2696c999577eed98f6fabc282a42b8",
24
36
  "LICENSE": "8486a10c4393cee1c25392769ddd3b2d6c242d6ec7928e1414efff7dfb2f07ef",
25
- "source.tar.gz": "5493bde608e1c19cfcaed532eaa8516491220c18a0412e122e4e982c1e602484"
37
+ "source.tar.gz": "dc73c248cda7feda66c0126c3f4bdff027c1d569c226fbd376281232abfd19e4"
26
38
  }
27
39
  }
@@ -16,11 +16,19 @@ const sleep = (ms, signal) => new Promise(resolve => {
16
16
  signal?.addEventListener('abort', done, { once: true });
17
17
  });
18
18
 
19
- async function bounded(task, milliseconds, operation, signal) {
19
+ async function bounded(task, milliseconds, operation, signal, extendDeadline) {
20
20
  let timer, abort;
21
21
  try {
22
22
  return await Promise.race([task, new Promise((_, reject) => {
23
- timer = setTimeout(() => reject(new Error(`${operation} timed out after ${milliseconds}ms`)), milliseconds);
23
+ let extended = false;
24
+ const expire = () => {
25
+ const remaining = extendDeadline?.() - performance.now();
26
+ if (remaining > 0) {
27
+ extended = true;
28
+ timer = setTimeout(expire, Math.min(milliseconds, remaining));
29
+ } else reject(new Error(extended ? `${operation} timed out at its navigation deadline` : `${operation} timed out after ${milliseconds}ms`));
30
+ };
31
+ timer = setTimeout(expire, milliseconds);
24
32
  abort = () => reject(signal.reason ?? new Error(`${operation} aborted`));
25
33
  if (signal?.aborted) abort();
26
34
  else signal?.addEventListener('abort', abort, { once: true });
@@ -28,11 +36,11 @@ async function bounded(task, milliseconds, operation, signal) {
28
36
  } finally { clearTimeout(timer); signal?.removeEventListener('abort', abort); }
29
37
  }
30
38
 
31
- async function capture(cdp, fullPage = false, timeout = 3000, signal) {
39
+ async function capture(cdp, fullPage = false, timeout = 3000, signal, extendDeadline) {
32
40
  signal?.throwIfAborted();
33
41
  const { data } = await bounded(cdp.send('Page.captureScreenshot', {
34
42
  format: 'png', captureBeyondViewport: fullPage,
35
- }), timeout, 'Native frame capture', signal);
43
+ }), timeout, 'Native frame capture', signal, extendDeadline);
36
44
  const png = Buffer.from(data, 'base64');
37
45
  if (png.length < 24 || !png.subarray(0, 8).equals(Buffer.from('89504e470d0a1a0a', 'hex'))) {
38
46
  throw new Error('The browser returned an invalid PNG');
@@ -109,9 +117,10 @@ export async function encodeFrames({ directory, count, path, fps = 5, ffmpeg = '
109
117
  * adds at most one frame period to the clip. A stalled owned encoder is
110
118
  * terminated; the caller's browser page remains open.
111
119
  */
112
- export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg = 'ffmpeg', signal } = {}) {
120
+ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg = 'ffmpeg', frameTimeout = 30000, signal } = {}) {
113
121
  if (!Number.isFinite(fps) || fps < 1 || fps > 60) throw new Error('fps must be between 1 and 60');
114
122
  if (!Number.isFinite(duration) || duration <= 0) throw new Error('duration must be positive (seconds)');
123
+ if (!Number.isFinite(frameTimeout) || frameTimeout < 1 || frameTimeout > 120000) throw new Error('frameTimeout must be between 1 and 120000 milliseconds');
115
124
  const extension = extname(path ?? '').toLowerCase();
116
125
  if (!['.mp4', '.webm', '.gif'].includes(extension)) throw new Error('Recording path must end in .mp4, .webm or .gif');
117
126
  signal?.throwIfAborted();
@@ -121,21 +130,39 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
121
130
  throw new Error('Recording needs CDP notifications from the same page session');
122
131
  }
123
132
  let frameId, loaderId, frameUrl, revision = 0, ready = false, observing = false, initial = true;
133
+ let pendingLoader, navigationDeadline;
134
+ const seenLoaders = new Set();
124
135
  const initialStop = new AbortController();
125
136
  const abortInitial = () => initialStop.abort(signal.reason);
126
137
  const detached = () => initialStop.abort(new Error('Recording CDP session detached'));
138
+ const armNavigation = () => {
139
+ if (!initial) navigationDeadline ??= performance.now() + 30_000;
140
+ };
141
+ const starting = event => {
142
+ if (!observing || !frameId || event.frameId !== frameId || !event.loaderId
143
+ || seenLoaders.has(event.loaderId)) return;
144
+ seenLoaders.add(event.loaderId);
145
+ pendingLoader = event.loaderId;
146
+ revision++; ready = false;
147
+ armNavigation();
148
+ };
127
149
  const navigated = ({ frame }) => {
128
- if (!frame || frame.parentId) return;
150
+ if (!frame || frame.parentId || !frame.id || !frame.loaderId || (frameId && frame.id !== frameId)) return;
151
+ if (seenLoaders.has(frame.loaderId) && pendingLoader !== frame.loaderId) return;
152
+ seenLoaders.add(frame.loaderId);
129
153
  frameId = frame.id; loaderId = frame.loaderId; frameUrl = frame.url;
154
+ pendingLoader = undefined;
130
155
  revision++; ready = false;
156
+ armNavigation();
131
157
  };
132
158
  const hasDocument = () => frameUrl && !/^about:blank(?:[?#]|$)/.test(frameUrl);
133
159
  const lifecycle = event => {
134
160
  // Enabling lifecycle notifications can replay old milestones, even for a
135
161
  // waiting about:blank frame. Only matching, observed main-document events count.
136
- if (observing && hasDocument() && event.name === 'DOMContentLoaded'
162
+ if (observing && !pendingLoader && hasDocument() && event.name === 'DOMContentLoaded'
137
163
  && event.frameId === frameId && event.loaderId === loaderId) ready = true;
138
164
  };
165
+ cdp.on('Page.frameStartedNavigating', starting);
139
166
  cdp.on('Page.frameNavigated', navigated);
140
167
  cdp.on('Page.lifecycleEvent', lifecycle);
141
168
  cdp.on('Inspector.detached', detached);
@@ -160,11 +187,12 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
160
187
  if (revision === before && frameTree?.frame) {
161
188
  const frame = frameTree.frame;
162
189
  frameId = frame.id; loaderId = frame.loaderId; frameUrl = frame.url;
190
+ if (loaderId) seenLoaders.add(loaderId);
163
191
  }
164
192
  observing = true;
165
193
  const current = revision;
166
194
  const state = await command('Runtime.evaluate', { expression: 'document.readyState', returnByValue: true });
167
- if (revision === current && hasDocument()
195
+ if (revision === current && !pendingLoader && hasDocument()
168
196
  && ['interactive', 'complete'].includes(state.result?.value)) ready = true;
169
197
  const firstRevision = revision, firstReady = ready;
170
198
  const first = await capture(cdp, false, remaining(), initialStop.signal);
@@ -211,10 +239,21 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
211
239
  const sample = async () => {
212
240
  const generation = revision;
213
241
  const mainReady = ready;
214
- const png = await capture(cdp, false, initial ? remaining() : 3000, initial ? initialStop.signal : undefined);
215
- // A capture already in flight at DCL keeps its original deadline. Require a
216
- // successful capture begun after that milestone before entering steady mode.
217
- if (initial && mainReady && generation === revision) initial = false;
242
+ // Extend the same pending capture when a main navigation starts; never issue a second screenshot.
243
+ // The frame deadline remains bounded; navigation can extend it only to
244
+ // the separately bounded main-document deadline.
245
+ const documentDeadline = () => initialStop.signal.aborted ? undefined : navigationDeadline;
246
+ if (navigationDeadline !== undefined && performance.now() >= navigationDeadline)
247
+ throw new Error('Navigated main document capture timed out after 30000ms');
248
+ const timeout = initial ? remaining() : Math.min(frameTimeout, Math.max(0, (documentDeadline() ?? Infinity) - performance.now()));
249
+ const png = await capture(cdp, false, timeout, initial ? initialStop.signal : undefined, initial ? undefined : documentDeadline);
250
+ if (navigationDeadline !== undefined && performance.now() >= navigationDeadline)
251
+ throw new Error('Navigated main document capture timed out after 30000ms');
252
+ // Only a capture begun after this document's DCL may restore steady-frame deadlines.
253
+ if (mainReady && generation === revision && !pendingLoader) {
254
+ initial = false;
255
+ navigationDeadline = undefined;
256
+ }
218
257
  if (png.readUInt32BE(16) !== width || png.readUInt32BE(20) !== height) {
219
258
  throw new Error('The viewport size changed during recording');
220
259
  }
@@ -239,6 +278,7 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
239
278
  await write(await sample());
240
279
  frames++;
241
280
  if (initial) throw new Error('Recording ended before the first main document capture');
281
+ if (navigationDeadline !== undefined) throw new Error('Recording ended before the navigated main document capture');
242
282
  encoder.stdin.end();
243
283
  const code = await bounded(closed, 5000, 'FFmpeg finalization');
244
284
  if (code !== 0) throw new Error(spawnError?.message ?? `FFmpeg exited with ${code}: ${diagnostics.trim()}`);
@@ -255,6 +295,7 @@ export async function recordVideo(cdp, { path, fps = 10, duration = 10, ffmpeg =
255
295
  } finally {
256
296
  initialStop.abort();
257
297
  signal?.removeEventListener('abort', abortInitial);
298
+ cdp.off('Page.frameStartedNavigating', starting);
258
299
  cdp.off('Page.frameNavigated', navigated);
259
300
  cdp.off('Page.lifecycleEvent', lifecycle);
260
301
  cdp.off('Inspector.detached', detached);
package/bin/source.tar.gz CHANGED
Binary file
@@ -0,0 +1,55 @@
1
+ import {spawn} from 'node:child_process';
2
+ import {createServer} from 'node:http';
3
+ import {createServer as createPort} from 'node:net';
4
+ import {join} from 'node:path';
5
+ import {pathToFileURL} from 'node:url';
6
+
7
+ /** Release gate over the package's exact executable and existing bundled CDP transport. */
8
+ export async function verifyNativeDebugger(directory) {
9
+ const {connect}=await import(pathToFileURL(join(directory,'lightpanda-capture.mjs')).href);
10
+ const script='function calculate(){\n const selected=21;\n const doubled=selected*2;\n globalThis.guardResult=doubled;\n return doubled;\n}\n';
11
+ const http=createServer((req,res)=>{res.setHeader('content-type',req.url==='/guard.js'?'text/javascript':'text/html');res.end(req.url==='/guard.js'?script:'<script src="/guard.js"></script>');});
12
+ await new Promise((resolve,reject)=>{http.once('error',reject);http.listen(0,'127.0.0.1',resolve);});
13
+ const portOwner=createPort();
14
+ await new Promise((resolve,reject)=>{portOwner.once('error',reject);portOwner.listen(0,'127.0.0.1',resolve);});
15
+ const port=portOwner.address().port;await new Promise(resolve=>portOwner.close(resolve));
16
+ const child=spawn(join(directory,'lightpanda'),['serve','--host','127.0.0.1','--port',String(port)],{stdio:['ignore','ignore','ignore'],env:{...process.env,LIGHTPANDA_DISABLE_TELEMETRY:'true',LIGHTPANDA_DISABLE_CORE_DUMP:'true'}});
17
+ let cdp,sessionId,paused=false,killTimer;let startupError;
18
+ child.once('error',error=>{startupError=error;});
19
+ const bounded=async(task,ms=3000)=>{let timer;try{return await Promise.race([task,new Promise((_,reject)=>{timer=setTimeout(()=>reject(new Error('Native debugger release guard deadline')),ms);})]);}finally{clearTimeout(timer);}};
20
+ const once=(method)=>{let listener;const task=new Promise(resolve=>{listener=value=>{cdp.off(method,listener,sessionId);resolve(value);};cdp.on(method,listener,sessionId);});return {task,cancel:()=>cdp.off(method,listener,sessionId)};};
21
+ const check=(value,message)=>{if(!value)throw new Error(message);};
22
+ try {
23
+ const until=Date.now()+8000;
24
+ while(!cdp&&Date.now()<until){if(startupError)throw startupError;if(child.exitCode!==null)throw new Error('Native debugger guard engine exited');try{cdp=await connect(`ws://127.0.0.1:${port}`,300);}catch{await new Promise(resolve=>setTimeout(resolve,40));}}
25
+ check(cdp,'Native debugger guard engine did not become ready');
26
+ const target=await cdp.send('Target.createTarget',{url:'about:blank'});
27
+ ({sessionId}=await cdp.send('Target.attachToTarget',{targetId:target.targetId,flatten:true}));
28
+ const send=(method,params={})=>cdp.send(method,params,sessionId);
29
+ await send('Page.enable');await send('Runtime.enable');await send('Debugger.enable');
30
+ const loaded=once('Page.loadEventFired');
31
+ try{await send('Page.navigate',{url:`http://127.0.0.1:${http.address().port}/`});await bounded(loaded.task);}finally{loaded.cancel();}
32
+ const armed=await send('Debugger.setBreakpointByUrl',{url:`http://127.0.0.1:${http.address().port}/guard.js`,lineNumber:3,condition:'selected === 21 && doubled === 42'});
33
+ check(armed.breakpointId,'Native debugger guard breakpoint was not installed');
34
+ const first=once('Debugger.paused');
35
+ const action=send('Runtime.evaluate',{expression:'calculate()',returnByValue:true});void action.catch(()=>{});
36
+ let pause;
37
+ try{pause=await bounded(first.task);paused=true;}finally{first.cancel();}
38
+ const frame=pause.callFrames.find(frame=>frame.functionName==='calculate');check(frame,'Native debugger guard did not pause in the actual conditional frame');
39
+ const capabilities=await send('LP.debugCapabilities');check(capabilities.pauseTransport===true,'CDP unavailable while native JavaScript paused');
40
+ const values=await send('Debugger.evaluateOnCallFrame',{callFrameId:frame.callFrameId,expression:'[selected,doubled]',returnByValue:true,throwOnSideEffect:true,silent:true});
41
+ check(JSON.stringify(values.result?.value)==='[21,42]','Native debugger guard selected locals differ');
42
+ const stepped=once('Debugger.paused');
43
+ try{await send('Debugger.stepOver');pause=await bounded(stepped.task);}finally{stepped.cancel();}
44
+ check(pause.callFrames.some(frame=>frame.functionName==='calculate'),'Native debugger guard step lost the live frame');
45
+ await send('Debugger.resume');paused=false;const completed=await bounded(action);
46
+ check(completed.result?.value===42,'Native debugger guard action did not finish after resume');
47
+ const readback=await send('Runtime.evaluate',{expression:'globalThis.guardResult',returnByValue:true});check(readback.result?.value===42,'Native debugger guard result mismatch');
48
+ await send('Debugger.removeBreakpoint',{breakpointId:armed.breakpointId});
49
+ } finally {
50
+ if(paused&&cdp&&sessionId)await cdp.send('Debugger.resume',{},sessionId).catch(()=>{});
51
+ cdp?.close();
52
+ if(child.exitCode===null&&child.signalCode===null){const exit=new Promise(resolve=>child.once('exit',resolve));child.kill('SIGTERM');killTimer=setTimeout(()=>child.kill('SIGKILL'),1000);try{await bounded(exit,2500);}finally{clearTimeout(killTimer);}}
53
+ await new Promise(resolve=>http.close(resolve));
54
+ }
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@app-studio/qa-browser-darwin-arm64",
3
- "version": "0.11.3",
3
+ "version": "0.11.6",
4
4
  "description": "Studio native CSS Lightpanda binary",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-or-later",
@@ -21,6 +21,7 @@
21
21
  "index.js",
22
22
  "index.d.ts",
23
23
  "verify.mjs",
24
+ "debugger-guard.mjs",
24
25
  "README.md"
25
26
  ],
26
27
  "publishConfig": {
package/verify.mjs CHANGED
@@ -12,3 +12,7 @@ for (const name of ['lightpanda', 'lightpanda-capture.mjs', 'lightpanda-scenario
12
12
  }
13
13
  const recorder = await import(pathToFileURL(join(root, 'bin/lightpanda-capture.mjs')).href);
14
14
  if (typeof recorder.encodeFrames !== 'function') throw new Error(`Native package ${pkg.name} recorder is missing encodeFrames. Adopt a complete native bundle; JavaScript helpers do not require Zig.`);
15
+
16
+ // Mandatory effect gate for stage, default prepack and extracted-package verification.
17
+ const {verifyNativeDebugger} = await import('./debugger-guard.mjs');
18
+ await verifyNativeDebugger(join(root, 'bin'));