new page handling

This commit is contained in:
Tommy D. Rossi
2025-11-15 15:55:56 +01:00
parent 36da6a1737
commit 1b0480c77f
2 changed files with 25 additions and 1 deletions
+24
View File
@@ -0,0 +1,24 @@
import playwright from 'playwright-core'
async function main() {
const cdpEndpoint = `ws://localhost:9988/cdp/${Date.now()}`
const browser = await playwright.chromium.connectOverCDP(cdpEndpoint)
const contexts = browser.contexts()
console.log(`Found ${contexts.length} browser context(s)`)
// Sleep 200 ms
await new Promise((resolve) => setTimeout(resolve, 200))
for (const context of contexts) {
const pages = context.pages()
console.log(`Context has ${pages.length} page(s):`)
// Create a new page
const newPage = await context.newPage()
// Evaluate a sum (e.g., 2 + 3) and log the result
const sumResult = await newPage.evaluate(() => 2 + 3)
console.log(`Evaluated sum 2 + 3 = ${sumResult}`)
}
}
main()
+1 -1
View File
@@ -287,7 +287,7 @@ export async function startRelayServer({ port = 9988 }: { port?: number } = {})
clientId
})
} catch (e) {
console.error('Error handling CDP command:', e)
console.error('Error handling CDP command:', method, params, e)
sendToPlaywright({
message: {
id,