跳到主要內容

TimeoutError (逾時錯誤)

每當特定操作因逾時而終止時,例如 locator.waitFor()browserType.launch(),就會發出 TimeoutError。

const playwright = require('playwright');

(async () => {
const browser = await playwright.chromium.launch();
const context = await browser.newContext();
const page = await context.newPage();
try {
await page.locator('text=Foo').click({
timeout: 100,
});
} catch (error) {
if (error instanceof playwright.errors.TimeoutError)
console.log('Timeout!');
}
await browser.close();
})();