Selenium base and UC=true but google still detects device as desktop

robifz

Newbie
Joined
Dec 15, 2023
Messages
9
Reaction score
2
I am using Selenium base and UC=true but google still detects the device as desktop.
How can I make it think I am using a mobile device.
I have tried different user agents but still detects device as a desktop
 
You can try with the following options:
Code:
mobile_emulation = {
    "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0},
    "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"
}

chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

Basically, you have to change the width & height as well as the pixelRatio & use a real phone user useragent,
The above is set to match a Nexus 5, you can change it to whatever you want, just make sure to set the other values to match as well
 
You can try with the following options:
Code:
mobile_emulation = {
    "deviceMetrics": {"width": 360, "height": 640, "pixelRatio": 3.0},
    "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19"
}

chrome_options = Options()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)

Basically, you have to change the width & height as well as the pixelRatio & use a real phone user useragent,
The above is set to match a Nexus 5, you can change it to whatever you want, just make sure to set the other values to match as well
Thanks.
 
Back
Top