UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

44 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.installDialogPromptTracker = installDialogPromptTracker; /** * Code intended to run as an initialization script for `DonobuFlow` flows. * This script helps flows handle/track prompts/confirmations. * This is done specially since these browser actions pause the Javascript * main thread and also cause issues with running various Playwright actions. * See `DonobuFlow.onDialog(Dialog)` for details. */ function installDialogPromptTracker() { const dnb = window.__donobu; if (!dnb) { throw new Error('[Donobu] __donobu namespace missing; dialog-prompt-tracker cannot initialize.'); } else if (dnb.dialogPromptTrackerInstalled) { return; } const donobuMagicString = 'DONOBU_DIALOG_RESPONSE'; const originalConsoleLog = window.console.log; const originalPrompt = window.prompt.bind(window); const originalConfirm = window.confirm.bind(window); // Overwrite the global prompt function. window.prompt = (message, defaultValue) => { const response = originalPrompt(message, defaultValue); originalConsoleLog(donobuMagicString, response); originalConsoleLog('prompt response: ' + response); return response; }; // Overwrite the global confirm function. window.confirm = (message) => { const response = originalConfirm(message); originalConsoleLog(donobuMagicString, response); originalConsoleLog('prompt response: ' + response); return response; }; Object.defineProperty(dnb, 'dialogPromptTrackerInstalled', { value: true, enumerable: false, writable: false, configurable: false, }); } //# sourceMappingURL=dialog-prompt-tracker.js.map