Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions apps/server/src/preview/ServerBrowser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ vi.mock("./ServerBrowserContexts.ts", () => ({
return makeEncoderPage() as unknown as Page;
}
async connectDesktopPage(endpoint: string) {
const context = makeContext();
const context = makeContext(undefined, desktopPageUrl);
context.page.viewportSize.mockReturnValue(null);
desktopConnections.push({ endpoint, context });
return { browser: { close: async () => {} }, page: context.page as unknown as Page };
Expand Down Expand Up @@ -151,12 +151,12 @@ function fileChooserElement(accept: string) {
};
}

function makeContext(onClose?: (context: BrowserContext) => void) {
function makeContext(onClose?: (context: BrowserContext) => void, initialUrl = "about:blank") {
const events = new NodeEvents.EventEmitter();
const nativeFileChooser = vi.fn();
const setChooserFiles = vi.fn(async (_files: unknown) => {});
const sessions: ReturnType<typeof makeSession>[] = [];
let url = "about:blank";
let url = initialUrl;
let viewport: ReturnType<Page["viewportSize"]> = { width: 1280, height: 800 };
const cssViewport = { width: 1920, height: 1080 };
let closed = false;
Expand Down Expand Up @@ -299,6 +299,7 @@ let focusedFrame: ReturnType<typeof makeFrame> | null = null;
let contextFailure: Error | null = null;
let initialNavigation: (() => Promise<void>) | null = null;
let desktopRendersNext = false;
let desktopPageUrl = "about:blank";
/** Replaces the answer to the desktop page's size reads. */
let desktopSizeAnswer: (() => Promise<Record<string, unknown>>) | null = null;
const desktopDetaches = new NodeEvents.EventEmitter();
Expand Down Expand Up @@ -446,6 +447,7 @@ beforeEach(() => {
focusedFrame = null;
desktopTabs.clear();
desktopRendersNext = false;
desktopPageUrl = "about:blank";
desktopSizeAnswer = null;
desktopDetachReady = Promise.withResolvers<void>();
desktopReleased = Promise.withResolvers<void>();
Expand Down Expand Up @@ -563,6 +565,33 @@ it.effect("a tab the desktop does not draw is marked headless, so the desktop st
).pipe(Effect.provide(layer)),
);

it.effect("a desktop page that loaded before the server attached reports its loaded title", () =>
Effect.scoped(
Effect.gen(function* () {
const { broker } = yield* ready;
const manager = yield* Manager.PreviewManager;
const events = yield* manager.subscribeEvents;
desktopRendersNext = true;
desktopPageUrl = "https://example.com/loaded";
const opened = yield* broker.invoke<PreviewAutomationStatus>({
scope,
operation: "open",
input: { url: desktopPageUrl, reuseExistingTab: false, show: false },
});
let event = yield* PubSub.take(events);
while (event.type !== "navigated" || event.tabId !== opened.tabId) {
event = yield* PubSub.take(events);
}

expect(event.snapshot.navStatus).toEqual({
_tag: "Success",
url: "https://example.com/loaded",
title: "test page",
});
}),
).pipe(Effect.provide(layer)),
);

it.live.each([
{ method: "goto" as const, message: { type: "navigate", url: "http://10.255.255.1/" } },
{ method: "goBack" as const, message: { type: "history", delta: -1 } },
Expand Down
2 changes: 2 additions & 0 deletions apps/server/src/preview/ServerBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ const make = Effect.gen(function* () {
page.on("crash", () => dropTab(tab, true));
tabs.set(key, tab);
reportLiveTabs();
// A desktop page navigates on its own and can finish loading before these listeners attach.
if (desktop) void page.waitForLoadState("load").then(() => reportLoaded(tab), constVoid);
Comment thread
camchis marked this conversation as resolved.
Resolved
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
// Existing desktop and popup PDFs can start loading before interception attaches.
if (
snapshot.navStatus._tag === "Loading" &&
Expand Down
Loading