fix(ci): wait for document bootstrap before browser interactions
creative workspace review checks / verify-deployed-canvas (pull_request) Successful in 1m23s
creative workspace review checks / verify (pull_request) Successful in 24m43s

This commit is contained in:
2026-11-01 21:36:24 +08:00
parent fafdae66bb
commit 517c31ca04
6 changed files with 80 additions and 24 deletions
@@ -30,3 +30,32 @@ export async function navigateBrandDocument(navigate, url, now = Date.now) {
}
throw new Error(`Document navigation failed: ${url}`);
}
/** Load a document fully before relying on server-rendered text or leaving it.
* Only document GETs may recover; application assertions remain outside retry.
* @param {import('playwright-core').Page} page
* @param {string} url
* @param {boolean} reload
*/
export async function visitBrowserDocument(page, url, reload = false) {
const started = Date.now();
const response = await navigateBrandDocument(async timeout => {
const scripts = new Set(), failures = [];
const requested = request => { if (request.resourceType() === 'script') scripts.add(request); };
const failed = request => { if (scripts.has(request)) failures.push(request.failure()?.errorText || 'unknown script failure'); };
page.on('request', requested);
page.on('requestfailed', failed);
try {
const response = await (reload ? page.reload({waitUntil: 'domcontentloaded', timeout}) : page.goto(url, {waitUntil: 'domcontentloaded', timeout}));
if (response?.ok() && failures.length) throw new Error('Document bootstrap script request failed: ' + failures.join('; '));
return response;
} finally {
page.off('request', requested);
page.off('requestfailed', failed);
}
}, url);
const remaining = 60000 - (Date.now() - started);
if (remaining <= 0) throw new Error('Document hydration budget exhausted: ' + url);
await page.locator('button[data-theme-ready="true"]').first().waitFor({timeout: remaining});
return response;
}