-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-logs.js
More file actions
36 lines (28 loc) · 956 Bytes
/
get-logs.js
File metadata and controls
36 lines (28 loc) · 956 Bytes
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
#!/usr/bin/env node
const WebSocket = require('ws');
const ws = new WebSocket('ws://127.0.0.1:9243/devtools/page/0308AAD721D1A0FB38E9E39CE7FE3BDE');
ws.on('open', function open() {
console.log('Connected to CDP');
// Enable log domain
ws.send(JSON.stringify({ id: 1, method: 'Log.enable' }));
// Also try to get existing console messages
ws.send(JSON.stringify({ id: 2, method: 'Runtime.enable' }));
});
ws.on('message', function incoming(data) {
const msg = JSON.parse(data);
// If it's a console log event, print it
if (msg.method === 'Log.entryAdded') {
console.log('=== CONSOLE LOG:', JSON.stringify(msg.params.entry, null, 2));
} else {
console.log('CDP Message:', JSON.stringify(msg, null, 2));
}
});
ws.on('error', (err) => {
console.error('WebSocket error:', err.message);
});
// Timeout after 10 seconds
setTimeout(() => {
console.log('Timeout - closing');
ws.close();
process.exit(0);
}, 10000);