fix: use browser.newContext() for axe-core/playwright compatibility

This commit is contained in:
张翔
2026-03-06 10:17:09 +08:00
parent 755e0889a5
commit e82f5b26aa
+4 -1
View File
@@ -5,7 +5,8 @@ const path = require('path');
async function runAxeTest(url, pageName) {
const browser = await chromium.launch();
const page = await browser.newPage();
const context = await browser.newContext();
const page = await context.newPage();
const results = [];
try {
@@ -38,10 +39,12 @@ async function runAxeTest(url, pageName) {
console.log(` ✅ 扫描完成: ${violations.length} 个违规, ${passes} 个通过, ${incomplete} 个未完成`);
await context.close();
await browser.close();
return results[0];
} catch (error) {
await context.close();
await browser.close();
throw new Error(`可访问性测试失败: ${error.message}`);
}