跳到正文
本页尚未翻译成中文,以下为英文原文。 查看英文版

TimeoutError ​

Added in: v1.8

Extends: Error

  • extends: [Error]

TimeoutError is emitted whenever certain operations are terminated due to timeout, e.g. locator.waitFor() or browserType.launch().

js
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();
})();

基于 Apache 2.0 许可证发布。