add support for opening page and closing page
This commit is contained in:
@@ -12,12 +12,16 @@ async function main() {
|
||||
for (const context of contexts) {
|
||||
const pages = context.pages()
|
||||
console.log(`Context has ${pages.length} page(s):`)
|
||||
// Create a new page
|
||||
// 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}`)
|
||||
|
||||
// Sleep 1 second
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000))
|
||||
// Close the page
|
||||
await newPage.close()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -195,8 +195,18 @@ export async function startRelayServer({ port = 9988 }: { port?: number } = {})
|
||||
}
|
||||
}
|
||||
|
||||
case 'Target.createTarget': {
|
||||
return await sendToExtension({
|
||||
method: 'forwardCDPCommand',
|
||||
params: { method, params }
|
||||
})
|
||||
}
|
||||
|
||||
case 'Target.closeTarget': {
|
||||
break
|
||||
return await sendToExtension({
|
||||
method: 'forwardCDPCommand',
|
||||
params: { method, params }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user