Skip to content

Commit 6d1ca80

Browse files
fix(server): read the preview title alongside the desktop viewport
A busy desktop tab could spend the full 1 s viewport read and then the 250 ms title read in sequence, past the broker's 1 s grace. Overlap the two reads so the title adds no time. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 989542a commit 6d1ca80

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎apps/server/src/preview/ServerBrowser.ts‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,6 +1790,17 @@ const make = Effect.gen(function* () {
17901790
}
17911791
};
17921792

1793+
const readTitle = async (tab: ServerTab) => {
1794+
let timer: ReturnType<typeof setTimeout> | undefined;
1795+
const late = new Promise<string>((resolve) => {
1796+
timer = setTimeout(() => resolve(""), TITLE_READ_MS);
1797+
});
1798+
const title = await Promise.race([tab.page.title().catch(() => ""), late]).finally(() =>
1799+
clearTimeout(timer),
1800+
);
1801+
return title || null;
1802+
};
1803+
17931804
const statusWithTitle = async (
17941805
tab: ServerTab | undefined,
17951806
agentSessionId?: string,
@@ -1806,14 +1817,19 @@ const make = Effect.gen(function* () {
18061817
};
18071818
}
18081819
const url = ServerBrowserPage.withoutDataPayload(tab.page.url());
1809-
const viewport = tab.desktop ? await layoutSize(tab) : tab.page.viewportSize();
18101820
const loadError = loadErrorOf(tab);
1811-
const status = {
1821+
const statusUrl = loadError?.url ?? (url === "about:blank" ? null : url);
1822+
// Both reads need the renderer; overlapping them keeps a busy page within the broker's grace.
1823+
const [viewport, title] = await Promise.all([
1824+
tab.desktop ? layoutSize(tab) : tab.page.viewportSize(),
1825+
statusUrl === null || tab.dialog ? null : readTitle(tab),
1826+
]);
1827+
return {
18121828
available: true,
18131829
visible: isVisible(tab),
18141830
tabId: tab.tabId,
1815-
url: loadError?.url ?? (url === "about:blank" ? null : url),
1816-
title: null,
1831+
url: statusUrl,
1832+
title,
18171833
loading: tab.loading,
18181834
...(loadError ? { loadError } : {}),
18191835
control: {
@@ -1851,15 +1867,6 @@ const make = Effect.gen(function* () {
18511867
completedAt,
18521868
})),
18531869
};
1854-
if (status.url === null || tab.dialog) return status;
1855-
let timer: ReturnType<typeof setTimeout> | undefined;
1856-
const late = new Promise<string>((resolve) => {
1857-
timer = setTimeout(() => resolve(""), TITLE_READ_MS);
1858-
});
1859-
const title = await Promise.race([tab.page.title().catch(() => ""), late]).finally(() =>
1860-
clearTimeout(timer),
1861-
);
1862-
return { ...status, title: title || null };
18631870
};
18641871

18651872
const resolveNavigationUrl = (input: PreviewAutomationNavigateInput) => {

0 commit comments

Comments
 (0)