1
1
import asyncio
2
2
import pdb
3
3
4
- from patchright .async_api import Browser as PlaywrightBrowser
5
- from patchright .async_api import (
4
+ from playwright .async_api import Browser as PlaywrightBrowser
5
+ from playwright .async_api import (
6
6
BrowserContext as PlaywrightBrowserContext ,
7
7
)
8
- from patchright .async_api import (
8
+ from playwright .async_api import (
9
9
Playwright ,
10
10
async_playwright ,
11
11
)
12
12
from browser_use .browser .browser import Browser , IN_DOCKER
13
13
from browser_use .browser .context import BrowserContext , BrowserContextConfig
14
- from patchright .async_api import BrowserContext as PlaywrightBrowserContext
14
+ from playwright .async_api import BrowserContext as PlaywrightBrowserContext
15
15
import logging
16
16
17
17
from browser_use .browser .chrome import (
@@ -48,9 +48,13 @@ async def _setup_builtin_browser(self, playwright: Playwright) -> PlaywrightBrow
48
48
if (
49
49
not self .config .headless
50
50
and hasattr (self .config , 'new_context_config' )
51
- and hasattr (self .config .new_context_config , 'browser_window_size' )
51
+ and hasattr (self .config .new_context_config , 'window_width' )
52
+ and hasattr (self .config .new_context_config , 'window_height' )
52
53
):
53
- screen_size = self .config .new_context_config .browser_window_size .model_dump ()
54
+ screen_size = {
55
+ 'width' : self .config .new_context_config .window_width ,
56
+ 'height' : self .config .new_context_config .window_height ,
57
+ }
54
58
offset_x , offset_y = get_window_adjustments ()
55
59
elif self .config .headless :
56
60
screen_size = {'width' : 1920 , 'height' : 1080 }
@@ -67,17 +71,12 @@ async def _setup_builtin_browser(self, playwright: Playwright) -> PlaywrightBrow
67
71
* (CHROME_DISABLE_SECURITY_ARGS if self .config .disable_security else []),
68
72
* (CHROME_DETERMINISTIC_RENDERING_ARGS if self .config .deterministic_rendering else []),
69
73
f'--window-position={ offset_x } ,{ offset_y } ' ,
74
+ f'--window-size={ screen_size ["width" ]} ,{ screen_size ["height" ]} ' ,
70
75
* self .config .extra_browser_args ,
71
76
}
72
- contain_window_size = False
73
- for arg in self .config .extra_browser_args :
74
- if "--window-size" in arg :
75
- contain_window_size = True
76
- break
77
- if not contain_window_size :
78
- chrome_args .add (f'--window-size={ screen_size ["width" ]} ,{ screen_size ["height" ]} ' )
79
77
80
- # check if port 9222 is already taken, if so remove the remote-debugging-port arg to prevent conflicts
78
+ # check if chrome remote debugging port is already taken,
79
+ # if so remove the remote-debugging-port arg to prevent conflicts
81
80
with socket .socket (socket .AF_INET , socket .SOCK_STREAM ) as s :
82
81
if s .connect_ex (('localhost' , self .config .chrome_remote_debugging_port )) == 0 :
83
82
chrome_args .remove (f'--remote-debugging-port={ self .config .chrome_remote_debugging_port } ' )
@@ -100,6 +99,7 @@ async def _setup_builtin_browser(self, playwright: Playwright) -> PlaywrightBrow
100
99
}
101
100
102
101
browser = await browser_class .launch (
102
+ channel = 'chromium' , # https://github.com/microsoft/playwright/issues/33566
103
103
headless = self .config .headless ,
104
104
args = args [self .config .browser_class ],
105
105
proxy = self .config .proxy .model_dump () if self .config .proxy else None ,
0 commit comments