open-wa / wa-automate-python

💬 🤖 The most advanced Python whatsapp library for chatbots with advanced features. Be sure to ⭐ this repository for updates!
Other
330 stars 71 forks source link

Chrome remote support #78

Open alissonws opened 2 years ago

alissonws commented 2 years ago

Hello! First of all, awesome work on this project. It is being really usefull for me. I am migrating my project to Docker and went from chrome client to remote client. I then noticed that there appears to be no support for Chrome since it loads Firefox configurations by default when selecting remote client.

...
elif client == 'remote':
            if self._profile_path is not None:
                self._profile = webdriver.FirefoxProfile(self._profile_path)
            else:
                self._profile = webdriver.FirefoxProfile()

            options = Options()

            if headless:
                options.headless = True

            capabilities = DesiredCapabilities.FIREFOX.copy()
...

The only thing I'd like to know is if there is for that or it is just a feature that was not added yet. If it is just a matter of adding chrome options and profile to remote, I could try do develop something to solve this problem.

mrodal commented 2 years ago

Hey @alissonws! its true, it assumes remote is firefox. This is legacy code, and I never worked with remote browsers, but I believe its because at the start the whole project was meant for use with firefox and chrome was added after. As you say, it should work adding the options for chrome.

It would be great if you could come with something for this! maybe there will have to be a remote_chrome and remote_firefox clients?

alissonws commented 2 years ago

I think that maybe a better solution would be maintaining chrome and firefox clients and adding an argument called remote. So the user would choose the client and, if needed, it would be set up as remote by parsing remote = True. I believe that it is a better approach if a requirement of adding more clients comes up (like edge). I could also update the docs to show how to use this option, but it would be nice to know if the client="remote" is used anywhere else besides __init__() method. If we would have to rewrite a lot of methods, then we should go for remote_chrome and remote_firefox, but if it is just a matter of updating the if client == "remote" if-block, then I think we should go for client="chrome", remote=True.

mrodal commented 2 years ago

Indeed, I like that solution better! And yes, the client="remote" is only used to configure the browser in the __init__ method. Then it is also used in some example files (new_messages_observer.py and remote.py). Thanks for your contribution!

alissonws commented 2 years ago

Pushing this new feature at https://github.com/open-wa/wa-automate-python/pull/80