Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Is there anyway to load cookies? #29

Open
A1rkuss opened this issue Jan 20, 2024 · 5 comments
Open

[Question] Is there anyway to load cookies? #29

A1rkuss opened this issue Jan 20, 2024 · 5 comments
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested

Comments

@A1rkuss
Copy link

A1rkuss commented Jan 20, 2024

In Playwright you can load cookies like that:
context = await browser.new_context(storage_state=cookie_file)
Is it possible to do in Botright? I didn't find the solution :(

@A1rkuss A1rkuss added documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested labels Jan 20, 2024
@A1rkuss
Copy link
Author

A1rkuss commented Jan 20, 2024

Also I saw a Discord generator made by you and I have a question, why is it not working? Is the problem with the generator or the captcha-solver? I'm interested because I want to make a bot that enters discord servers with already existing accounts.

@Vinyzu
Copy link
Owner

Vinyzu commented Jan 20, 2024

You can add cookies via await browser.add_cookies() @ BrowserContext.add_cookies
You cant add a storage_state, as Botright now uses Persistent Contexts, which dont allow for such an option.
However, you can edit the user_data_dir, which botright uses, although this is not recommended. (Ref: PersistentContext user_data_dir).

This Repository is not connected to Dislock (the Discord Generator), if you have any questions about it, open an issue there.

@Vinyzu Vinyzu closed this as completed Jan 20, 2024
@n-sviridenko
Copy link

@Vinyzu but the temp dir is always different:

if sys.version_info.minor >= 10:
temp_dir = TemporaryDirectory(prefix="botright-", ignore_cleanup_errors=True)
else:
temp_dir = TemporaryDirectory(prefix="botright-")
temp_dir_path = temp_dir.name
botright.temp_dirs.append(temp_dir)
# Spawning a new Context for more options
if proxy.browser_proxy:
_browser = await botright.playwright.chromium.launch_persistent_context(
user_data_dir=temp_dir_path, headless=botright.headless, executable_path=botright.browser["path"], args=flags, chromium_sandbox=True, **parsed_launch_arguments
)
else:
_browser = await botright.playwright.chromium.launch_persistent_context(
user_data_dir=temp_dir_path, headless=botright.headless, executable_path=botright.browser["path"], args=flags, chromium_sandbox=True, **parsed_launch_arguments
)

in our case we need to persist the user data so that they can use the same session in the future

how can we do that w/o changing source code of Botright?

@n-sviridenko
Copy link

We also need to disable default PDF preview so that these files get downloaded natively:

preference = {
            "plugins": {
                "always_open_pdf_externally": True,
                "open_pdf_in_system_reader": True,
            },
        }
        user_data_dir = [our directory]
        preference_dir = os.path.join(user_data_dir, "Default")
        os.makedirs(preference_dir, mode=0o777, exist_ok=True)
        with open(preference_dir + "/Preferences", "w") as f:
            json.dump(preference, f)

And this has to happen before the persistent context is launched.

@Vinyzu
Copy link
Owner

Vinyzu commented Jan 18, 2025

@Vinyzu but the temp dir is always different:

if sys.version_info.minor >= 10:
temp_dir = TemporaryDirectory(prefix="botright-", ignore_cleanup_errors=True)
else:
temp_dir = TemporaryDirectory(prefix="botright-")
temp_dir_path = temp_dir.name
botright.temp_dirs.append(temp_dir)
# Spawning a new Context for more options
if proxy.browser_proxy:
_browser = await botright.playwright.chromium.launch_persistent_context(
user_data_dir=temp_dir_path, headless=botright.headless, executable_path=botright.browser["path"], args=flags, chromium_sandbox=True, **parsed_launch_arguments
)
else:
_browser = await botright.playwright.chromium.launch_persistent_context(
user_data_dir=temp_dir_path, headless=botright.headless, executable_path=botright.browser["path"], args=flags, chromium_sandbox=True, **parsed_launch_arguments
)

in our case we need to persist the user data so that they can use the same session in the future

how can we do that w/o changing source code of Botright?

I have some Updates planned which will make botright more compatible with playwright. Im reopening for now

@Vinyzu Vinyzu reopened this Jan 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants