Update extension-connect.ts

This commit is contained in:
Tommy D. Rossi
2025-11-13 21:28:47 +01:00
parent 46be331120
commit 339d5d86d3
+8 -10
View File
@@ -3,27 +3,25 @@ import playwright from 'playwright-core';
async function main() {
const cdpEndpoint = `ws://localhost:9988/cdp`
const browser = await playwright.chromium.connectOverCDP(cdpEndpoint);
const contexts = browser.contexts();
console.log(`Found ${contexts.length} browser context(s)`);
for (const context of contexts) {
const pages = context.pages();
console.log(`Context has ${pages.length} page(s):`);
for (const page of pages) {
const url = page.url();
console.log(`\nPage URL: ${url}`);
const html = await page.content();
const lines = html.split('\n').slice(0, 3);
console.log('First 3 lines of HTML:');
lines.forEach((line, i) => {
console.log(` ${i + 1}: ${line}`);
});
const chars = html.slice(0, 30);
console.log('First chars of HTML:');
console.log(chars)
}
}
await browser.close();
}