-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathload-extension-cdp.mjs
More file actions
executable file
·70 lines (61 loc) · 2.24 KB
/
Copy pathload-extension-cdp.mjs
File metadata and controls
executable file
·70 lines (61 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env node
/**
* Load extension via Chrome DevTools Protocol Extensions.loadUnpacked
* Requires Chrome with --remote-debugging-pipe and --enable-unsafe-extension-debugging
*/
import { chromium } from 'playwright';
import * as fs from 'path';
const extensionPath = '/tmp/graphiti-test';
console.log('Connecting to Chrome via CDP...');
try {
// Connect to Chrome - try different endpoints
let browser;
try {
browser = await chromium.connectOverCDP('http://127.0.0.1:9222');
} catch (e) {
// Try to get endpoint from chrome-devtools-mcp
const version = await fetch('http://127.0.0.1:9222/json/version').then(r => r.json()).catch(() => null);
if (version?.webSocketDebuggerUrl) {
browser = await chromium.connectOverCDP(version.webSocketDebuggerUrl);
} else {
throw new Error('Could not connect to Chrome. Make sure chrome-devtools-mcp is running.');
}
}
console.log('Connected to Chrome');
// Get CDP session - need to enable Extensions domain first
const context = browser.contexts()[0];
if (!context) {
// Create a page to get CDP session
const page = await browser.newPage();
const client = await page.context().newCDPSession(page);
// Enable Extensions domain
try {
await client.send('Runtime.enable');
console.log('Enabled Runtime domain');
} catch (e) {
console.warn('Could not enable Runtime:', e.message);
}
// Try to load extension
console.log('Loading extension via Extensions.loadUnpacked...');
try {
const result = await client.send('Extensions.loadUnpacked', {
path: extensionPath
});
console.log('✅ Extension loaded!', result);
} catch (e) {
if (e.message.includes('Method not available')) {
console.error('❌ Extensions domain not available.');
console.error('Chrome needs to be started with:');
console.error(' --remote-debugging-pipe');
console.error(' --enable-unsafe-extension-debugging');
console.error('\nFor chrome-devtools-mcp, you may need to manually load the extension.');
} else {
throw e;
}
}
await browser.close();
}
} catch (error) {
console.error('❌ Failed:', error.message);
process.exit(1);
}