refactor(browser): let withRouteTabContext wrapper handle url/targetId injection

Remove redundant url: tab.url and targetId: tab.targetId from
individual action/debug route responses. The withRouteTabContext
wrapper already resolves the live Playwright URL and injects both
fields into any response where they're missing. Hardcoding tab.url
in handlers prevented the wrapper from correcting stale relay
metadata — the exact scenario it was designed to fix.

Addresses Codex review on openclaw/openclaw#30323.
This commit is contained in:
zeroaltitude 2026-02-28 22:44:11 -07:00
parent 43a670f095
commit d1b4b30eb6
No known key found for this signature in database
GPG Key ID: 77592FB1C703882E
2 changed files with 14 additions and 19 deletions

View File

@ -558,7 +558,7 @@ export function registerBrowserAgentActRoutes(
clickRequest.timeoutMs = timeoutMs;
}
await pw.clickViaPlaywright(clickRequest);
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "type": {
const ref = toStringOrEmpty(body.ref) || undefined;
@ -626,7 +626,7 @@ export function registerBrowserAgentActRoutes(
typeRequest.timeoutMs = timeoutMs;
}
await pw.typeViaPlaywright(typeRequest);
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "press": {
const key = toStringOrEmpty(body.key);
@ -656,7 +656,7 @@ export function registerBrowserAgentActRoutes(
key,
delayMs: delayMs ?? undefined,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "hover": {
const ref = toStringOrEmpty(body.ref) || undefined;
@ -699,7 +699,7 @@ export function registerBrowserAgentActRoutes(
selector,
timeoutMs: timeoutMs ?? undefined,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "scrollIntoView": {
const ref = toStringOrEmpty(body.ref) || undefined;
@ -750,7 +750,7 @@ export function registerBrowserAgentActRoutes(
scrollRequest.timeoutMs = timeoutMs;
}
await pw.scrollIntoViewViaPlaywright(scrollRequest);
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "drag": {
const startRef = toStringOrEmpty(body.startRef) || undefined;
@ -801,7 +801,7 @@ export function registerBrowserAgentActRoutes(
endSelector,
timeoutMs: timeoutMs ?? undefined,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "select": {
const ref = toStringOrEmpty(body.ref) || undefined;
@ -854,7 +854,7 @@ export function registerBrowserAgentActRoutes(
values,
timeoutMs: timeoutMs ?? undefined,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "fill": {
const rawFields = Array.isArray(body.fields) ? body.fields : [];
@ -899,7 +899,7 @@ export function registerBrowserAgentActRoutes(
fields,
timeoutMs: timeoutMs ?? undefined,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "resize": {
const width = toNumber(body.width);
@ -927,7 +927,7 @@ export function registerBrowserAgentActRoutes(
width,
height,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "wait": {
const timeMs = toNumber(body.timeMs);
@ -1001,7 +1001,7 @@ export function registerBrowserAgentActRoutes(
fn,
timeoutMs,
});
return res.json({ ok: true, targetId: tab.targetId, url: tab.url });
return res.json({ ok: true });
}
case "evaluate": {
if (!evaluateEnabled) {
@ -1050,12 +1050,7 @@ export function registerBrowserAgentActRoutes(
evalRequest.timeoutMs = evalTimeoutMs;
}
const result = await pw.evaluateViaPlaywright(evalRequest);
return res.json({
ok: true,
targetId: tab.targetId,
url: tab.url,
result,
});
return res.json({ ok: true, result });
}
case "close": {
if (isExistingSession) {
@ -1152,7 +1147,7 @@ export function registerBrowserAgentActRoutes(
timeoutMs: timeoutMs ?? undefined,
maxChars: maxChars ?? undefined,
});
res.json({ ok: true, targetId: tab.targetId, url: tab.url, response: result });
res.json({ ok: true, response: result });
},
});
});
@ -1204,7 +1199,7 @@ export function registerBrowserAgentActRoutes(
targetId: tab.targetId,
ref,
});
res.json({ ok: true, targetId: tab.targetId, url: tab.url });
res.json({ ok: true });
},
});
});

View File

@ -32,7 +32,7 @@ export function registerBrowserAgentDebugRoutes(
targetId: tab.targetId,
level: level.trim() || undefined,
});
res.json({ ok: true, messages, targetId: tab.targetId, url: tab.url });
res.json({ ok: true, messages });
},
});
});