Browse Source

feat: 创建 chrome 浏览器

wangkang 6 days ago
parent
commit
140d765d61
1 changed files with 24 additions and 0 deletions
  1. 24 0
      common/lxrod/bank.go

+ 24 - 0
common/lxrod/bank.go

@@ -24,6 +24,11 @@ func NewEdgeBrowser(ctx context.Context, u string) *rod.Browser {
 	return rod.New().Context(ctx).DefaultDevice(EdgeLandscape).ControlURL(u)
 }
 
+// NewChromeBrowser 创建一个由 rod chromium 模拟的 Chrome 浏览器
+func NewChromeBrowser(ctx context.Context, u string) *rod.Browser {
+	return rod.New().Context(ctx).DefaultDevice(ChromeLandscape).ControlURL(u)
+}
+
 // EdgeLandscape device.
 var EdgeLandscape = devices.Device{
 	Title:          "Edge Laptop with HiDPI screen",
@@ -43,6 +48,25 @@ var EdgeLandscape = devices.Device{
 	},
 }.Landscape()
 
+// ChromeLandscape device.
+var ChromeLandscape = devices.Device{
+	Title:          "Chrome Laptop with HiDPI screen",
+	Capabilities:   []string{},
+	UserAgent:      "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36",
+	AcceptLanguage: "en",
+	Screen: devices.Screen{
+		DevicePixelRatio: 2,
+		Horizontal: devices.ScreenSize{
+			Width:  1600,
+			Height: 900,
+		},
+		Vertical: devices.ScreenSize{
+			Width:  900,
+			Height: 1600,
+		},
+	},
+}.Landscape()
+
 // NewUserMode 使用系统浏览器启动一个新的浏览器。具体使用哪个浏览器由 rod 选择。
 // 一般是 Chrome 浏览器。注意:本地的浏览器必须完全关闭,否则会启动失败。
 func (lxrod *Lxrod) NewUserMode(ctx context.Context) (b *rod.Browser, p *rod.Page, err error) {