提问人:as07 提问时间:11/14/2023 最后编辑:as07 更新时间:11/14/2023 访问量:30
尝试运行 Lighthouse 用户流时出错
Error while trying to run Lighthouse user flows
问:
我正在尝试从灯塔文档(https://github.com/GoogleChrome/lighthouse/blob/main/docs/user-flows.md)复制示例代码 我感兴趣的代码块是完整的用户流代码。
import {writeFileSync} from 'fs';
import puppeteer from 'puppeteer';
import * as pptrTestingLibrary from 'pptr-testing-library';
import {startFlow} from 'lighthouse';
const {getDocument, queries} = pptrTestingLibrary;
async function search(page) {
const $document = await getDocument(page);
const $searchBox = await queries.getByLabelText($document, /type to search/i);
await $searchBox.type('Xbox Series X');
await Promise.all([
$searchBox.press('Enter'),
page.waitForNavigation({waitUntil: ['load', 'networkidle2']}),
]);
}
// Setup the browser and Lighthouse.
const browser = await puppeteer.launch();
const page = await browser.newPage();
const flow = await startFlow(page);
// Phase 1 - Navigate to the landing page.
await flow.navigate('https://www.bestbuy.com');
// Phase 2 - Interact with the page and submit the search form.
await flow.startTimespan();
await search(page);
await flow.endTimespan();
// Phase 3 - Analyze the new state.
await flow.snapshot();
// Phase 4 - Navigate to a detail page.
await flow.navigate(async () => {
const $document = await getDocument(page);
const $link = await queries.getByText($document, /Xbox Series X 1TB Console/);
$link.click();
});
// Get the comprehensive flow report.
writeFileSync('report.html', await flow.generateReport());
// Save results as JSON.
writeFileSync('flow-result.json', JSON.stringify(await flow.createFlowResult(), null, 2));
// Cleanup.
await browser.close();
这给了我以下错误: 节点:internal/process/esm_loader:108 internalBinding('errors').triggerUncaughtException( ^
TypeError:containerHandle.executionContext 不是函数
我已经测试了我的代码,发现问题出在我运行 queries.getByLabelText 和 queries.getByText 的行上。但是,我不确定如何从这里开始。我正在使用 lighthouse:11.3.0、puppeteer:21.5.1 和 pptr-testing-library:0.7.0。我的package.json文件在下面列出,以防相关。
{
"type": "module",
"devDependencies": {
"lighthouse": "^11.3.0",
"pptr-testing-library": "^0.7.0"
},
"dependencies": {
"puppeteer": "^21.5.1"
}
}
我还尝试使用其他方法(例如getByPlaceholderText)从网页中获取指定的文本框,但这些方法给了我同样的错误。
答: 暂无答案
评论