handrew / browserpilot

Natural language browser automation
MIT License
497 stars 60 forks source link

user-data-dir not working? #12

Closed evanrmurphy closed 7 months ago

evanrmurphy commented 7 months ago

This is a cool project!

I'm trying to get my local browserpilot/chromedriver to use my own personal Chrome profile and sessions, but I can't get it working. Here's a a minimal example very similar to the one you provide that I'm using.

from browserpilot.agents.gpt_selenium_agent import GPTSeleniumAgent
from selenium import webdriver

instructions = """Go to Google.com
Find all textareas.
Find the first visible textarea.
Click on the first visible textarea.
Type in "buffalo buffalo buffalo buffalo buffalo" and press enter.
Wait 2 seconds.
Find all anchor elements that link to Wikipedia.
Click on the first one.
Wait for 10 seconds."""

chromedriver_path = "/Users/evan/Code/trying-browserpilot/chromedriver-mac-arm64/chromedriver"
chrome_profile_path = "/Users/evan/Library/Application Support/Google/Chrome/Profile 1"

chrome_options = {
    'user-data-dir': chrome_profile_path
}

agent = GPTSeleniumAgent(instructions, chromedriver_path, chrome_options)
agent.run()

It successfully launches Chrome and does the buffalo search. But even though I provide user-data-dir in the Chrome options, it still appears to be starting a fresh temporary profile, and I can see when it goes to Google.com that it is not signed into my Google account even though Profile 1 is.

Any tips on how to get this working?

handrew commented 7 months ago

Hey Evan, thanks for the interest. You know, I've never tried pointing it at the actual user directory. I suspect that if it's not working, it might be because the way that "actual" Chrome stores its cookies is different from how the Chromium instance stores cookies. I think the simplest fix would be to simply spin up a BrowserPilot Chromium instance, (say, with the instructions to go to Google.com and then wait 100 seconds), and then log in manually yourself.

It's a bit hacky, but that's how I've always done it.

evanrmurphy commented 7 months ago

Good point, could be another garden wall. I'll try your approach, thanks!

On Fri, Mar 29, 2024, 11:54 Andrew Han @.***> wrote:

Hey Evan, thanks for the interest. You know, I've never tried pointing it at the actual user directory. I suspect that if it's not working, it might be because the way that "actual" Chrome stores its cookies is different from how the Chromium instance stores cookies. I think the simplest fix would be to simply spin up a BrowserPilot Chromium instance, (say, with the instructions to go to Google.com and then wait 100 seconds), and then log in manually yourself.

It's a bit hacky, but that's how I've always done it.

— Reply to this email directly, view it on GitHub https://github.com/handrew/browserpilot/issues/12#issuecomment-2027606034, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACYSYZRIZUCMYJQ5R7WFR3Y2W2F5AVCNFSM6AAAAABFOXNA5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRXGYYDMMBTGQ . You are receiving this because you authored the thread.Message ID: @.***>

handrew commented 7 months ago

Did that work for you? Let me know—and I can close if so.

evanrmurphy commented 7 months ago

Thanks for following up. Yes it did work for me. Not quite the same as using a real profile but it's a good workaround.

Yes feel free to close this issue, thanks.

On Tue, Apr 2, 2024, 16:56 Andrew Han @.***> wrote:

Did that work for you? Let me know—and I can close if so.

— Reply to this email directly, view it on GitHub https://github.com/handrew/browserpilot/issues/12#issuecomment-2033297542, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACYSY4RKUDI5RMSUZQYBM3Y3NASRAVCNFSM6AAAAABFOXNA5WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZTGI4TONJUGI . You are receiving this because you authored the thread.Message ID: @.***>

handrew commented 7 months ago

Great to hear!