-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcapture-snippet-api.ts
More file actions
74 lines (58 loc) · 2.61 KB
/
capture-snippet-api.ts
File metadata and controls
74 lines (58 loc) · 2.61 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
import { connectToSuperhuman, disconnect, openCompose, closeCompose } from "./src/superhuman-api";
async function main() {
const conn = await connectToSuperhuman(9333);
if (!conn) { console.log("No connection"); process.exit(1); }
const capturedRequests: any[] = [];
// Enable network monitoring
await conn.Network.enable({});
// Capture all requests
conn.Network.requestWillBeSent((params) => {
const url = params.request.url;
// Filter for Superhuman backend calls
if (url.includes("superhuman") || url.includes("snippet") || url.includes("phrase") || url.includes("template")) {
capturedRequests.push({
url,
method: params.request.method,
postData: params.request.postData?.slice(0, 500),
type: params.type
});
}
});
// Also capture responses
conn.Network.responseReceived((params) => {
const url = params.response.url;
if (url.includes("snippet") || url.includes("phrase") || url.includes("template")) {
console.log("Response:", url, params.response.status);
}
});
console.log("Network monitoring enabled. Opening compose and triggering snippets...\n");
// Open compose
const draftKey = await openCompose(conn);
console.log("Opened compose:", draftKey);
await new Promise(r => setTimeout(r, 500));
// Trigger "g ;" to open snippets (or just ";")
console.log("Pressing g ; to open snippets...");
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: "g", code: "KeyG", text: "g" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: "g", code: "KeyG" });
await new Promise(r => setTimeout(r, 100));
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: ";", code: "Semicolon", text: ";" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: ";", code: "Semicolon" });
// Wait for network activity
await new Promise(r => setTimeout(r, 2000));
// Also try just ";" in the body
console.log("Pressing ; in body...");
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: ";", code: "Semicolon", text: ";" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: ";", code: "Semicolon" });
await new Promise(r => setTimeout(r, 2000));
// Press Escape to close any popup
await conn.Input.dispatchKeyEvent({ type: "keyDown", key: "Escape", code: "Escape" });
await conn.Input.dispatchKeyEvent({ type: "keyUp", key: "Escape", code: "Escape" });
console.log("\n=== Captured Requests ===");
console.log(JSON.stringify(capturedRequests, null, 2));
// Close compose
if (draftKey) {
await closeCompose(conn, draftKey);
}
await disconnect(conn);
}
main().catch(console.error);