This commit is contained in:
seb
2026-10-08 04:45:35 +02:00
parent b01ebccf90
commit ec238c7b50
5 changed files with 200 additions and 43 deletions

View File

@@ -161,7 +161,7 @@ async function httpJson(url, options = {}) {
* Opens a new page target on the browser, navigates, waits for the app root
* to contain content + network to quiet down, captures a PNG.
*/
export async function capturePage(debugPort, url, file, { width, height, settleMs = 6000 }) {
export async function capturePage(debugPort, url, file, { width, height, settleMs = 6000, dialog }) {
// Chrome ≥136 requires PUT for /json/new.
const target = await httpJson(`http://127.0.0.1:${debugPort}/json/new?${encodeURIComponent(url)}`, {
method: 'PUT',
@@ -205,6 +205,58 @@ export async function capturePage(debugPort, url, file, { width, height, settleM
// Extra quiet period for images / thumbhash decode / layout.
await wait(settleMs);
// If a dialog needs to be opened before capturing:
if (dialog) {
if (dialog.name === 'settings') {
// Open user avatar menu
await session.send('Runtime.evaluate', {
expression: `(() => {
const btn = document.querySelector('nav .MuiAvatar-root')?.closest('button');
if (btn) btn.click();
})()`,
});
await wait(300);
// Click "Einstellungen" menu item
await session.send('Runtime.evaluate', {
expression: `(() => {
const item = Array.from(document.querySelectorAll('.MuiMenuItem-root'))
.find(el => el.textContent.includes('Einstellungen'));
if (item) item.click();
})()`,
});
await wait(400);
// Click specific tab if requested
if (dialog.tab) {
await session.send('Runtime.evaluate', {
expression: `(() => {
const target = ${JSON.stringify(dialog.tab.toLowerCase())};
const tab = Array.from(document.querySelectorAll('[role="dialog"] [role="tab"]'))
.find(el => el.textContent.trim().toLowerCase() === target || el.textContent.toLowerCase().includes(target));
if (tab) tab.click();
})()`,
});
await wait(300);
}
// Wait for any dialog-internal loading spinners to settle
const dialogDeadline = Date.now() + 15000;
while (Date.now() < dialogDeadline) {
const res = await session.send('Runtime.evaluate', {
expression: `(() => {
const spinners = document.querySelectorAll('[role="dialog"] [role="progressbar"]').length;
return { spinners };
})()`,
returnByValue: true,
});
if ((res.result?.value?.spinners ?? 0) === 0) break;
await wait(300);
}
await wait(800);
}
}
// Determinism: hide carets and scrollbars.
await session.send('Runtime.evaluate', {
expression: `(() => { const s = document.createElement('style');