Feat: enable multi-browser support#718
Conversation
|
|
4d0805e to
8693853
Compare
|
I tried to generate new tests but there might be some issues in your codebase that I couldn't fix. 🔄 Could not generate any new tests. 🐛 Bug DetectionPotential issues found in the following files:
None. 🛠️ Test ResultsAll 0 tests passed. Settings | Logs | CodeBeaver |
|
Hey! Thanks for your effort, but could you revert the formatting changes, it makes it hard to review. You can raise a different PR for format/refactoring changes. |
9acc108 to
5194494
Compare
| browser = await browser_class.launch( | ||
| headless=self.config.headless, | ||
| args=[ | ||
| '--no-sandbox', |
There was a problem hiding this comment.
I'm not sure if the configuration here applies to all the browsers in the list, or if it's specific to Chromium.
There was a problem hiding this comment.
You are right. Not all the configurations will apply to firefox and safari webkit. Some args are common but not all. You have to conditionally set the args.
There was a problem hiding this comment.
I made the changes but I couldn't find alternatives for all the Chromium features. I tested both Firefox and WebKit, and the current configuration is working fine.
There was a problem hiding this comment.
@alimasri Could just check this image
For Firefox in Playwright, you should not pass args like you do for Chromium. Instead, use firefoxUserPrefs to configure browser behavior. if you check playwright.firefox.launch() there is an argument of firefoxUserPrefs.
reference: https://playwright.dev/docs/api/class-browsertype
There was a problem hiding this comment.
Passing args is working following https://wiki.mozilla.org/Firefox/CommandLineOptions. For a quick test try passing -migration to the firefox args.
I see that firefoxUserPrefs allows for other options, but what are the default ones that are necessary in here?
5194494 to
81f51a3
Compare
|
Hi! I'm trying to execute the real browser example (with reasonable modifications) in Firefox: import os
import sys
from pathlib import Path
from browser_use.agent.views import ActionResult
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import asyncio
from langchain_openai import ChatOpenAI
from browser_use import Agent, Controller
from browser_use.browser.browser import Browser, BrowserConfig
from browser_use.browser.context import BrowserContext
from dotenv import load_dotenv
from pydantic import SecretStr
# dotenv
load_dotenv()
api_key = os.getenv('DEEPSEEK_API_KEY', '')
if not api_key:
raise ValueError('DEEPSEEK_API_KEY is not set')
browser = Browser(
config=BrowserConfig(
browser_class='firefox',
browser_instance_path='C:\\Program Files\\Mozilla Firefox\\firefox.exe',
)
)
async def main():
agent = Agent(
task='In docs.google.com write my Papa a quick letter',
llm=ChatOpenAI(
base_url='https://api.deepseek.com/v1',
model='deepseek-chat',
api_key=SecretStr(api_key),
),
use_vision=False,
browser=browser,
)
await agent.run()
await browser.close()
input('Press Enter to close...')
if __name__ == '__main__':
asyncio.run(main())However, it gives me the error My Firefox version is 128.7.0esr. As far as I know, the CDP connections have been deprecated and turned off at the end of 2024 in Firefox and your code uses CDP connections. Do you have a workaround in mind? |
Thanks for the details. I'll test this and think of a solution. |
|
playwright can use webdriver bidi to talk to newer firefox versions, but I'm not sure if the rest of the code fully supports firefox currently. There are a few direct CDP calls. |
|
FYI @alimasri we have merged a different multi-browser-support PR #950 If there is anything you would like to add from this PR that you feel is missing, please rebase and open a new PR. Thank you for your patience and time working on this, we are getting a lot of overlapping PR submissions so we cant just merge them directly, but there are pieces of this PR that are useful and would be great as a new smaller PR. |
resolves #171