-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdebug-enqueue-modifier.ts
More file actions
108 lines (87 loc) · 3.47 KB
/
debug-enqueue-modifier.ts
File metadata and controls
108 lines (87 loc) · 3.47 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
import { connectToSuperhuman, disconnect, openCompose, setSubject, addRecipient, setBody, textToHtml } from "./src/superhuman-api";
async function debugEnqueueModifier() {
console.log("=== Examining enqueueModifier ===\n");
const conn = await connectToSuperhuman(9333, true);
if (!conn) {
console.error("Failed to connect");
return;
}
// Network monitoring
await conn.Network.enable();
let allRequests: any[] = [];
conn.Network.requestWillBeSent((params) => {
allRequests.push({
time: Date.now(),
url: params.request.url.substring(0, 150),
method: params.request.method,
postData: params.request.postData?.substring(0, 200)
});
});
const draftKey = await openCompose(conn);
console.log(`1. Opened compose: ${draftKey}`);
await addRecipient(conn, "modifier-test@test.com", undefined, draftKey!);
await setSubject(conn, "Modifier Test", draftKey!);
await setBody(conn, textToHtml("Modifier test body"), draftKey!);
console.log("2. Populated draft");
allRequests = [];
// Examine enqueueModifier
const result = await conn.Runtime.evaluate({
expression: `
(async () => {
const cfc = window.ViewState?._composeFormController;
const draftKey = ${JSON.stringify(draftKey)};
const ctrl = cfc[draftKey];
const draft = ctrl.state.draft;
const props = ctrl.props;
const account = props.account;
const presenter = account.threads.getPresenter(ctrl.state.draftOp, draft.threadId);
// Check enqueueModifier
const enqueueModifierSource = presenter?.enqueueModifier?.toString?.().substring(0, 1000);
// Check what saveDraft modifier does
// First find the Jn.a.saveDraft (or equivalent) class
const modifiers = presenter?.modifiers;
const modifierQueue = presenter?._modifierQueue;
const pendingModifiers = presenter?._pendingModifiers;
// Try to trace what happens when we call saveDraft
let traceResult = null;
try {
// Override enqueueModifier temporarily to see what modifier is created
const originalEnqueue = presenter.enqueueModifier.bind(presenter);
let capturedModifier = null;
presenter.enqueueModifier = function(modifier, updateOutputs) {
capturedModifier = {
type: modifier?.constructor?.name,
keys: Object.keys(modifier || {}),
updateOutputs
};
return originalEnqueue(modifier, updateOutputs);
};
await presenter.saveDraft(draft, { saveAttachments: false, updateOutputs: false });
// Restore
presenter.enqueueModifier = originalEnqueue;
traceResult = capturedModifier;
} catch (e) {
traceResult = { error: e.message };
}
return {
enqueueModifierSource,
modifiersCount: modifiers?.length,
modifierQueueCount: modifierQueue?.length,
pendingModifiersCount: pendingModifiers?.length,
traceResult
};
})()
`,
returnByValue: true,
awaitPromise: true
});
console.log("\n3. enqueueModifier analysis:");
console.log(JSON.stringify(result.result.value, null, 2));
// Wait for network
await new Promise(r => setTimeout(r, 3000));
console.log("\n4. All network requests:");
console.log(JSON.stringify(allRequests, null, 2));
await conn.Network.disable();
await disconnect(conn);
}
debugEnqueueModifier().catch(console.error);