donobu
Version:
Create browser automations with an LLM agent and replay them as Playwright scripts.
42 lines • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.webPage = webPage;
exports.webInspector = webInspector;
exports.webTarget = webTarget;
const PageClosedException_1 = require("../exceptions/PageClosedException");
/**
* Extract the Playwright {@link Page} from a web-mode {@link ToolCallContext}.
* Throws if the target is not a web target or the page is closed.
*/
function webPage(context) {
if (context.targetInspector.type !== 'web') {
throw new Error('This tool requires a web target');
}
const target = context.targetInspector.target;
if (!target.current) {
throw new PageClosedException_1.PageClosedException();
}
return target.current;
}
/**
* Narrow the context's {@link TargetInspector} to a {@link WebTargetInspector}.
* Use this when you need access to the underlying {@link PageInspector} for
* web-specific operations (e.g. getHtmlSnippet).
*/
function webInspector(context) {
if (context.targetInspector.type !== 'web') {
throw new Error('This tool requires a web target');
}
return context.targetInspector;
}
/**
* Narrow the context's target to a mutable {@link WebTarget}.
* Used by tools that need to reassign the current page (e.g. tab switching).
*/
function webTarget(context) {
if (context.targetInspector.type !== 'web') {
throw new Error('This tool requires a web target');
}
return context.targetInspector.target;
}
//# sourceMappingURL=TargetUtils.js.map