Skip to content

Commit 9cbac80

Browse files
ottomaoclaude
andauthored
refactor(report): require data-group-id on dump elements, remove backward compat (#2159)
Drop `buildPlaywrightTaskFromElement` and the ungrouped fallback path. All `<script type="midscene_web_dump">` elements must now have a `data-group-id` attribute; missing it throws an error at parse time. https://claude.ai/code/session_017ir8y83LbmEhoMgshK3zzH Co-authored-by: Claude <noreply@anthropic.com>
1 parent c7a08f5 commit 9cbac80

File tree

1 file changed

+10
-58
lines changed

1 file changed

+10
-58
lines changed

apps/report/src/App.tsx

Lines changed: 10 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -331,49 +331,6 @@ export function App() {
331331
return attributes as PlaywrightTaskAttributes;
332332
}
333333

334-
/**
335-
* Build a PlaywrightTasks entry from a single dump element (original behavior).
336-
*/
337-
function buildPlaywrightTaskFromElement(el: Element): PlaywrightTasks {
338-
const attributes = parseAttributesFromElement(el);
339-
let cachedJsonContent: GroupedActionDump | null = null;
340-
let isParsed = false;
341-
342-
return {
343-
get: () => {
344-
if (!isParsed) {
345-
try {
346-
console.time('parse_dump');
347-
const content = antiEscapeScriptTag(el.textContent || '');
348-
const parsed = JSON.parse(content);
349-
const restored = restoreImageReferences(
350-
parsed,
351-
resolveImageFromDom,
352-
);
353-
cachedJsonContent = GroupedActionDump.fromJSON(restored);
354-
console.timeEnd('parse_dump');
355-
(cachedJsonContent as any).attributes = attributes;
356-
isParsed = true;
357-
} catch (e) {
358-
console.error(el);
359-
console.error('failed to parse json content', e);
360-
cachedJsonContent = new GroupedActionDump({
361-
sdkVersion: '',
362-
groupName: '',
363-
modelBriefs: [],
364-
executions: [],
365-
});
366-
(cachedJsonContent as any).attributes = attributes;
367-
(cachedJsonContent as any).error = 'Failed to parse JSON content';
368-
isParsed = true;
369-
}
370-
}
371-
return cachedJsonContent!;
372-
},
373-
attributes,
374-
};
375-
}
376-
377334
function getDumpElements(): PlaywrightTasks[] {
378335
const dumpElements = document.querySelectorAll(
379336
'script[type="midscene_web_dump"]',
@@ -386,21 +343,21 @@ export function App() {
386343
return !!textContent;
387344
});
388345

389-
// Group elements by data-group-id
346+
// Group elements by data-group-id (required attribute)
390347
const groupMap = new Map<string, Element[]>();
391-
const ungrouped: Element[] = [];
392348

393349
for (const el of validElements) {
394350
const groupId = el.getAttribute('data-group-id');
395-
if (groupId) {
396-
const decodedGroupId = decodeURIComponent(groupId);
397-
if (!groupMap.has(decodedGroupId)) {
398-
groupMap.set(decodedGroupId, []);
399-
}
400-
groupMap.get(decodedGroupId)!.push(el);
401-
} else {
402-
ungrouped.push(el);
351+
if (!groupId) {
352+
throw new Error(
353+
'Missing required attribute "data-group-id" on <script type="midscene_web_dump"> element',
354+
);
403355
}
356+
const decodedGroupId = decodeURIComponent(groupId);
357+
if (!groupMap.has(decodedGroupId)) {
358+
groupMap.set(decodedGroupId, []);
359+
}
360+
groupMap.get(decodedGroupId)!.push(el);
404361
}
405362

406363
const result: PlaywrightTasks[] = [];
@@ -468,11 +425,6 @@ export function App() {
468425
});
469426
}
470427

471-
// Process ungrouped dump tags — original behavior (backward compatible)
472-
for (const el of ungrouped) {
473-
result.push(buildPlaywrightTaskFromElement(el));
474-
}
475-
476428
return result;
477429
}
478430

0 commit comments

Comments
 (0)