use std::path::{Path, PathBuf};
use super::extras::{HarRecorder, PdfOptions};
use super::tab::ChromiumTab;
use crate::Result;
pub struct PageCapture {
tab: ChromiumTab,
}
impl ChromiumTab {
pub fn capture(&self) -> PageCapture {
PageCapture { tab: self.clone() }
}
pub fn download(&self) -> crate::cdp::ChromiumDownloads {
self.downloads()
}
pub async fn upload(&self, selector: &str, path: &str) -> crate::Result<()> {
self.ele(selector).await?.upload(path).await
}
}
impl PageCapture {
pub async fn screenshot(&self) -> Result<Vec<u8>> {
self.tab.screenshot_bytes().await
}
pub async fn full_page(&self) -> Result<Vec<u8>> {
self.tab.screenshot_full_bytes().await
}
pub async fn pdf(&self, path: impl AsRef<Path>) -> Result<PathBuf> {
self.tab.save_pdf(path, &PdfOptions::default()).await
}
pub async fn mhtml(&self, path: impl AsRef<Path>) -> Result<PathBuf> {
self.tab.save_mhtml(path).await
}
pub async fn html(&self) -> Result<String> {
self.tab.html().await
}
pub async fn har(&self) -> Result<HarRecorder> {
self.tab.har_record().await
}
}