菜单
开源

pages()

注意

此功能有 已知问题。详情请参阅 #444

返回 BrowserContext 中所有打开的 Page

返回

类型描述
Array<Page>Page 对象的数组。

示例

JavaScript
import { browser } from 'k6/browser';

export const options = {
  scenarios: {
    browser: {
      executor: 'shared-iterations',
      options: {
        browser: {
          type: 'chromium',
        },
      },
    },
  },
};

export default async function () {
  const context = await browser.newContext();
  await context.newPage();
  const pages = context.pages();
  console.log(pages.length); // 1
  await context.close();
}