Skip to content

BrowserSettings#

Class to configure the browser driver.

Parameters:

Name Type Description Default
type BrowserType

Set browser type, e.g. Chrome, Edge, Firefox, etc.

EDGE if is_windows() else CHROME
headless bool

Run the browser in headless mode. May not be supported by all browsers, or some interaction methods, e.g. select, may not be supported.

False
disable_images bool

Neither request nor render images, which typically improves loading speed. May not be supported by all browsers.

False
page_load_strategy PageLoadStrategy NORMAL
path_to_executable str | Path | None

If the browser executable isn't in a default folder, select which file to use.

None
download_dir str | Path

Set where to save downloads. Default is the Downloads folder of the user.

DOWNLOADS_DIR
screenshot_dir str | Path

Set where to save sreenshots. Default is the Downloads folder of the user.

DOWNLOADS_DIR
timeout TimeoutSettings TimeoutSettings()
viewport DeviceViewportSize | tuple[int, int] | None

Emulate viewport size as device or set custom value in pixels. If not set, the browser's default size is used.

None
check_connection bool

Check whether there is an internet connection before starting the browser. Bypass the check by setting it to False.

True
user_agent str

Set a custom user agent to override the default user agent. If not set, the browser's default user agent is used.

None
Example

Use Firefox as browser type:

1
2
3
4
5
6
from browserist import Browser, BrowserSettings

settings = BrowserSettings(browser_type=BrowserType.FIREFOX)

with Browser(settings) as browser:
    browser.open.url("https://example.com")

Use browser in headless mode and with images disabled:

1
2
3
4
5
6
from browserist import Browser, BrowserSettings

settings = BrowserSettings(headless=True, disable_images=True)

with Browser(settings) as browser:
    browser.open.url("https://example.com")

Use custom directory for screenshots:

1
2
3
4
5
6
7
from browserist import Browser, BrowserSettings

settings = BrowserSettings(screenshot_dir="/screenshots/folder")

with Browser(settings) as browser:
    browser.open.url("https://example.com")
    browser.screenshot.visible_portion()

Use custom viewport size:

1
2
3
4
5
6
from browserist import Browser, BrowserSettings

settings = BrowserSettings(viewport=(1024, 768))

with Browser(settings) as browser:
    browser.open.url("https://example.com")

Use custom User-agent in the request header:

1
2
3
4
5
6
7
8
from browserist import Browser, BrowserSettings

settings = BrowserSettings(user_agent="MyUserAgent")

with Browser(settings) as browser:
    browser.open.url("https://example.com")
    user_agent = browser.user_agent.get()
    print(user_agent)

How the print output appears in the terminal:

MyUserAgent

How to disable checking for an internet connection:

1
2
3
4
5
6
from browserist import Browser, BrowserSettings

settings = BrowserSettings(check_connection=False)

with Browser(settings) as browser:
    browser.open.url("https://example.com")