new page handling
This commit is contained in:
@@ -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()
|
||||||
@@ -287,7 +287,7 @@ export async function startRelayServer({ port = 9988 }: { port?: number } = {})
|
|||||||
clientId
|
clientId
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error handling CDP command:', e)
|
console.error('Error handling CDP command:', method, params, e)
|
||||||
sendToPlaywright({
|
sendToPlaywright({
|
||||||
message: {
|
message: {
|
||||||
id,
|
id,
|
||||||
|
|||||||
Reference in New Issue
Block a user