HENNGE / arsenic

Async WebDriver implementation for asyncio and asyncio-compatible frameworks
Other
350 stars 53 forks source link

Starting up Headless Firefox launches the GUI #46

Open Eternity71529 opened 5 years ago

Eternity71529 commented 5 years ago

Hi I recently started using Arsenic because it's asynchronous. So far I got the hang of the normal WebDrivers so I started with using a headless one. I made a Firefox session which had the argument which causes a browser to go headless written on it, When the script loads up, it shows that the argument has indeed been passed but the Firefox Browser GUI loads up, is there any fix to this or this is a local issue? Here is my code:

import asyncio
import sys

from arsenic import get_session, keys, browsers, services

if sys.platform.startswith('win'):
    GECKODRIVER = './geckodriver.exe'
else:
    GECKODRIVER = './geckodriver'

async def hello_world():
    service = services.Geckodriver()
    browser = browsers.Firefox(firefoxOptions={'args': ['-headless']})
    async with get_session(service, browser) as session:
        ....
def main():
    loop = asyncio.get_event_loop()
    loop.run_until_complete(hello_world())

if __name__ == '__main__':
    print("Starting!")
    main()
nokados commented 5 years ago

That works for me:

browser = browsers.Firefox(**{'moz:firefoxOptions': {'args': ['-headless']}})