| 306 | } |
| 307 | |
| 308 | async newPage( |
| 309 | background?: boolean, |
| 310 | isolatedContextName?: string, |
| 311 | ): Promise<McpPage> { |
| 312 | let page: Page; |
| 313 | if (isolatedContextName !== undefined) { |
| 314 | let ctx = this.#isolatedContexts.get(isolatedContextName); |
| 315 | if (!ctx) { |
| 316 | ctx = await this.browser.createBrowserContext(); |
| 317 | this.#isolatedContexts.set(isolatedContextName, ctx); |
| 318 | } |
| 319 | page = await ctx.newPage(); |
| 320 | } else { |
| 321 | page = await this.browser.newPage({background}); |
| 322 | } |
| 323 | await this.createPagesSnapshot(); |
| 324 | this.selectPage(this.#getMcpPage(page)); |
| 325 | this.#networkCollector.addPage(page); |
| 326 | this.#consoleCollector.addPage(page); |
| 327 | return this.#getMcpPage(page); |
| 328 | } |
| 329 | async closePage(pageId: number): Promise<void> { |
| 330 | if (this.#pages.length === 1) { |
| 331 | throw new Error(CLOSE_PAGE_ERROR); |