-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug-multiple-drafts.ts
More file actions
95 lines (81 loc) · 2.77 KB
/
debug-multiple-drafts.ts
File metadata and controls
95 lines (81 loc) · 2.77 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
87
88
89
90
91
92
93
94
95
import { connectToSuperhuman, disconnect } from "./src/superhuman-api";
async function debugMultipleDrafts() {
console.log("=== DEBUG: Multiple Draft Detection ===\n");
const conn = await connectToSuperhuman(9333, true);
if (!conn) {
console.error("Failed to connect");
return;
}
// First, check how many drafts currently exist
const initialCheck = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
if (!cfc) return { error: "No cfc" };
const keys = Object.keys(cfc).filter(k => k.startsWith('draft'));
return {
draftCount: keys.length,
draftKeys: keys,
firstKey: keys.find(k => k.startsWith('draft')),
lastKey: keys[keys.length - 1]
};
})()
`,
returnByValue: true
});
console.log("1. Initial state:");
console.log(JSON.stringify(initialCheck.result.value, null, 2));
// Try opening a compose (the current way)
console.log("\n2. Clicking compose button...");
await conn.Runtime.evaluate({
expression: `document.querySelector('.ThreadListView-compose')?.click()`,
});
await new Promise(r => setTimeout(r, 2000));
// Check again
const afterOpen = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
if (!cfc) return { error: "No cfc" };
const keys = Object.keys(cfc).filter(k => k.startsWith('draft'));
// Get info about each draft
const drafts = keys.map(key => {
const ctrl = cfc[key];
const draft = ctrl?.state?.draft;
return {
key,
subject: draft?.subject || "(empty)",
to: (draft?.to || []).map(r => r.email),
body: (draft?.body || "").substring(0, 30)
};
});
return {
draftCount: keys.length,
draftKeys: keys,
firstKey: keys.find(k => k.startsWith('draft')),
lastKey: keys[keys.length - 1],
drafts
};
})()
`,
returnByValue: true
});
console.log("3. After clicking compose:");
console.log(JSON.stringify(afterOpen.result.value, null, 2));
// The current getDraftKey function
const currentMethod = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
if (!cfc) return null;
const keys = Object.keys(cfc);
return keys.find(k => k.startsWith('draft')) || null;
})()
`,
returnByValue: true
});
console.log("\n4. Current getDraftKey returns:", currentMethod.result.value);
console.log(" (Should be the LAST one if we just opened it)");
await disconnect(conn);
}
debugMultipleDrafts().catch(console.error);