@@ -39,16 +39,15 @@ def __activate_standard_virtual_display():
3939 width = settings .HEADLESS_START_WIDTH
4040 height = settings .HEADLESS_START_HEIGHT
4141 with suppress (Exception ):
42- _xvfb_display = Display (
43- visible = 0 , size = (width , height )
44- )
42+ _xvfb_display = Display (visible = 0 , size = (width , height ))
4543 _xvfb_display .start ()
44+ time .sleep (0.03 )
4645 sb_config ._virtual_display = _xvfb_display
4746 sb_config .headless_active = True
4847
4948
5049def __activate_virtual_display_as_needed (
51- headless , headed , xvfb , xvfb_metrics
50+ headless , headed , xvfb , xvfb_metrics , override_display = False
5251):
5352 """This is only needed on Linux."""
5453 reset_virtual_display = False
@@ -72,6 +71,7 @@ def __activate_virtual_display_as_needed(
7271 not hasattr (sb_config , "_virtual_display" )
7372 or not sb_config ._virtual_display
7473 or reset_virtual_display
74+ or override_display
7575 )
7676 ):
7777 from sbvirtualdisplay import Display
@@ -109,6 +109,7 @@ def __activate_virtual_display_as_needed(
109109 backend = "xvfb" ,
110110 use_xauth = True ,
111111 )
112+ time .sleep (0.05 )
112113 if "--debug-display" in sys .argv :
113114 print (
114115 "Starting VDisplay from cdp_util: (%s, %s)"
@@ -672,7 +673,12 @@ async def start(
672673 try :
673674 driver = await Browser .create (config )
674675 except Exception :
675- time .sleep (0.15 )
676+ time .sleep (0.12 )
677+ if not host or not port :
678+ __activate_virtual_display_as_needed (
679+ headless , headed , xvfb , xvfb_metrics , override_display = True
680+ )
681+ time .sleep (0.05 )
676682 driver = await Browser .create (config )
677683 if proxy :
678684 sb_config ._cdp_proxy = proxy
0 commit comments