bank.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package lxrod
  2. import (
  3. "context"
  4. "git.listensoft.net/tool/jspkit/taxerr"
  5. "github.com/go-rod/rod"
  6. "github.com/go-rod/rod/lib/devices"
  7. "github.com/go-rod/rod/lib/launcher"
  8. )
  9. // NewLauncher 创建一个新的 rod 浏览器启动器
  10. func NewLauncher(ctx context.Context) *launcher.Launcher {
  11. return launcher.New().Context(ctx).Set("window-size", "1600,900").Headless(false)
  12. }
  13. // NewEdgeBrowser 创建一个由 rod chromium 模拟的 Edge 浏览器
  14. func NewEdgeBrowser(ctx context.Context, u string) *rod.Browser {
  15. return rod.New().Context(ctx).DefaultDevice(EdgeLandscape).ControlURL(u)
  16. }
  17. // EdgeLandscape device.
  18. var EdgeLandscape = devices.Device{
  19. Title: "Edge Laptop with HiDPI screen",
  20. Capabilities: []string{},
  21. UserAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0",
  22. AcceptLanguage: "en",
  23. Screen: devices.Screen{
  24. DevicePixelRatio: 2,
  25. Horizontal: devices.ScreenSize{
  26. Width: 1600,
  27. Height: 900,
  28. },
  29. Vertical: devices.ScreenSize{
  30. Width: 900,
  31. Height: 1600,
  32. },
  33. },
  34. }.Landscape()
  35. func (lxrod *Lxrod) NewUserMode(ctx context.Context) (b *rod.Browser, p *rod.Page, err error) {
  36. l := launcher.NewUserMode().Headless(false)
  37. l.Flags["disable-blink-features"] = []string{"AutomationControlled"}
  38. lxrod.Launcher = l
  39. wsURL, err := l.Launch()
  40. lxrod.WsURL = wsURL
  41. if err != nil {
  42. return nil, nil, taxerr.NewWebStuckTitle(true)
  43. }
  44. b = rod.New().NoDefaultDevice().ControlURL(wsURL).Context(ctx).MustConnect()
  45. p = b.MustPage().MustSetWindow(0, 0, 1600, 900).MustSetViewport(1600, 900, 1, false)
  46. lxrod.Browser = b
  47. return b, p, nil
  48. }