Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(preview): agent clicks no longer take the user's typing focus #13914

Closedmkiera(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/13914/headopened View on GitHub

Showing 3 changed files with 210 additions and 3 deletions.

x
0 of 3 viewed, 3 left
9 additions and 3 deletionsapps/web/src/components/preview/PreviewAutomationHosts.tsxModified
View file
@@ -90,6 +90,7 @@
resolvePreviewAutomationTarget,
} from "./previewAutomationTarget";
import { resolveHostWaitBudgetMs, waitForHostReadiness } from "./previewAutomationHostBudget";
+import { keepHostFocusDuringGuestInput } from "./previewHostFocus";
import { isPreviewViewportReady } from "./previewViewportReadiness";
import { shouldRollbackPreviewViewport } from "./previewViewportRollback";
​
@@ -141,6 +142,9 @@
(candidate) => candidate.getAttribute("data-preview-tab") === tabId,
) ?? null;
​
+const activeHtmlElement = (): HTMLElement | null =>
+ document.activeElement instanceof HTMLElement ? document.activeElement : null;
+​
const isPreviewWebviewRendering = (runtimeTabId: string): boolean => {
const wrapper = findPreviewWebview(runtimeTabId)?.closest<HTMLElement>("[data-preview-viewport]");
return wrapper?.getAttribute("data-preview-rendering") === "active";
@@ -686,9 +690,11 @@
case "click": {
const ready = await requireReadyTab();
- return await ready.bridge.automation.click(
- ready.runtimeTabId,
- request.input as Parameters<typeof ready.bridge.automation.click>[1],
+ return await keepHostFocusDuringGuestInput(ready.runtimeTabId, activeHtmlElement, () =>
+ ready.bridge.automation.click(
+ ready.runtimeTabId,