got it to work
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import playwright from 'playwright-core';
|
||||
|
||||
async function main() {
|
||||
const uuid = process.env.CDP_UUID || '550e8400-e29b-41d4-a716-446655440000';
|
||||
const cdpEndpoint = `ws://localhost:9988/cdp/${uuid}`
|
||||
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}`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close();
|
||||
}
|
||||
|
||||
main()
|
||||
@@ -5,6 +5,6 @@ async function main() {
|
||||
const { browserContext, close } = await createExtensionContext(
|
||||
controller.signal,
|
||||
)
|
||||
|
||||
|
||||
}
|
||||
|
||||
main()
|
||||
|
||||
@@ -75,7 +75,7 @@ export class CDPRelayServer {
|
||||
this._wsHost = httpAddressToString(server.address()).replace(/^http/, 'ws');
|
||||
|
||||
|
||||
const uuid = crypto.randomUUID();
|
||||
const uuid = process.env.CDP_UUID || crypto.randomUUID();
|
||||
this._cdpPath = `/cdp/${uuid}`;
|
||||
this._extensionPath = `/extension/${uuid}`;
|
||||
|
||||
@@ -227,7 +227,9 @@ export class CDPRelayServer {
|
||||
if (sessionId)
|
||||
break;
|
||||
// Simulate auto-attach behavior with real target info
|
||||
const { targetInfo } = await this._extensionConnection!.send('attachToTab', { });
|
||||
if (!this._extensionConnection)
|
||||
throw new Error('Extension not connected. Please ensure the Chrome extension is installed and connected to the extension endpoint before connecting Playwright.');
|
||||
const { targetInfo } = await this._extensionConnection.send('attachToTab', { });
|
||||
this._connectedTabInfo = {
|
||||
targetInfo,
|
||||
sessionId: `pw-tab-${this._nextSessionId++}`,
|
||||
|
||||
@@ -40,6 +40,8 @@ export async function createExtensionContext(abortSignal: AbortSignal, ): Promis
|
||||
|
||||
// TODO simply call fetch. it was creatign a full fledged browser just to fetch an url previously. CRAZY
|
||||
// await cdpRelayServer.ensureExtensionConnectionForMCPContext(clientInfo, abortSignal, toolName);
|
||||
// await waitForExtension()
|
||||
return {}
|
||||
const browser = await playwright.chromium.connectOverCDP(cdpRelayServer.cdpEndpoint());
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user