Skip to content

sb.save_cookies() and sb.load_cookies() strip absolute paths and forcefully save to the local 'saved_cookies' folder` #4411

Description

@adarmawan117

Hi, when trying to use sb.save_cookies(name="C:/my/custom/path/cookies.txt"), SeleniumBase ignores the absolute directory path provided in the name parameter. Instead of saving the file to C:/my/custom/path/, it strips the directory structure and violently hardcodes the save location to a ./saved_cookies/ directory created dynamically at the script's root execution path.

This behavior breaks custom directory management in larger software architectures where cookies need to be centralized in a specific resource folder across different modules.

Steps to Reproduce:

from seleniumbase import SB
import os

def test_cookie_path():
    absolute_target = os.path.abspath("C:/my_custom_folder/my_cookies.txt")
    print(f"Intended path: {absolute_target}")

    with SB() as sb:
        sb.open("https://www.google.com")
        # Attempt to save to the absolute path
        sb.save_cookies(name=absolute_target)
        
        # The file will NOT be in C:/my_custom_folder/
        # Instead, it will be inside ./saved_cookies/C:/my_custom_folder/my_cookies.txt (or stripped)

Expected Behavior:
If an absolute path (or a relative path containing directory separators) is passed to the name argument, save_cookies and load_cookies should respect that full path and write/read exactly at the provided location, rather than enforcing the default env_cookies_dir (saved_cookies/).

Actual Behavior:
The absolute path is intercepted, and the file is written relative to a hardcoded saved_cookies/ folder at the root of the project.

Workaround Used:
Currently, users have to bypass SeleniumBase's native cookie functions entirely and manually dump/load using sb.driver.get_cookies() and Python's json module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions