Repository navigation
Expand file tree
/
Copy pathnetwork-intercept.ts
More file actions
86 lines (70 loc) · 2.33 KB
/
Copy pathnetwork-intercept.ts
File metadata and controls
86 lines (70 loc) · 2.33 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/**
* Network monitor - capture all requests when triggering snippet picker
*/
import WebSocket from "ws";
const CDP_URL = "http://localhost:9333";
async function getSuperhuman() {
const response = await fetch(`${CDP_URL}/json`);
const targets: any[] = await response.json();
return targets.find(t =>
t.url.includes("mail.superhuman.com") &&
!t.url.includes("background") &&
t.webSocketDebuggerUrl
);
}
async function monitor() {
console.log("=== Network Monitor for Snippet Loading ===\n");
const target = await getSuperhuman();
if (!target) {
console.error("Superhuman not found");
process.exit(1);
}
console.log(`Connected to: ${target.title}\n`);
console.log("Now go trigger g ; from inbox. Press Ctrl+C to stop.\n");
console.log("-".repeat(60) + "\n");
const ws = new WebSocket(target.webSocketDebuggerUrl!);
let msgId = 0;
const send = (method: string, params: any = {}): number => {
const id = ++msgId;
ws.send(JSON.stringify({ id, method, params }));
return id;
};
ws.on("open", () => {
send("Network.enable", {
maxTotalBufferSize: 10000000,
maxResourceBufferSize: 5000000
});
});
ws.on("message", (data: Buffer) => {
const msg = JSON.parse(data.toString());
if (msg.method === "Network.requestWillBeSent") {
const { request } = msg.params;
const { url, method, postData } = request;
// Log ALL requests so we can see what fires when snippet picker opens
const short = url.length > 120 ? url.slice(0, 120) + "..." : url;
console.log(`[REQ] ${method} ${short}`);
if (postData) {
try {
const body = JSON.parse(postData);
console.log(` BODY: ${JSON.stringify(body).slice(0, 500)}`);
} catch {
console.log(` BODY (raw): ${postData.slice(0, 300)}`);
}
}
}
if (msg.method === "Network.responseReceived") {
const { response } = msg.params;
const { url, status } = response;
if (url.includes("snippet") || url.includes("setting") || url.includes("firebase") ||
url.includes("firestore") || url.includes("superhuman")) {
console.log(`[RES] ${status} ${url.slice(0, 120)}`);
}
}
});
process.on("SIGINT", () => {
console.log("\n\nDone.");
ws.close();
process.exit(0);
});
}
monitor().catch(console.error);