Skip to content

browser.user_agent#

Functions#

get() #

Get the user agent of the browser.

Returns:

Type Description
str

The user agent of the browser.

Example
user_agent = browser.user_agent.get()
print(user_agent)

How the output could look like in the terminal:

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0

set(user_agent) #

Set the User-Agent of the browser's request header with a custom value. Note that not all browsers support changing user agent on the fly. Alternatively, it's recommended to set the user agent in the BrowserSettings when initiating the session.

Parameters:

Name Type Description Default
user_agent str

The user agent to set.

required
Example

Basic example:

browser.user_agent.set("MyUserAgent")

Or if you want to identify your sessions with a custom value, you can append the existing user agent with your own value:

1
2
3
user_agent = browser.user_agent.get()
user_agent += " MyUserAgent"
browser.user_agent.set(user_agent)