Can't add chrome arg
deputinizer opened this issue · 4 comments
deputinizer commented
Hi, so I can't add chrome args because program crashes at:
let mut caps = DesiredCapabilities::chrome();
caps.set_headless()?; // panics here
Looks like this fixes the issue:
changing
["goog:chromeOptions"][key]
to
/// Get the specified Chrome option.
pub fn get_chrome_option<T>(&self, key: &str) -> T
where
T: DeserializeOwned + Default,
{
self.capabilities.get("goog:chromeOptions").map(|options| {
options.get(key).map(|option| from_value(option.clone()).unwrap_or_default()).unwrap_or_default()
}).unwrap_or_default()
}
samdevbr commented
Same issue here.
I've tested with v0.28.0
and it works just fine, I don't the exact version it broke.
nubis commented
This issue is caused because the 'args' chrome option is not initialized, so trying to add stuff to it fails.
Since args is just a shortcut method for chrome options, you can still set your args like this (I'm using these options for circleci but you probably get the idea).
caps.add_chrome_option("args", serde_json::to_value(vec![
"--headless".to_string(),
"--no-sandbox".to_string(),
"--disable-gpu".to_string(),
"--disable-dev-shm-usage".to_string(),
"--window-size=1920,1080".to_string(),
]).unwrap()).unwrap();
deputinizer commented
How to write this .map(...)
in a more 'Rusty' way?
self.capabilities.get("goog:chromeOptions").map(|options| {
options.get(key).map(|option| from_value(option.clone()).unwrap_or_default()).unwrap_or_default()
}).unwrap_or_default()
nubis commented
Since capabilities is a serde_json Map, I wonder if itos not possible to just rewrite it as
from_value(self.capabilities["goog:chromeOptions"].get(key).cloned().unwrap_or_default()).unwrap_or_default()