@@ -34,20 +34,25 @@ export function controlUiSessionUrl(baseUrl: string, sessionKey: string): string
3434}
3535
3636export async function navigateToControlUiSession ( page : Page , sessionKey : string ) : Promise < void > {
37- await page . evaluate ( ( pathname ) => {
37+ const expectedPathname = await page . evaluate ( ( sessionPath ) => {
3838 const app = document . querySelector ( "openclaw-app" ) as HTMLElement & {
3939 runtime ?: {
4040 context : {
41+ basePath : string ;
4142 navigate : ( routeId : string , options : { pathname : string } ) => void ;
4243 } ;
4344 } ;
4445 } ;
4546 if ( ! app . runtime ) {
4647 throw new Error ( "OpenClaw application runtime is unavailable" ) ;
4748 }
49+ const pathname = `${ app . runtime . context . basePath } ${ sessionPath } ` ;
50+ const url = new URL ( window . location . href ) ;
51+ url . pathname = pathname ;
4852 app . runtime . context . navigate ( "chat" , { pathname } ) ;
53+ return url . pathname ;
4954 } , controlUiSessionPath ( sessionKey ) ) ;
50- await page . waitForURL ( ( url ) => url . pathname === controlUiSessionPath ( sessionKey ) ) ;
55+ await page . waitForURL ( ( url ) => url . pathname === expectedPathname ) ;
5156 await page . waitForFunction (
5257 ( targetSessionKey ) =>
5358 [ ...document . querySelectorAll < HTMLElement > ( "openclaw-chat-pane" ) ] . some (
@@ -109,13 +114,22 @@ export async function waitForControlUiRoute(page: Page, target: ControlUiRouteTa
109114 } ;
110115 const state = app . runtime ?. router . getState ( ) ;
111116 const pathname = window . location . pathname ;
117+ // Router paths retain literal characters that browser history percent-encodes.
118+ // Serialize as a pathname; decoding would alias encoded delimiters and percent data.
119+ const browserPathname = ( value : string ) => {
120+ const url = new URL ( window . location . href ) ;
121+ url . pathname = value ;
122+ return url . pathname ;
123+ } ;
112124 return (
113125 state ?. status === "success" &&
114126 state . matches [ 0 ] ?. routeId === expected . routeId &&
115- state . resolvedLocation ?. pathname === pathname &&
127+ state . resolvedLocation !== null &&
128+ browserPathname ( state . resolvedLocation . pathname ) === pathname &&
116129 state . pendingMatches . length === 0 &&
117- ( expected . pathname === undefined || pathname === expected . pathname ) &&
118- ( expected . pathnamePrefix === undefined || pathname . startsWith ( expected . pathnamePrefix ) ) &&
130+ ( expected . pathname === undefined || pathname === browserPathname ( expected . pathname ) ) &&
131+ ( expected . pathnamePrefix === undefined ||
132+ pathname . startsWith ( browserPathname ( expected . pathnamePrefix ) ) ) &&
119133 ( expected . search === undefined || window . location . search === expected . search ) &&
120134 ( expected . hash === undefined || window . location . hash === expected . hash )
121135 ) ;
0 commit comments