@@ -39,7 +39,7 @@ import {
3939import { resolveBrowserRecordingStopTarget } from "~/browser/browserRecordingScope" ;
4040import { useBrowserSurfaceStore } from "~/browser/browserSurfaceStore" ;
4141import { runBrowserViewportMutation } from "~/browser/browserViewportActions" ;
42- import { isCurrentPreviewRuntimeTab , previewRuntimeTabId } from "~/browser/previewRuntimeTabId" ;
42+ import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId" ;
4343import { isElectron } from "~/env" ;
4444import { useEnvironments } from "~/state/environments" ;
4545import { previewEnvironment } from "~/state/preview" ;
@@ -48,7 +48,6 @@ import { useAtomCommand } from "~/state/use-atom-command";
4848
4949import { previewBridge } from "./previewBridge" ;
5050import {
51- PreviewAutomationNavigationTimeoutError ,
5251 PreviewAutomationOperationError ,
5352 PreviewAutomationOverlayTimeoutError ,
5453 PreviewAutomationRecordingNotActiveError ,
@@ -60,6 +59,10 @@ import {
6059 previewAutomationOpenNeedsOverlay ,
6160 shouldOpenPreviewMiniPlayer ,
6261} from "./previewAutomationOpenReadiness" ;
62+ import {
63+ assertPreviewRuntimeCurrent ,
64+ waitForNavigationReadiness ,
65+ } from "./previewNavigationReadiness" ;
6366import { createPreviewAutomationRequestConsumerAtom } from "./previewAutomationRequestConsumer" ;
6467import { createPreviewAutomationClientId } from "./previewAutomationClientId" ;
6568import {
@@ -80,29 +83,6 @@ const waitForPreviewPresentation = async (runtimeTabId: string): Promise<void> =
8083 }
8184} ;
8285
83- const assertPreviewRuntimeCurrent = (
84- threadRef : ScopedThreadRef ,
85- tabId : string ,
86- runtimeTabId : string ,
87- request : Pick < PreviewAutomationRequest , "operation" | "requestId" > ,
88- ) => {
89- const state = readThreadPreviewState ( threadRef ) ;
90- if (
91- state . sessions [ tabId ] &&
92- isCurrentPreviewRuntimeTab ( threadRef , state . serverEpoch , tabId , runtimeTabId )
93- ) {
94- return state ;
95- }
96- throw new PreviewAutomationTargetUnavailableError ( {
97- requestId : request . requestId ,
98- operation : request . operation ,
99- environmentId : threadRef . environmentId ,
100- threadId : threadRef . threadId ,
101- tabId,
102- bridgeAvailable : Boolean ( previewBridge ) ,
103- } ) ;
104- } ;
105-
10686const waitForDesktopOverlay = async (
10787 threadRef : ScopedThreadRef ,
10888 requestId : string ,
@@ -131,41 +111,6 @@ const waitForDesktopOverlay = async (
131111 } ) ;
132112} ;
133113
134- const waitForNavigationReadiness = async (
135- threadRef : ScopedThreadRef ,
136- requestId : string ,
137- tabId : string ,
138- runtimeTabId : string ,
139- operation : PreviewAutomationRequest [ "operation" ] ,
140- readiness : PreviewAutomationNavigateInput [ "readiness" ] ,
141- timeoutMs : number ,
142- ) : Promise < void > => {
143- const targetReadiness = readiness ?? "load" ;
144- if ( ! previewBridge || targetReadiness === "none" ) return ;
145- const deadline = Date . now ( ) + timeoutMs ;
146- while ( Date . now ( ) <= deadline ) {
147- assertPreviewRuntimeCurrent ( threadRef , tabId , runtimeTabId , { operation, requestId } ) ;
148- if ( targetReadiness === "domContentLoaded" ) {
149- const readyState = await previewBridge . automation . evaluate ( runtimeTabId , {
150- expression : "document.readyState" ,
151- } ) ;
152- if ( readyState === "interactive" || readyState === "complete" ) return ;
153- } else {
154- const status = await previewBridge . automation . status ( runtimeTabId ) ;
155- if ( status . available && ! status . loading ) return ;
156- }
157- await new Promise < void > ( ( resolve ) => window . setTimeout ( resolve , 50 ) ) ;
158- }
159- throw new PreviewAutomationNavigationTimeoutError ( {
160- requestId,
161- environmentId : threadRef . environmentId ,
162- threadId : threadRef . threadId ,
163- tabId,
164- readiness : targetReadiness ,
165- timeoutMs,
166- } ) ;
167- } ;
168-
169114interface ExecutablePreviewWebview extends Element {
170115 readonly executeJavaScript : ( code : string , userGesture ?: boolean ) => Promise < unknown > ;
171116}
0 commit comments