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

RE: Make this work for your own browser instead of spinning up an artificial one. #8

Open
bjsi opened this issue Nov 9, 2023 · 4 comments

Comments

@bjsi
Copy link

bjsi commented Nov 9, 2023

Make this work for your own browser instead of spinning up an artificial one. I want to be able to order food with my credit card.

You can pass the path to your chrome user data file to chromium like this I think eg:

 f"--user-data-dir={os.environ.get('CHROME_USER_DATA')}"

.env (eg for windows)

CHROME_USER_DATA = "c:\\Users\\<user name>\\AppData\\Local\\Google\\Chrome\\User Data\\"
@rgarcia
Copy link

rgarcia commented Nov 9, 2023

I've tried this here: main...rgarcia:vimGPT:feature/issue-8

But when I run it, the browser immediately closes and the script errors out:

Traceback (most recent call last):
  File "/Users/rafaelgarcia/code/vimGPT/main.py", line 28, in <module>
    main()
  File "/Users/rafaelgarcia/code/vimGPT/main.py", line 9, in main
    driver = Vimbot()
             ^^^^^^^^
  File "/Users/rafaelgarcia/code/vimGPT/vimbot.py", line 16, in __init__
    .chromium.launch_persistent_context(
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/sync_api/_generated.py", line 15031, in launch_persistent_context
    self._sync(
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/_impl/_sync_base.py", line 109, in _sync
    return task.result()
           ^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/_impl/_browser_type.py", line 158, in launch_persistent_context
    from_channel(await self._channel.send("launchPersistentContext", params)),
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 61, in send
    return await self._connection.wrap_api_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 490, in wrap_api_call
    return await cb()
           ^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/playwright/_impl/_connection.py", line 99, in inner_send
    result = next(iter(done)).result()
             ^^^^^^^^^^^^^^^^^^^^^^^^^
playwright._impl._api_types.Error: Browser closed.

@ishan0102
Copy link
Owner

interesting, I'll play around with this and see if I can get it working. my playwright skills are weak, for some reason when I start it up it makes two tabs as well

@peterw
Copy link

peterw commented Nov 10, 2023

One hacky way is to use PyAutoGui instead of Playwright, if you want to control your own personal browser.

@bjsi
Copy link
Author

bjsi commented Nov 11, 2023

import { Builder } from "selenium-webdriver";
import chrome from "selenium-webdriver/chrome";
import "chromedriver";
import dotenv from "dotenv";

dotenv.config();

const options = new chrome.Options();

const userDataDir = process.env["CHROME_USER_DATA"];

options.addArguments(`--user-data-dir=${userDataDir}`);
options.addArguments(`--profile-directory=Profile\ 1`);

const driver = await new Builder()
    .setChromeOptions(options)
    .forBrowser("chrome")
    .build();
    

This is how I do it in TypeScript + Selenium.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants