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

Function captureOpenTransition

scripts/reproWorkspaceSwitchTearWeb.ts:202–259  ·  view source on GitHub ↗
(args: {
  page: Page;
  clickWorkspaceId: string;
  targetMarker: string;
})

Source from the content-addressed store, hash-verified

200}
201
202async function captureOpenTransition(args: {
203 page: Page;
204 clickWorkspaceId: string;
205 targetMarker: string;
206}): Promise<OpenTransitionFrameSample[]> {
207 const row = args.page.locator(
208 `[data-workspace-id="${args.clickWorkspaceId}"][data-workspace-path]`
209 );
210 await row.waitFor({ state: "visible", timeout: 60_000 });
211 await row.scrollIntoViewIfNeeded();
212 await args.page.evaluate((targetMarker: string) => {
213 (
214 window as Window & {
215 __muxOpenTransitionFramesPromise?: Promise<OpenTransitionFrameSample[]>;
216 }
217 ).__muxOpenTransitionFramesPromise = new Promise((resolve) => {
218 const frames: OpenTransitionFrameSample[] = [];
219 let frame = 0;
220 const step = () => {
221 const inputSection = document.querySelector(
222 '[data-component="ChatInputSection"]'
223 ) as HTMLElement | null;
224 const messageWindow = document.querySelector(
225 '[data-testid="message-window"]'
226 ) as HTMLElement | null;
227 const bodyText = document.body.textContent ?? "";
228 frames.push({
229 frame,
230 timestamp: performance.now(),
231 hasInput: inputSection !== null,
232 chatInputHeight: inputSection?.getBoundingClientRect().height ?? null,
233 hasMessageWindow: messageWindow !== null,
234 messageWindowHeight: messageWindow?.getBoundingClientRect().height ?? null,
235 containsTargetMarker: bodyText.includes(targetMarker),
236 loadingWorkspace: bodyText.includes("Loading workspace..."),
237 loadingTranscript: bodyText.includes("Loading transcript..."),
238 });
239 frame += 1;
240 if (frame < 20) {
241 requestAnimationFrame(step);
242 } else {
243 resolve(frames);
244 }
245 };
246 requestAnimationFrame(step);
247 });
248 }, args.targetMarker);
249 await row.dispatchEvent("click");
250 return await args.page.evaluate(() => {
251 return (
252 (
253 window as Window & {
254 __muxOpenTransitionFramesPromise?: Promise<OpenTransitionFrameSample[]>;
255 }
256 ).__muxOpenTransitionFramesPromise ?? Promise.resolve([])
257 );
258 });
259}

Callers 1

mainFunction · 0.85

Calls 3

waitForMethod · 0.80
dispatchEventMethod · 0.80
resolveMethod · 0.80

Tested by

no test coverage detected