Closed konstunn closed 3 years ago
I have no experience with this, but a quick glance at the documentation of chromedriver on how to do this, you should be able to pass the emulation mode as desired capabilities when instantiating the browser.
I have managed to do this. I will post here a piece of code demonstrating this soon.
Here is the code for chrome driver
from arsenic import services, browsers
service = services.Chromedriver(binary='chromedriver')
device_metrics = dict(width=1024, height=768, pixelRatio=1.0)
mobile_emulation = dict(deviceMetrics=device_metrics)
kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation)}
browser = browsers.Chrome(**kwargs)
async with get_session(service, browser) as session:
await session.get('/')
I suggest documenting this somewhere: FAQ, documentation, whatever.
Btw, we need such a strange kwarg as 'goog:chromeOptions' because mobileEmulation is considered as experimental capability, as far as I get it.
I dont know why but now I can not manage to run chrome in headless mode. This is how I try to do this
from arsenic import services, browsers
service = services.Chromedriver(binary='chromedriver')
device_metrics = dict(width=1024, height=768, pixelRatio=1.0)
mobile_emulation = dict(deviceMetrics=device_metrics)
kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation)}
browser = browsers.Chrome(chromeOptions={'args': [
'--headless',
'--disable-gpu',
]},
**kwargs
)
async with get_session(service, browser) as session:
await session.get('/')
This is how I managed to succeed to run device emulation and headless mode
from arsenic import services, browsers
service = services.Chromedriver(binary='chromedriver')
device_metrics = dict(width=1024, height=768, pixelRatio=1.0)
mobile_emulation = dict(deviceMetrics=device_metrics)
kwargs = {'goog:chromeOptions': dict(mobileEmulation=mobile_emulation,
args=['--headless', '--disable-gpu']
)
}
browser = browsers.Chrome(
**kwargs
)
async with get_session(service, browser) as session:
await session.get('/')
Please add PR to document these recipes! 🙏
Where should we document it? Is README suitable enough for that?
Documentation source code is here: https://github.com/HDE/arsenic/tree/main/docs I guess either howto or possibly tutorial?
Docs are ultimately pushed to https://arsenic.readthedocs.io/en/latest/
Here is the PR. Please have a look https://github.com/HDE/arsenic/pull/110
I have added the two recipes to browser-specific section "Supported browsers".
The pull request is merged so we might close the issue. Can we?
I need to test in 1024 x 768 fullscreen.
How can I do that?