MCPcopy
hub / github.com/coder/mux / captureSwitch

Function captureSwitch

scripts/reproWorkspaceSwitchTearWeb.ts:261–312  ·  view source on GitHub ↗
(args: {
  page: Page;
  sourceMarker: string;
  targetMarker: string;
  clickWorkspaceId: string;
  outputDir: string;
  framePrefix: string;
})

Source from the content-addressed store, hash-verified

259}
260
261async function captureSwitch(args: {
262 page: Page;
263 sourceMarker: string;
264 targetMarker: string;
265 clickWorkspaceId: string;
266 outputDir: string;
267 framePrefix: string;
268}): Promise<SwitchFrameSample[]> {
269 const row = args.page.locator(
270 `[data-workspace-id="${args.clickWorkspaceId}"][data-workspace-path]`
271 );
272 await row.waitFor({ state: "visible", timeout: 60_000 });
273 await row.scrollIntoViewIfNeeded();
274 await row.dispatchEvent("click");
275
276 const messageWindow = args.page.locator('[data-testid="message-window"]');
277 const frames: SwitchFrameSample[] = [];
278 for (let frame = 0; frame < 12; frame++) {
279 if (frame > 0) await args.page.waitForTimeout(40);
280 await messageWindow.waitFor({ state: "visible", timeout: 60_000 });
281 const imagePath = path.join(
282 args.outputDir,
283 `${args.framePrefix}-${String(frame).padStart(2, "0")}.png`
284 );
285 const [snapshot, png] = await Promise.all([
286 args.page.evaluate(
287 ({ sourceMarker, targetMarker, frame }) => {
288 const messageWindow = document.querySelector('[data-testid="message-window"]');
289 const chatInputSection = document.querySelector(
290 '[data-component="ChatInputSection"]'
291 ) as HTMLElement | null;
292 const rect = messageWindow?.getBoundingClientRect();
293 const text = messageWindow?.textContent ?? "";
294 return {
295 frame,
296 timestamp: performance.now(),
297 containsTargetMarker: text.includes(targetMarker),
298 containsSourceMarker: text.includes(sourceMarker),
299 messageWindowTop: rect?.top ?? null,
300 messageWindowHeight: rect?.height ?? null,
301 scrollTop: messageWindow instanceof HTMLDivElement ? messageWindow.scrollTop : null,
302 chatInputHeight: chatInputSection?.getBoundingClientRect().height ?? null,
303 };
304 },
305 { sourceMarker: args.sourceMarker, targetMarker: args.targetMarker, frame }
306 ),
307 messageWindow.screenshot({ path: imagePath }),
308 ]);
309 frames.push({ ...snapshot, imagePath, png });
310 }
311 return frames;
312}
313
314function detectInputDisappearances(frames: OpenTransitionFrameSample[]) {
315 const disappearances = [] as Array<{

Callers 1

mainFunction · 0.85

Calls 5

waitForMethod · 0.80
dispatchEventMethod · 0.80
getBoundingClientRectMethod · 0.65
pushMethod · 0.65
screenshotMethod · 0.45

Tested by

no test coverage detected