mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 19:48:27 +00:00
refactor(browser): dedupe request record lookup
This commit is contained in:
@@ -107,6 +107,16 @@ function normalizeCdpUrl(raw: string) {
|
|||||||
return raw.replace(/\/$/, "");
|
return raw.replace(/\/$/, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findNetworkRequestById(state: PageState, id: string): BrowserNetworkRequest | undefined {
|
||||||
|
for (let i = state.requests.length - 1; i >= 0; i -= 1) {
|
||||||
|
const candidate = state.requests[i];
|
||||||
|
if (candidate && candidate.id === id) {
|
||||||
|
return candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function roleRefsKey(cdpUrl: string, targetId: string) {
|
function roleRefsKey(cdpUrl: string, targetId: string) {
|
||||||
return `${normalizeCdpUrl(cdpUrl)}::${targetId}`;
|
return `${normalizeCdpUrl(cdpUrl)}::${targetId}`;
|
||||||
}
|
}
|
||||||
@@ -246,14 +256,7 @@ export function ensurePageState(page: Page): PageState {
|
|||||||
if (!id) {
|
if (!id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let rec: BrowserNetworkRequest | undefined;
|
const rec = findNetworkRequestById(state, id);
|
||||||
for (let i = state.requests.length - 1; i >= 0; i -= 1) {
|
|
||||||
const candidate = state.requests[i];
|
|
||||||
if (candidate && candidate.id === id) {
|
|
||||||
rec = candidate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -265,14 +268,7 @@ export function ensurePageState(page: Page): PageState {
|
|||||||
if (!id) {
|
if (!id) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let rec: BrowserNetworkRequest | undefined;
|
const rec = findNetworkRequestById(state, id);
|
||||||
for (let i = state.requests.length - 1; i >= 0; i -= 1) {
|
|
||||||
const candidate = state.requests[i];
|
|
||||||
if (candidate && candidate.id === id) {
|
|
||||||
rec = candidate;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!rec) {
|
if (!rec) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user