donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
56 lines • 2.12 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SetDonobuAnnotations = void 0;
const v4_1 = require("zod/v4");
const JsonUtils_1 = require("../utils/JsonUtils");
/**
* A binding that sets or unsets the annotations on the page executing this callback.
* This is used for debugging purposes to show the interactable elements on the page
* as understood by the Donobu engine.
*/
class SetDonobuAnnotations {
static async register(pageInspector, browserContext) {
const instance = new SetDonobuAnnotations(pageInspector);
try {
await browserContext.exposeBinding(instance.name(), instance.call.bind(instance));
}
catch (_error) {
// This means the binding has already been registered.
}
return instance;
}
constructor(pageInspector) {
this.pageInspector = pageInspector;
}
name() {
return SetDonobuAnnotations.NAME;
}
async call(source, ...args) {
let isToggled;
try {
isToggled = v4_1.z.boolean().parse(args[0]);
}
catch (error) {
await source.page.evaluate((message) => {
console.error(message);
}, `First argument must be a boolean value: ${error.message}`);
return;
}
if (isToggled) {
await this.pageInspector.attributeInteractableElements(source.page);
await this.pageInspector.annotateInteractableElements(source.page);
const elements = await this.pageInspector.getAttributedInteractableElements(source.page);
const message = JSON.stringify(JsonUtils_1.JsonUtils.objectToJson(elements), null, 2);
await source.page.evaluate((message) => {
console.info(message);
}, message);
}
else {
await this.pageInspector.removeDonobuAnnotations(source.page);
}
return;
}
}
exports.SetDonobuAnnotations = SetDonobuAnnotations;
SetDonobuAnnotations.NAME = '__donobuSetAnnotations';
//# sourceMappingURL=SetDonobuAnnotations.js.map