Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the default UserAgent's platform is "Intel Mac" even in windows? #1093

Closed
kvii opened this issue Jul 18, 2024 · 1 comment
Closed

Why the default UserAgent's platform is "Intel Mac" even in windows? #1093

kvii opened this issue Jul 18, 2024 · 1 comment
Labels
question Questions related to rod

Comments

@kvii
Copy link
Contributor

kvii commented Jul 18, 2024

Rod Version: v0.116.2

The defaultDevice of a rod.Browser is devices.LaptopWithMDPIScreen.Landscape(), which is a device whose UserAgent's platform is mac, even in windows.

rod/browser.go

Lines 69 to 82 in 01a50b9

func New() *Browser {
return (&Browser{
ctx: context.Background(),
sleeper: DefaultSleeper,
controlURL: defaults.URL,
slowMotion: defaults.Slow,
trace: defaults.Trace,
monitor: defaults.Monitor,
logger: DefaultLogger,
defaultDevice: devices.LaptopWithMDPIScreen.Landscape(),
targetsLock: &sync.Mutex{},
states: &sync.Map{},
}).WithPanic(utils.Panic)
}

rod/lib/devices/list.go

Lines 615 to 632 in 01a50b9

// LaptopWithMDPIScreen device.
LaptopWithMDPIScreen = Device{
Title: "Laptop with MDPI screen",
Capabilities: []string{},
UserAgent: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
AcceptLanguage: "en",
Screen: Screen{
DevicePixelRatio: 1,
Horizontal: ScreenSize{
Width: 1280,
Height: 800,
},
Vertical: ScreenSize{
Width: 800,
Height: 1280,
},
},
}

So if a web site has some logic depend on navigator.userAgent, it will lead to an unexpected result in windows.

@kvii kvii added the question Questions related to rod label Jul 18, 2024
@kvii
Copy link
Contributor Author

kvii commented Jul 18, 2024

This mainly for the ability that running the same code will get the same result, no matter where it is. It's very helpful to reproduce problems. And the device can be changed. It's just a hard-code device setting.

As @ysmood's answer in discord. We need to change user agent manually in windows(how to). The current user agent in windows is "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36".

@kvii kvii closed this as completed Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

1 participant