-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpostmessage-debug-test.js
More file actions
85 lines (67 loc) · 2.51 KB
/
postmessage-debug-test.js
File metadata and controls
85 lines (67 loc) · 2.51 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
// PostMessage Debug Test - Direct component communication test
console.log('🔧 Starting PostMessage Debug Test...');
// Test 1: Send a simple ping to see if component responds
function testComponentPing() {
console.log('📤 Sending ping to component...');
// Send to current window (component might be listening here)
window.postMessage({
type: 'RETOOL_COMPONENT_COMMAND',
action: 'ping',
payload: { test: 'ping from debug test' },
id: 'debug_ping_' + Date.now()
}, '*');
console.log('✅ Ping sent to current window');
}
// Test 2: Listen for any PostMessage responses (filtered to avoid loops)
function setupResponseListener() {
console.log('👂 Setting up response listener...');
window.addEventListener('message', (event) => {
// Only log component responses, not our own commands
if (event.data && event.data.type === 'RETOOL_COMPONENT_RESPONSE') {
console.log('🎉 COMPONENT RESPONDED!', event.data);
} else if (event.data && event.data.type === 'RETOOL_COMPONENT_READY') {
console.log('🎉 COMPONENT READY SIGNAL!', event.data);
}
// Don't log RETOOL_COMPONENT_COMMAND to avoid infinite loops
});
console.log('✅ Response listener active');
}
// Test 3: Send setConfig directly to current window
function testDirectSetConfig() {
console.log('📤 Sending setConfig directly to current window...');
window.postMessage({
type: 'RETOOL_COMPONENT_COMMAND',
action: 'setConfig',
payload: {
type: "checkbox",
rows: ["DEBUG TEST QUESTION"],
columns: ["YES", "NO"]
},
id: 'debug_setconfig_' + Date.now()
}, '*');
console.log('✅ SetConfig sent to current window');
}
// Run all tests
function runDebugTests() {
console.log('🚀 Running PostMessage Debug Tests...\n');
// Setup listener first
setupResponseListener();
// Wait a moment, then send ping
setTimeout(() => {
testComponentPing();
}, 500);
// Wait another moment, then send setConfig
setTimeout(() => {
testDirectSetConfig();
}, 1000);
console.log('⏱️ Tests scheduled - watch for responses...');
}
// Make functions available globally
window.testComponentPing = testComponentPing;
window.setupResponseListener = setupResponseListener;
window.testDirectSetConfig = testDirectSetConfig;
window.runDebugTests = runDebugTests;
console.log('✅ PostMessage Debug Test loaded');
console.log('🧪 Run: runDebugTests()');
// Don't auto-run to avoid loops
console.log('🚨 Manual run only - call runDebugTests() when ready');