@@ -72,7 +72,24 @@ vi.mock("./agent.shared.js", () => ({
7272 requirePwAi : vi . fn ( async ( ) => null ) ,
7373 resolveProfileContext : vi . fn ( ( ) => profileContext ) ,
7474 withPlaywrightRouteContext : vi . fn ( ) ,
75- withRouteTabContext : vi . fn ( ) ,
75+ withRouteTabContext : vi . fn (
76+ async ( params : {
77+ run : ( ctx : {
78+ profileCtx : typeof profileContext ;
79+ tab : { targetId : string ; url : string ; wsUrl : string } ;
80+ cdpUrl : string ;
81+ } ) => Promise < void > ;
82+ } ) =>
83+ await params . run ( {
84+ profileCtx : profileContext ,
85+ tab : {
86+ targetId : "tab-1" ,
87+ url : "https://example.com" ,
88+ wsUrl : "ws://127.0.0.1:18800/devtools/page/tab-1" ,
89+ } ,
90+ cdpUrl : "http://127.0.0.1:18800" ,
91+ } ) ,
92+ ) ,
7693} ) ) ;
7794
7895const { registerBrowserAgentSnapshotRoutes } = await import ( "./agent.snapshot.js" ) ;
@@ -87,6 +104,16 @@ function getSnapshotHandler() {
87104 return handler ;
88105}
89106
107+ function getScreenshotHandler ( ) {
108+ const { app, postHandlers } = createBrowserRouteApp ( ) ;
109+ registerBrowserAgentSnapshotRoutes ( app , {
110+ state : ( ) => ( { resolved : { extraArgs : [ ] } } ) ,
111+ } as never ) ;
112+ const handler = postHandlers . get ( "/screenshot" ) ;
113+ expect ( handler ) . toBeTypeOf ( "function" ) ;
114+ return handler ;
115+ }
116+
90117describe ( "browser agent snapshot timeout routing" , ( ) => {
91118 beforeEach ( ( ) => {
92119 cdpMocks . captureScreenshot . mockClear ( ) ;
@@ -124,4 +151,22 @@ describe("browser agent snapshot timeout routing", () => {
124151 } ) ,
125152 ) ;
126153 } ) ;
154+
155+ it ( "caps screenshot timeoutMs before dispatching to CDP" , async ( ) => {
156+ cdpMocks . captureScreenshot . mockResolvedValueOnce ( Buffer . from ( "png" ) ) ;
157+ const handler = getScreenshotHandler ( ) ;
158+ const response = createBrowserRouteResponse ( ) ;
159+
160+ await handler ?.(
161+ { params : { } , query : { } , body : { type : "png" , timeoutMs : 3_000_000_000 } } ,
162+ response . res ,
163+ ) ;
164+
165+ expect ( response . statusCode ) . toBe ( 200 ) ;
166+ expect ( cdpMocks . captureScreenshot ) . toHaveBeenCalledWith (
167+ expect . objectContaining ( {
168+ timeoutMs : 2_147_483_647 ,
169+ } ) ,
170+ ) ;
171+ } ) ;
127172} ) ;
0 commit comments