@@ -401,6 +401,45 @@ describe('screenshot', () => {
401401 } ) ;
402402 } ) ;
403403
404+ it ( 'honors screenshotMaxWidth at device scale factors above 1' , async ( ) => {
405+ const tool = screenshot ( {
406+ screenshotMaxWidth : 100 ,
407+ } as ParsedArguments ) ;
408+ await withMcpContext (
409+ async ( response , context ) => {
410+ const page = context . getSelectedMcpPage ( ) . pptrPage ;
411+ assert . equal ( page . viewport ( ) , null ) ;
412+ await page . setContent (
413+ html `< div style ="width:100vw;height:100vh;background:red "> </ div > ` ,
414+ ) ;
415+ const source = await page . evaluate ( ( ) => ( {
416+ width : window . innerWidth ,
417+ height : window . innerHeight ,
418+ devicePixelRatio : window . devicePixelRatio ,
419+ } ) ) ;
420+ assert . equal ( source . devicePixelRatio , 2 ) ;
421+
422+ await tool . handler (
423+ { params : { format : 'png' } , page : context . getSelectedMcpPage ( ) } ,
424+ response ,
425+ context ,
426+ ) ;
427+
428+ assert . equal ( response . images . length , 1 ) ;
429+ const buf = Buffer . from ( response . images [ 0 ] . data , 'base64' ) ;
430+ assert . equal ( pngWidth ( buf ) , 100 ) ;
431+ const expectedHeight = Math . round (
432+ source . height * ( 100 / source . width ) ,
433+ ) ;
434+ assert . ok (
435+ Math . abs ( pngHeight ( buf ) - expectedHeight ) <= 1 ,
436+ `expected height ~${ expectedHeight } , got ${ pngHeight ( buf ) } ` ,
437+ ) ;
438+ } ,
439+ { args : [ '--force-device-scale-factor=2' ] } ,
440+ ) ;
441+ } ) ;
442+
404443 it ( 'downscales viewport screenshot when no viewport is emulated' , async ( ) => {
405444 const tool = screenshot ( {
406445 screenshotMaxWidth : 100 ,
0 commit comments