From 54f38cb1eaeb2e7984fbdbd2ad45ea17efd79e2c Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Wed, 23 Oct 2024 17:37:56 -0400 Subject: [PATCH 1/4] Fix lint issues --- chromiumoxide_cdp/tests/generate.rs | 2 +- chromiumoxide_fetcher/src/browser/options.rs | 3 ++- chromiumoxide_fetcher/src/browser/zip.rs | 2 +- chromiumoxide_fetcher/src/revision.rs | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/chromiumoxide_cdp/tests/generate.rs b/chromiumoxide_cdp/tests/generate.rs index 9c49e70e..09faf760 100644 --- a/chromiumoxide_cdp/tests/generate.rs +++ b/chromiumoxide_cdp/tests/generate.rs @@ -18,7 +18,7 @@ fn generated_code_is_fresh() { let tmp = tempfile::tempdir().unwrap(); Generator::default() - .out_dir(&tmp.path()) + .out_dir(tmp.path()) .experimental(env::var("CDP_NO_EXPERIMENTAL").is_err()) .deprecated(env::var("CDP_DEPRECATED").is_ok()) .compile_pdls(&[js_proto, browser_proto]) diff --git a/chromiumoxide_fetcher/src/browser/options.rs b/chromiumoxide_fetcher/src/browser/options.rs index 39d532b1..3ac2c481 100644 --- a/chromiumoxide_fetcher/src/browser/options.rs +++ b/chromiumoxide_fetcher/src/browser/options.rs @@ -36,6 +36,7 @@ impl BrowserFetcherOptions { BrowserFetcherOptionsBuilder::default() } + #[allow(clippy::should_implement_trait)] pub fn default() -> Result { Self::builder().build() } @@ -84,7 +85,7 @@ impl BrowserFetcherOptionsBuilder { let platform = self.platform - .or_else(|| Platform::current()) + .or_else(Platform::current) .ok_or(FetcherError::UnsupportedOs( std::env::consts::OS, std::env::consts::ARCH, diff --git a/chromiumoxide_fetcher/src/browser/zip.rs b/chromiumoxide_fetcher/src/browser/zip.rs index 97fbe613..1b3b721e 100644 --- a/chromiumoxide_fetcher/src/browser/zip.rs +++ b/chromiumoxide_fetcher/src/browser/zip.rs @@ -48,7 +48,7 @@ impl ZipArchive { } else { if let Some(p) = outpath.parent() { if !p.exists() { - fs::create_dir_all(&p)?; + fs::create_dir_all(p)?; } } diff --git a/chromiumoxide_fetcher/src/revision.rs b/chromiumoxide_fetcher/src/revision.rs index 8768fc90..5fedab57 100644 --- a/chromiumoxide_fetcher/src/revision.rs +++ b/chromiumoxide_fetcher/src/revision.rs @@ -24,7 +24,7 @@ impl std::str::FromStr for Revision { type Err = ParseIntError; fn from_str(s: &str) -> Result { - s.parse::().map(|v| Self(v)) + s.parse::().map(Self) } } From 8e0eb97b7edd64a0421fd684b54dc76a30fdd1b3 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Thu, 24 Oct 2024 00:02:50 -0400 Subject: [PATCH 2/4] Add comment on CDP version --- chromiumoxide_cdp/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/chromiumoxide_cdp/src/lib.rs b/chromiumoxide_cdp/src/lib.rs index 7fbd12d8..739917e4 100644 --- a/chromiumoxide_cdp/src/lib.rs +++ b/chromiumoxide_cdp/src/lib.rs @@ -14,6 +14,20 @@ use crate::revision::Revision; pub mod cdp; pub mod revision; +// The CDP is not a stable API, it changes from time to time and sometimes +// in backward incompatible ways. +// +// When the CDP changes, the chromium team pushes a commit to the repository +// https://github.com/ChromeDevTools/devtools-protocol. There you can find +// valid CDP revisions. That number corresponds to a chromium revision. +// It is a monotonic version number referring to the chromium master commit position. +// +// To map a revision to a chromium version you can use the site +// https://chromiumdash.appspot.com/commits. We should not necessarily +// always use the latest revision, as this will mean only the newest chromium +// browser can be used. Apart from breaking changes, using an older CDP +// is generally a good idea. + /// Currently built CDP revision pub const CURRENT_REVISION: Revision = Revision(1359167); From ab2bb64cd9c5ce41384391a82b512fc05af67b5b Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Thu, 24 Oct 2024 00:35:05 -0400 Subject: [PATCH 3/4] Update revision of fetcher --- chromiumoxide_fetcher/Cargo.toml | 3 ++ chromiumoxide_fetcher/src/lib.rs | 19 ++++++++- chromiumoxide_fetcher/src/platform.rs | 3 +- chromiumoxide_fetcher/tests/verify.rs | 57 +++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 chromiumoxide_fetcher/tests/verify.rs diff --git a/chromiumoxide_fetcher/Cargo.toml b/chromiumoxide_fetcher/Cargo.toml index 359ba34a..1eabc8ca 100644 --- a/chromiumoxide_fetcher/Cargo.toml +++ b/chromiumoxide_fetcher/Cargo.toml @@ -11,6 +11,9 @@ repository = "https://github.com/mattsse/chromiumoxide" readme = "../README.md" include = ["src/**/*", "LICENSE-*"] +[dev-dependencies] +ureq = "2.10.0" + [dependencies] thiserror = "1" anyhow = "1" diff --git a/chromiumoxide_fetcher/src/lib.rs b/chromiumoxide_fetcher/src/lib.rs index 7067eb07..94ed47d5 100644 --- a/chromiumoxide_fetcher/src/lib.rs +++ b/chromiumoxide_fetcher/src/lib.rs @@ -3,8 +3,25 @@ pub use self::error::FetcherError; pub use self::platform::Platform; pub use self::revision::Revision; +// The chromium revision is hard to get right and the relation to the CDP revision +// even more so, so here are some guidances. +// +// We used to use the revision of Puppeteer, but they switched to chrome-for-testing. +// This means we have to check things ourself. The chromium revision should at least +// as great as the CDP revision otherwise they won't be compatible. +// Not all revisions of chromium have builds for all platforms. +// +// This is essentially a bruteforce process. You can use the test `find_revision_available` +// to find a revision that is available for all platforms. We recommend setting the `min` +// to the current CDP revision and the max to max revision of stable chromium. +// See https://chromiumdash.appspot.com/releases for the latest stable revision. +// +// In general, we should also try to ship as close as a stable version of chromium if possible. +// The CDP should also be a bit older than that stable version. +// To map a revision to a chromium version you can use the site https://chromiumdash.appspot.com/commits. + /// Currently downloaded chromium revision -pub const CURRENT_REVISION: Revision = Revision(1045629); +pub const CURRENT_REVISION: Revision = Revision(1362488); mod browser; mod error; diff --git a/chromiumoxide_fetcher/src/platform.rs b/chromiumoxide_fetcher/src/platform.rs index 47bfd25a..e969ec04 100644 --- a/chromiumoxide_fetcher/src/platform.rs +++ b/chromiumoxide_fetcher/src/platform.rs @@ -13,7 +13,8 @@ pub enum Platform { } impl Platform { - pub(crate) fn download_url(&self, host: &str, revision: &Revision) -> String { + #[doc(hidden)] // internal API + pub fn download_url(&self, host: &str, revision: &Revision) -> String { let archive = self.archive_name(revision); let name = match self { Self::Linux => "Linux_x64", diff --git a/chromiumoxide_fetcher/tests/verify.rs b/chromiumoxide_fetcher/tests/verify.rs new file mode 100644 index 00000000..48689c64 --- /dev/null +++ b/chromiumoxide_fetcher/tests/verify.rs @@ -0,0 +1,57 @@ +use chromiumoxide_fetcher::{Platform, Revision, CURRENT_REVISION}; + +// Check if the chosen revision has a build available for all platforms. +// That not always the case, that is why we need to make sure of it. +#[test] +fn verify_revision_available() { + for platform in &[ + Platform::Linux, + Platform::Mac, + Platform::MacArm, + Platform::Win32, + Platform::Win64, + ] { + let res = + ureq::head(&platform.download_url("https://storage.googleapis.com", &CURRENT_REVISION)) + .call(); + + if res.is_err() { + panic!( + "Revision {} is not available for {:?}", + CURRENT_REVISION, platform + ); + } + } +} + +#[ignore] +#[test] +fn find_revision_available() { + let min = 1361485; // Enter the minimum revision + let max = 1362838; // Enter the maximum revision + + 'outer: for revision in (min..max).rev() { + println!("Checking revision {}", revision); + + for platform in &[ + Platform::Linux, + Platform::Mac, + Platform::MacArm, + Platform::Win32, + Platform::Win64, + ] { + let res = ureq::head( + &platform.download_url("https://storage.googleapis.com", &Revision::from(revision)), + ) + .call(); + + if res.is_err() { + println!("Revision {} is not available for {:?}", revision, platform); + continue 'outer; + } + } + + println!("Found revision {}", revision); + break; + } +} From a1e762025d81557e01a4320ca2e8758d16b51924 Mon Sep 17 00:00:00 2001 From: Emile Fugulin Date: Thu, 24 Oct 2024 00:42:27 -0400 Subject: [PATCH 4/4] Revert CDP and fetcher to stable --- chromiumoxide_cdp/browser_protocol.pdl | 8 +-- chromiumoxide_cdp/js_protocol.pdl | 5 +- chromiumoxide_cdp/src/cdp.rs | 89 +++++++++++++++++++------- chromiumoxide_cdp/src/lib.rs | 2 +- chromiumoxide_fetcher/src/lib.rs | 2 +- chromiumoxide_fetcher/tests/verify.rs | 4 +- 6 files changed, 75 insertions(+), 35 deletions(-) diff --git a/chromiumoxide_cdp/browser_protocol.pdl b/chromiumoxide_cdp/browser_protocol.pdl index 07e17ba5..6f07fe34 100644 --- a/chromiumoxide_cdp/browser_protocol.pdl +++ b/chromiumoxide_cdp/browser_protocol.pdl @@ -532,8 +532,6 @@ experimental domain Audits WarnDomainNonASCII WarnThirdPartyPhaseout WarnCrossSiteRedirectDowngradeChangesInclusion - WarnDeprecationTrialMetadata - WarnThirdPartyCookieHeuristic type CookieOperation extends string enum @@ -4223,6 +4221,7 @@ domain Emulation gyroscope linear-acceleration magnetometer + proximity relative-orientation experimental type SensorMetadata extends object @@ -7925,8 +7924,8 @@ experimental domain Overlay # True for showing hit-test borders boolean show - # Deprecated, no longer has any effect. - deprecated command setShowWebVitals + # Request that backend shows an overlay with web vital metrics. + command setShowWebVitals parameters boolean show @@ -8090,7 +8089,6 @@ domain Page deferred-fetch digital-credentials-get direct-sockets - direct-sockets-private display-capture document-domain encrypted-media diff --git a/chromiumoxide_cdp/js_protocol.pdl b/chromiumoxide_cdp/js_protocol.pdl index b106a709..8dad9c98 100644 --- a/chromiumoxide_cdp/js_protocol.pdl +++ b/chromiumoxide_cdp/js_protocol.pdl @@ -606,6 +606,7 @@ domain Debugger properties # Type of the debug symbols. enum type + None SourceMap EmbeddedDWARF ExternalDWARF @@ -688,8 +689,8 @@ domain Debugger experimental optional integer codeOffset # The language of the script. experimental optional Debugger.ScriptLanguage scriptLanguage - # If the scriptLanguage is WebAssembly, the source of debug symbols for the module. - experimental optional array of Debugger.DebugSymbols debugSymbols + # If the scriptLanguage is WebASsembly, the source of debug symbols for the module. + experimental optional Debugger.DebugSymbols debugSymbols # The name the embedder supplied for this script. experimental optional string embedderName diff --git a/chromiumoxide_cdp/src/cdp.rs b/chromiumoxide_cdp/src/cdp.rs index 1bb712ae..c3f55df0 100644 --- a/chromiumoxide_cdp/src/cdp.rs +++ b/chromiumoxide_cdp/src/cdp.rs @@ -7958,6 +7958,8 @@ pub mod js_protocol { #[doc = "Type of the debug symbols."] #[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)] pub enum DebugSymbolsType { + #[serde(rename = "None")] + None, #[serde(rename = "SourceMap")] SourceMap, #[serde(rename = "EmbeddedDWARF")] @@ -7968,6 +7970,7 @@ pub mod js_protocol { impl AsRef for DebugSymbolsType { fn as_ref(&self) -> &str { match self { + DebugSymbolsType::None => "None", DebugSymbolsType::SourceMap => "SourceMap", DebugSymbolsType::EmbeddedDwarf => "EmbeddedDWARF", DebugSymbolsType::ExternalDwarf => "ExternalDWARF", @@ -7978,6 +7981,7 @@ pub mod js_protocol { type Err = String; fn from_str(s: &str) -> Result { match s { + "None" | "none" => Ok(DebugSymbolsType::None), "SourceMap" | "sourcemap" => Ok(DebugSymbolsType::SourceMap), "EmbeddedDWARF" | "EmbeddedDwarf" | "embeddeddwarf" => { Ok(DebugSymbolsType::EmbeddedDwarf) @@ -11121,10 +11125,10 @@ pub mod js_protocol { #[serde(default)] #[serde(deserialize_with = "super::super::de::deserialize_from_str_optional")] pub script_language: Option, - #[doc = "If the scriptLanguage is WebAssembly, the source of debug symbols for the module."] + #[doc = "If the scriptLanguage is WebASsembly, the source of debug symbols for the module."] #[serde(rename = "debugSymbols")] #[serde(skip_serializing_if = "Option::is_none")] - pub debug_symbols: Option>, + pub debug_symbols: Option, #[doc = "The name the embedder supplied for this script."] #[serde(rename = "embedderName")] #[serde(skip_serializing_if = "Option::is_none")] @@ -21303,10 +21307,6 @@ pub mod browser_protocol { WarnThirdPartyPhaseout, #[serde(rename = "WarnCrossSiteRedirectDowngradeChangesInclusion")] WarnCrossSiteRedirectDowngradeChangesInclusion, - #[serde(rename = "WarnDeprecationTrialMetadata")] - WarnDeprecationTrialMetadata, - #[serde(rename = "WarnThirdPartyCookieHeuristic")] - WarnThirdPartyCookieHeuristic, } impl AsRef for CookieWarningReason { fn as_ref(&self) -> &str { @@ -21341,12 +21341,6 @@ pub mod browser_protocol { CookieWarningReason::WarnCrossSiteRedirectDowngradeChangesInclusion => { "WarnCrossSiteRedirectDowngradeChangesInclusion" } - CookieWarningReason::WarnDeprecationTrialMetadata => { - "WarnDeprecationTrialMetadata" - } - CookieWarningReason::WarnThirdPartyCookieHeuristic => { - "WarnThirdPartyCookieHeuristic" - } } } } @@ -21397,12 +21391,6 @@ pub mod browser_protocol { | "warncrosssiteredirectdowngradechangesinclusion" => { Ok(CookieWarningReason::WarnCrossSiteRedirectDowngradeChangesInclusion) } - "WarnDeprecationTrialMetadata" | "warndeprecationtrialmetadata" => { - Ok(CookieWarningReason::WarnDeprecationTrialMetadata) - } - "WarnThirdPartyCookieHeuristic" | "warnthirdpartycookieheuristic" => { - Ok(CookieWarningReason::WarnThirdPartyCookieHeuristic) - } _ => Err(s.to_string()), } } @@ -47627,6 +47615,8 @@ pub mod browser_protocol { LinearAcceleration, #[serde(rename = "magnetometer")] Magnetometer, + #[serde(rename = "proximity")] + Proximity, #[serde(rename = "relative-orientation")] RelativeOrientation, } @@ -47640,6 +47630,7 @@ pub mod browser_protocol { SensorType::Gyroscope => "gyroscope", SensorType::LinearAcceleration => "linear-acceleration", SensorType::Magnetometer => "magnetometer", + SensorType::Proximity => "proximity", SensorType::RelativeOrientation => "relative-orientation", } } @@ -47659,6 +47650,7 @@ pub mod browser_protocol { Ok(SensorType::LinearAcceleration) } "magnetometer" | "Magnetometer" => Ok(SensorType::Magnetometer), + "proximity" | "Proximity" => Ok(SensorType::Proximity), "relative-orientation" | "RelativeOrientation" => { Ok(SensorType::RelativeOrientation) } @@ -70361,6 +70353,61 @@ pub mod browser_protocol { impl chromiumoxide_types::Command for SetShowScrollBottleneckRectsParams { type Response = SetShowScrollBottleneckRectsReturns; } + #[doc = "Request that backend shows an overlay with web vital metrics.\n[setShowWebVitals](https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowWebVitals)"] + #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] + pub struct SetShowWebVitalsParams { + #[serde(rename = "show")] + pub show: bool, + } + impl SetShowWebVitalsParams { + pub fn new(show: impl Into) -> Self { + Self { show: show.into() } + } + } + impl SetShowWebVitalsParams { + pub fn builder() -> SetShowWebVitalsParamsBuilder { + SetShowWebVitalsParamsBuilder::default() + } + } + #[derive(Default, Clone)] + pub struct SetShowWebVitalsParamsBuilder { + show: Option, + } + impl SetShowWebVitalsParamsBuilder { + pub fn show(mut self, show: impl Into) -> Self { + self.show = Some(show.into()); + self + } + pub fn build(self) -> Result { + Ok(SetShowWebVitalsParams { + show: self.show.ok_or_else(|| { + format!("Field `{}` is mandatory.", std::stringify!(show)) + })?, + }) + } + } + impl SetShowWebVitalsParams { + pub const IDENTIFIER: &'static str = "Overlay.setShowWebVitals"; + } + impl chromiumoxide_types::Method for SetShowWebVitalsParams { + fn identifier(&self) -> chromiumoxide_types::MethodId { + Self::IDENTIFIER.into() + } + } + impl chromiumoxide_types::MethodType for SetShowWebVitalsParams { + fn method_id() -> chromiumoxide_types::MethodId + where + Self: Sized, + { + Self::IDENTIFIER.into() + } + } + #[doc = "Request that backend shows an overlay with web vital metrics.\n[setShowWebVitals](https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowWebVitals)"] + #[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)] + pub struct SetShowWebVitalsReturns {} + impl chromiumoxide_types::Command for SetShowWebVitalsParams { + type Response = SetShowWebVitalsReturns; + } #[doc = "Paints viewport size upon main frame resize.\n[setShowViewportSizeOnResize](https://chromedevtools.github.io/devtools-protocol/tot/Overlay/#method-setShowViewportSizeOnResize)"] #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub struct SetShowViewportSizeOnResizeParams { @@ -71124,8 +71171,6 @@ pub mod browser_protocol { DigitalCredentialsGet, #[serde(rename = "direct-sockets")] DirectSockets, - #[serde(rename = "direct-sockets-private")] - DirectSocketsPrivate, #[serde(rename = "display-capture")] DisplayCapture, #[serde(rename = "document-domain")] @@ -71274,7 +71319,6 @@ pub mod browser_protocol { PermissionsPolicyFeature::DeferredFetch => "deferred-fetch", PermissionsPolicyFeature::DigitalCredentialsGet => "digital-credentials-get", PermissionsPolicyFeature::DirectSockets => "direct-sockets", - PermissionsPolicyFeature::DirectSocketsPrivate => "direct-sockets-private", PermissionsPolicyFeature::DisplayCapture => "display-capture", PermissionsPolicyFeature::DocumentDomain => "document-domain", PermissionsPolicyFeature::EncryptedMedia => "encrypted-media", @@ -71437,9 +71481,6 @@ pub mod browser_protocol { "direct-sockets" | "DirectSockets" => { Ok(PermissionsPolicyFeature::DirectSockets) } - "direct-sockets-private" | "DirectSocketsPrivate" => { - Ok(PermissionsPolicyFeature::DirectSocketsPrivate) - } "display-capture" | "DisplayCapture" => { Ok(PermissionsPolicyFeature::DisplayCapture) } diff --git a/chromiumoxide_cdp/src/lib.rs b/chromiumoxide_cdp/src/lib.rs index 739917e4..933da070 100644 --- a/chromiumoxide_cdp/src/lib.rs +++ b/chromiumoxide_cdp/src/lib.rs @@ -29,7 +29,7 @@ pub mod revision; // is generally a good idea. /// Currently built CDP revision -pub const CURRENT_REVISION: Revision = Revision(1359167); +pub const CURRENT_REVISION: Revision = Revision(1354347); /// convenience fixups impl Default for CreateTargetParams { diff --git a/chromiumoxide_fetcher/src/lib.rs b/chromiumoxide_fetcher/src/lib.rs index 94ed47d5..d298a003 100644 --- a/chromiumoxide_fetcher/src/lib.rs +++ b/chromiumoxide_fetcher/src/lib.rs @@ -21,7 +21,7 @@ pub use self::revision::Revision; // To map a revision to a chromium version you can use the site https://chromiumdash.appspot.com/commits. /// Currently downloaded chromium revision -pub const CURRENT_REVISION: Revision = Revision(1362488); +pub const CURRENT_REVISION: Revision = Revision(1355984); mod browser; mod error; diff --git a/chromiumoxide_fetcher/tests/verify.rs b/chromiumoxide_fetcher/tests/verify.rs index 48689c64..732ef375 100644 --- a/chromiumoxide_fetcher/tests/verify.rs +++ b/chromiumoxide_fetcher/tests/verify.rs @@ -27,8 +27,8 @@ fn verify_revision_available() { #[ignore] #[test] fn find_revision_available() { - let min = 1361485; // Enter the minimum revision - let max = 1362838; // Enter the maximum revision + let min = 1355000; // Enter the minimum revision + let max = 1356013; // Enter the maximum revision 'outer: for revision in (min..max).rev() { println!("Checking revision {}", revision);