Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emulate_media_type function #232

Merged
merged 3 commits into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,21 @@ impl Page {
Ok(self)
}

/// Changes the CSS media type of the page
// Based on https://pptr.dev/api/puppeteer.page.emulatemediatype
pub async fn emulate_media_type(
&self,
media_type: impl Into<MediaTypeParams>,
) -> Result<&Self> {
self.execute(
SetEmulatedMediaParams::builder()
.media(media_type.into())
.build(),
)
.await?;
Ok(self)
}

/// Overrides default host system timezone
pub async fn emulate_timezone(
&self,
Expand Down Expand Up @@ -1348,3 +1363,23 @@ impl From<CaptureScreenshotParams> for ScreenshotParams {
}
}
}

#[derive(Debug, Clone, Copy, Default)]
pub enum MediaTypeParams {
/// Default CSS media type behavior for page and print
#[default]
Null,
/// Force screen CSS media type for page and print
Screen,
/// Force print CSS media type for page and print
Print,
}
impl From<MediaTypeParams> for String {
fn from(media_type: MediaTypeParams) -> Self {
match media_type {
MediaTypeParams::Null => "null".to_string(),
MediaTypeParams::Screen => "screen".to_string(),
MediaTypeParams::Print => "print".to_string(),
}
}
}
Loading