use serde::Serialize;
use crate::cdp::Cdp;
use crate::cdp::command::{CdpCommand, Empty};
use crate::error::WebDriverResult;
#[derive(Debug, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClearDataForOrigin {
pub origin: String,
pub storage_types: String,
}
impl CdpCommand for ClearDataForOrigin {
const METHOD: &'static str = "Storage.clearDataForOrigin";
type Returns = Empty;
}
#[derive(Debug, Clone, Default, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ClearCookies {
#[serde(skip_serializing_if = "Option::is_none")]
pub browser_context_id: Option<String>,
}
impl CdpCommand for ClearCookies {
const METHOD: &'static str = "Storage.clearCookies";
type Returns = Empty;
}
#[derive(Debug)]
pub struct StorageDomain<'a> {
cdp: &'a Cdp,
}
impl<'a> StorageDomain<'a> {
pub(crate) fn new(cdp: &'a Cdp) -> Self {
Self {
cdp,
}
}
pub async fn clear_all_data_for_origin(
&self,
origin: impl Into<String>,
) -> WebDriverResult<()> {
self.cdp
.send(ClearDataForOrigin {
origin: origin.into(),
storage_types: "all".to_string(),
})
.await?;
Ok(())
}
pub async fn clear_cookies(&self) -> WebDriverResult<()> {
self.cdp.send(ClearCookies::default()).await?;
Ok(())
}
}