mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:27:39 +00:00
refactor(browser): reuse role snapshot args in route
This commit is contained in:
@@ -194,6 +194,8 @@ export function registerBrowserAgentSnapshotRoutes(
|
|||||||
depthRaw ?? (mode === "efficient" ? DEFAULT_AI_SNAPSHOT_EFFICIENT_DEPTH : undefined);
|
depthRaw ?? (mode === "efficient" ? DEFAULT_AI_SNAPSHOT_EFFICIENT_DEPTH : undefined);
|
||||||
const selector = toStringOrEmpty(req.query.selector);
|
const selector = toStringOrEmpty(req.query.selector);
|
||||||
const frameSelector = toStringOrEmpty(req.query.frame);
|
const frameSelector = toStringOrEmpty(req.query.frame);
|
||||||
|
const selectorValue = selector.trim() || undefined;
|
||||||
|
const frameSelectorValue = frameSelector.trim() || undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const tab = await profileCtx.ensureTabAvailable(targetId || undefined);
|
const tab = await profileCtx.ensureTabAvailable(targetId || undefined);
|
||||||
@@ -211,22 +213,23 @@ export function registerBrowserAgentSnapshotRoutes(
|
|||||||
interactive === true ||
|
interactive === true ||
|
||||||
compact === true ||
|
compact === true ||
|
||||||
depth !== undefined ||
|
depth !== undefined ||
|
||||||
Boolean(selector.trim()) ||
|
Boolean(selectorValue) ||
|
||||||
Boolean(frameSelector.trim());
|
Boolean(frameSelectorValue);
|
||||||
|
const roleSnapshotArgs = {
|
||||||
|
cdpUrl: profileCtx.profile.cdpUrl,
|
||||||
|
targetId: tab.targetId,
|
||||||
|
selector: selectorValue,
|
||||||
|
frameSelector: frameSelectorValue,
|
||||||
|
refsMode,
|
||||||
|
options: {
|
||||||
|
interactive: interactive ?? undefined,
|
||||||
|
compact: compact ?? undefined,
|
||||||
|
maxDepth: depth ?? undefined,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const snap = wantsRoleSnapshot
|
const snap = wantsRoleSnapshot
|
||||||
? await pw.snapshotRoleViaPlaywright({
|
? await pw.snapshotRoleViaPlaywright(roleSnapshotArgs)
|
||||||
cdpUrl: profileCtx.profile.cdpUrl,
|
|
||||||
targetId: tab.targetId,
|
|
||||||
selector: selector.trim() || undefined,
|
|
||||||
frameSelector: frameSelector.trim() || undefined,
|
|
||||||
refsMode,
|
|
||||||
options: {
|
|
||||||
interactive: interactive ?? undefined,
|
|
||||||
compact: compact ?? undefined,
|
|
||||||
maxDepth: depth ?? undefined,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
: await pw
|
: await pw
|
||||||
.snapshotAiViaPlaywright({
|
.snapshotAiViaPlaywright({
|
||||||
cdpUrl: profileCtx.profile.cdpUrl,
|
cdpUrl: profileCtx.profile.cdpUrl,
|
||||||
@@ -236,18 +239,7 @@ export function registerBrowserAgentSnapshotRoutes(
|
|||||||
.catch(async (err) => {
|
.catch(async (err) => {
|
||||||
// Public-API fallback when Playwright's private _snapshotForAI is missing.
|
// Public-API fallback when Playwright's private _snapshotForAI is missing.
|
||||||
if (String(err).toLowerCase().includes("_snapshotforai")) {
|
if (String(err).toLowerCase().includes("_snapshotforai")) {
|
||||||
return await pw.snapshotRoleViaPlaywright({
|
return await pw.snapshotRoleViaPlaywright(roleSnapshotArgs);
|
||||||
cdpUrl: profileCtx.profile.cdpUrl,
|
|
||||||
targetId: tab.targetId,
|
|
||||||
selector: selector.trim() || undefined,
|
|
||||||
frameSelector: frameSelector.trim() || undefined,
|
|
||||||
refsMode,
|
|
||||||
options: {
|
|
||||||
interactive: interactive ?? undefined,
|
|
||||||
compact: compact ?? undefined,
|
|
||||||
maxDepth: depth ?? undefined,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user