From 9f50f84f6c5116a4e1cb494bad3ef50a1801cb55 Mon Sep 17 00:00:00 2001 From: Nathan Mossaad Date: Fri, 9 Aug 2024 19:23:27 +0200 Subject: [PATCH 1/2] Added emulate_media_type function See: https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setEmulatedMedia (media is unused in function emulate_media_features) Also See: https://pptr.dev/api/puppeteer.page.emulatemediatype This is basically the newly implemented function --- src/page.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/page.rs b/src/page.rs index 79abb6c..0170896 100644 --- a/src/page.rs +++ b/src/page.rs @@ -639,6 +639,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, + ) -> 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, @@ -1343,3 +1358,23 @@ impl From 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 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(), + } + } +} \ No newline at end of file From 9acdd44096e4446e918e61912448017bc4c038db Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 12 Aug 2024 07:34:24 +0200 Subject: [PATCH 2/2] rustfmt --- src/page.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/page.rs b/src/page.rs index 8376c7e..f4409e9 100644 --- a/src/page.rs +++ b/src/page.rs @@ -1382,4 +1382,4 @@ impl From for String { MediaTypeParams::Print => "print".to_string(), } } -} \ No newline at end of file +}