@@ -10,6 +10,7 @@ import os from 'node:os';
1010import path from 'node:path' ;
1111import { describe , it } from 'node:test' ;
1212
13+ import type { ParsedArguments } from '../../src/bin/chrome-devtools-mcp-cli-options.js' ;
1314import { lighthouseAudit } from '../../src/tools/lighthouse.js' ;
1415import { serverHooks } from '../server.js' ;
1516import { html , withMcpContext } from '../utils.js' ;
@@ -117,6 +118,69 @@ describe('lighthouse', () => {
117118 } ) ;
118119 } ) ;
119120
121+ it ( 'restores launch-time viewport device scale factor' , async ( ) => {
122+ server . addHtmlRoute ( '/test-launch-viewport' , html `< div > Test DPR</ div > ` ) ;
123+
124+ await withMcpContext (
125+ async ( response , context ) => {
126+ const page = context . getSelectedPptrPage ( ) ;
127+ await page . goto ( server . getRoute ( '/test-launch-viewport' ) ) ;
128+
129+ {
130+ const viewportData = await page . evaluate ( ( ) => {
131+ return {
132+ width : window . innerWidth ,
133+ height : window . innerHeight ,
134+ deviceScaleFactor : window . devicePixelRatio ,
135+ } ;
136+ } ) ;
137+
138+ assert . deepStrictEqual ( viewportData , {
139+ width : 400 ,
140+ height : 400 ,
141+ deviceScaleFactor : 2 ,
142+ } ) ;
143+ }
144+
145+ await lighthouseAudit . handler (
146+ {
147+ params : {
148+ mode : 'snapshot' ,
149+ device : 'desktop' ,
150+ } ,
151+ page : context . getSelectedMcpPage ( ) ,
152+ } ,
153+ response ,
154+ context ,
155+ ) ;
156+
157+ {
158+ const viewportData = await page . evaluate ( ( ) => {
159+ return {
160+ width : window . innerWidth ,
161+ height : window . innerHeight ,
162+ deviceScaleFactor : window . devicePixelRatio ,
163+ } ;
164+ } ) ;
165+
166+ assert . deepStrictEqual ( viewportData , {
167+ width : 400 ,
168+ height : 400 ,
169+ deviceScaleFactor : 2 ,
170+ } ) ;
171+ }
172+ } ,
173+ { } ,
174+ {
175+ viewport : {
176+ width : 400 ,
177+ height : 400 ,
178+ deviceScaleFactor : 2 ,
179+ } ,
180+ } as ParsedArguments ,
181+ ) ;
182+ } ) ;
183+
120184 it ( 'runs Lighthouse in snapshot mode with mobile device' , async ( ) => {
121185 server . addHtmlRoute ( '/test-mobile' , html `< div > Test Mobile</ div > ` ) ;
122186
0 commit comments