Add onCompleted callback system for guaranteed console log delivery
- Add onCompleted() callback registration in RuntimeMessageBridge - Modify wrapperFunction to call completion callbacks before returning - Update ConsoleRuntimeProvider to immediate send + completion batch pattern - Extract DOWNLOADABLE_FILE_RUNTIME_DESCRIPTION from ATTACHMENTS_RUNTIME_DESCRIPTION - Logs sent immediately (fire-and-forget), unsent logs batched at completion - Ensures all console logs arrive before tool execution completes
This commit is contained in:
@@ -27,6 +27,7 @@ export class RuntimeMessageBridge {
|
||||
private static generateSandboxBridge(sandboxId: string): string {
|
||||
// Returns stringified function that uses window.parent.postMessage
|
||||
return `
|
||||
window.__completionCallbacks = [];
|
||||
window.sendRuntimeMessage = async (message) => {
|
||||
const messageId = 'msg_' + Date.now() + '_' + Math.random().toString(36).substring(2, 9);
|
||||
|
||||
@@ -57,18 +58,25 @@ window.sendRuntimeMessage = async (message) => {
|
||||
}, 30000);
|
||||
});
|
||||
};
|
||||
window.onCompleted = (callback) => {
|
||||
window.__completionCallbacks.push(callback);
|
||||
};
|
||||
`.trim();
|
||||
}
|
||||
|
||||
private static generateUserScriptBridge(sandboxId: string): string {
|
||||
// Returns stringified function that uses chrome.runtime.sendMessage
|
||||
return `
|
||||
window.__completionCallbacks = [];
|
||||
window.sendRuntimeMessage = async (message) => {
|
||||
return await chrome.runtime.sendMessage({
|
||||
...message,
|
||||
sandboxId: ${JSON.stringify(sandboxId)}
|
||||
});
|
||||
};
|
||||
window.onCompleted = (callback) => {
|
||||
window.__completionCallbacks.push(callback);
|
||||
};
|
||||
`.trim();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user