wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 254 forks source link

How to change user agent in selenium wire options ? #581

Closed thesalah1212 closed 2 years ago

thesalah1212 commented 2 years ago

I tried this one options = { 'proxy': { 'http': f'http://{proxy_user}:{proxy_pass}@{host}:{port}', }, 'user-agent':randomuseragent }

then I test using

driver.execute_script("return navigator.userAgent;")

the user agent don't changed same always

wkeeling commented 2 years ago

You will have to use a request interceptor if you want to change the user agent.

def request_interceptor(req):
    del req.headers["user-agent"]
    req.headers["user-agent"] = "randomuseragent"

driver.request_interceptor = request_interceptor

Verify it by visiting https://httpbin.org/headers