-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug-actual-network-save.ts
More file actions
130 lines (107 loc) · 4.23 KB
/
debug-actual-network-save.ts
File metadata and controls
130 lines (107 loc) · 4.23 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import { connectToSuperhuman, disconnect, openCompose, setSubject, addRecipient, setBody, textToHtml } from "./src/superhuman-api";
async function debugActualNetworkSave() {
console.log("=== Finding What Triggers Actual Network Save ===\n");
const conn = await connectToSuperhuman(9333, true);
if (!conn) {
console.error("Failed to connect");
return;
}
// Enable network monitoring
await conn.Network.enable();
let networkRequests: any[] = [];
conn.Network.requestWillBeSent((params) => {
networkRequests.push({
time: Date.now(),
url: params.request.url,
method: params.request.method,
postData: params.request.postData?.substring(0, 300)
});
});
const draftKey = await openCompose(conn);
console.log(`1. Opened compose: ${draftKey}`);
// Populate the draft
await addRecipient(conn, "network-save@test.com", undefined, draftKey!);
await setSubject(conn, "Network Save Test", draftKey!);
await setBody(conn, textToHtml("Network save test body"), draftKey!);
console.log("2. Populated draft");
// Check what other save-related methods exist
const methods = await conn.Runtime.evaluate({
expression: `
(() => {
const cfc = window.ViewState?._composeFormController;
const draftKey = ${JSON.stringify(draftKey)};
const ctrl = cfc[draftKey];
const ctrlProto = Object.getPrototypeOf(ctrl);
const ctrlClass = ctrl.constructor;
// Instance methods
const instanceMethods = Object.getOwnPropertyNames(ctrlProto).filter(n =>
n.toLowerCase().includes('save') ||
n.toLowerCase().includes('sync') ||
n.toLowerCase().includes('send') ||
n.toLowerCase().includes('submit') ||
n.toLowerCase().includes('persist') ||
n.toLowerCase().includes('create') ||
n.toLowerCase().includes('upload')
);
// Static methods
const staticMethods = Object.getOwnPropertyNames(ctrlClass).filter(n =>
typeof ctrlClass[n] === 'function' && (
n.toLowerCase().includes('save') ||
n.toLowerCase().includes('sync') ||
n.toLowerCase().includes('send') ||
n.toLowerCase().includes('submit') ||
n.toLowerCase().includes('persist') ||
n.toLowerCase().includes('create')
)
);
return {
instanceMethods,
staticMethods
};
})()
`,
returnByValue: true
});
console.log("3. Available methods:");
console.log(JSON.stringify(methods.result.value, null, 2));
// Try calling the static saveDraft directly
console.log("\n4. Attempting direct static saveDraft call...");
networkRequests = [];
const saveResult = await conn.Runtime.evaluate({
expression: `
(async () => {
const cfc = window.ViewState?._composeFormController;
const draftKey = ${JSON.stringify(draftKey)};
const ctrl = cfc[draftKey];
const ctrlClass = ctrl.constructor;
// Get necessary props
const draft = ctrl.state.draft;
const draftOp = ctrl.state.draftOp;
const props = ctrl.props;
// Check changesAllowed first
const changesAllowed = ctrlClass.changesAllowed(props, ctrl.state);
if (!changesAllowed) {
return { error: "changesAllowed returned false" };
}
// Try calling static saveDraft directly
try {
const result = await ctrlClass.saveDraft(draftOp, draft, props, { saveSource: 'cli-debug' });
return { success: true, result: result === undefined ? "undefined" : result };
} catch (e) {
return { error: e.message, stack: e.stack?.substring(0, 500) };
}
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log("5. Direct saveDraft result:", JSON.stringify(saveResult.result.value, null, 2));
// Wait for network
await new Promise(r => setTimeout(r, 3000));
console.log("\n6. Network requests after direct save:");
const postRequests = networkRequests.filter(r => ['POST', 'PUT', 'PATCH'].includes(r.method));
console.log(JSON.stringify(postRequests.slice(0, 5), null, 2));
await conn.Network.disable();
await disconnect(conn);
}
debugActualNetworkSave().catch(console.error);