@@ -214,18 +214,24 @@ async def _on_page_change(self, page: Page):
214214
215215 self ._cdp_session = await self .context .new_cdp_session (page )
216216
217- # set viewport size
218- await self ._cdp_session .send ("Emulation.setDeviceMetricsOverride" , {
219- "width" : self .config .viewport_size ["width" ],
220- "height" : self .config .viewport_size ["height" ],
221- "deviceScaleFactor" : 1 ,
222- "mobile" : False ,
223- })
217+ # set viewport size
218+ await self ._cdp_session .send (
219+ "Emulation.setDeviceMetricsOverride" ,
220+ {
221+ "width" : self .config .viewport_size ["width" ],
222+ "height" : self .config .viewport_size ["height" ],
223+ "deviceScaleFactor" : 1 ,
224+ "mobile" : False ,
225+ },
226+ )
224227 # Optional: adjust visible size (for headless rendering)
225- await self ._cdp_session .send ("Emulation.setVisibleSize" , {
226- "width" : self .config .viewport_size ["width" ],
227- "height" : self .config .viewport_size ["height" ],
228- })
228+ await self ._cdp_session .send (
229+ "Emulation.setVisibleSize" ,
230+ {
231+ "width" : self .config .viewport_size ["width" ],
232+ "height" : self .config .viewport_size ["height" ],
233+ },
234+ )
229235
230236 self .current_page = page
231237
@@ -484,18 +490,24 @@ async def get_cdp_session(self):
484490 ):
485491 self ._cdp_session = await self .context .new_cdp_session (self .current_page )
486492
487- # set viewport size
488- await self ._cdp_session .send ("Emulation.setDeviceMetricsOverride" , {
489- "width" : self .config .viewport_size ["width" ],
490- "height" : self .config .viewport_size ["height" ],
491- "deviceScaleFactor" : 1 ,
492- "mobile" : False ,
493- })
493+ # set viewport size
494+ await self ._cdp_session .send (
495+ "Emulation.setDeviceMetricsOverride" ,
496+ {
497+ "width" : self .config .viewport_size ["width" ],
498+ "height" : self .config .viewport_size ["height" ],
499+ "deviceScaleFactor" : 1 ,
500+ "mobile" : False ,
501+ },
502+ )
494503 # Optional: adjust visible size (for headless rendering)
495- await self ._cdp_session .send ("Emulation.setVisibleSize" , {
496- "width" : self .config .viewport_size ["width" ],
497- "height" : self .config .viewport_size ["height" ],
498- })
504+ await self ._cdp_session .send (
505+ "Emulation.setVisibleSize" ,
506+ {
507+ "width" : self .config .viewport_size ["width" ],
508+ "height" : self .config .viewport_size ["height" ],
509+ },
510+ )
499511
500512 # Store reference to the page this session belongs to
501513 self ._cdp_session ._page = self .current_page
@@ -547,15 +559,15 @@ async def get_storage_state(self) -> dict[str, Any]:
547559 async def handle_pdf_url_navigation (self ):
548560 page = await self .get_current_page ()
549561 if is_pdf_url (page .url ):
550- await asyncio .sleep (5 ) # Long sleep to ensure PDF is loaded
562+ await asyncio .sleep (5 ) # Long sleep to ensure PDF is loaded
551563 await page .keyboard .press ("Escape" )
552564 await asyncio .sleep (0.1 )
553565 await page .keyboard .press ("Control+\\ " )
554566 await asyncio .sleep (0.1 )
555567 await page .mouse .click (
556568 self .config .viewport_size ["width" ] * 0.75 , # Right side of screen
557- self .config .viewport_size ["height" ] * 0.25 # Upper portion
569+ self .config .viewport_size ["height" ] * 0.25 , # Upper portion
558570 )
559-
571+
560572 state = await self .update_state ()
561- return state
573+ return state
0 commit comments