Skip to content

Commit

Permalink
Rollback PDL to stable and update fetcher to match (#245)
Browse files Browse the repository at this point in the history
* Fix lint issues

* Add comment on CDP version

* Update revision of fetcher

* Revert CDP and fetcher to stable
  • Loading branch information
Sytten authored Oct 24, 2024
1 parent c955148 commit 6f2392f
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 38 deletions.
8 changes: 3 additions & 5 deletions chromiumoxide_cdp/browser_protocol.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -532,8 +532,6 @@ experimental domain Audits
WarnDomainNonASCII
WarnThirdPartyPhaseout
WarnCrossSiteRedirectDowngradeChangesInclusion
WarnDeprecationTrialMetadata
WarnThirdPartyCookieHeuristic

type CookieOperation extends string
enum
Expand Down Expand Up @@ -4223,6 +4221,7 @@ domain Emulation
gyroscope
linear-acceleration
magnetometer
proximity
relative-orientation

experimental type SensorMetadata extends object
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -8090,7 +8089,6 @@ domain Page
deferred-fetch
digital-credentials-get
direct-sockets
direct-sockets-private
display-capture
document-domain
encrypted-media
Expand Down
5 changes: 3 additions & 2 deletions chromiumoxide_cdp/js_protocol.pdl
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ domain Debugger
properties
# Type of the debug symbols.
enum type
None
SourceMap
EmbeddedDWARF
ExternalDWARF
Expand Down Expand Up @@ -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

Expand Down
89 changes: 65 additions & 24 deletions chromiumoxide_cdp/src/cdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -7968,6 +7970,7 @@ pub mod js_protocol {
impl AsRef<str> for DebugSymbolsType {
fn as_ref(&self) -> &str {
match self {
DebugSymbolsType::None => "None",
DebugSymbolsType::SourceMap => "SourceMap",
DebugSymbolsType::EmbeddedDwarf => "EmbeddedDWARF",
DebugSymbolsType::ExternalDwarf => "ExternalDWARF",
Expand All @@ -7978,6 +7981,7 @@ pub mod js_protocol {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"None" | "none" => Ok(DebugSymbolsType::None),
"SourceMap" | "sourcemap" => Ok(DebugSymbolsType::SourceMap),
"EmbeddedDWARF" | "EmbeddedDwarf" | "embeddeddwarf" => {
Ok(DebugSymbolsType::EmbeddedDwarf)
Expand Down Expand Up @@ -11121,10 +11125,10 @@ pub mod js_protocol {
#[serde(default)]
#[serde(deserialize_with = "super::super::de::deserialize_from_str_optional")]
pub script_language: Option<super::debugger::ScriptLanguage>,
#[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<Vec<super::debugger::DebugSymbols>>,
pub debug_symbols: Option<super::debugger::DebugSymbols>,
#[doc = "The name the embedder supplied for this script."]
#[serde(rename = "embedderName")]
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down Expand Up @@ -21303,10 +21307,6 @@ pub mod browser_protocol {
WarnThirdPartyPhaseout,
#[serde(rename = "WarnCrossSiteRedirectDowngradeChangesInclusion")]
WarnCrossSiteRedirectDowngradeChangesInclusion,
#[serde(rename = "WarnDeprecationTrialMetadata")]
WarnDeprecationTrialMetadata,
#[serde(rename = "WarnThirdPartyCookieHeuristic")]
WarnThirdPartyCookieHeuristic,
}
impl AsRef<str> for CookieWarningReason {
fn as_ref(&self) -> &str {
Expand Down Expand Up @@ -21341,12 +21341,6 @@ pub mod browser_protocol {
CookieWarningReason::WarnCrossSiteRedirectDowngradeChangesInclusion => {
"WarnCrossSiteRedirectDowngradeChangesInclusion"
}
CookieWarningReason::WarnDeprecationTrialMetadata => {
"WarnDeprecationTrialMetadata"
}
CookieWarningReason::WarnThirdPartyCookieHeuristic => {
"WarnThirdPartyCookieHeuristic"
}
}
}
}
Expand Down Expand Up @@ -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()),
}
}
Expand Down Expand Up @@ -47627,6 +47615,8 @@ pub mod browser_protocol {
LinearAcceleration,
#[serde(rename = "magnetometer")]
Magnetometer,
#[serde(rename = "proximity")]
Proximity,
#[serde(rename = "relative-orientation")]
RelativeOrientation,
}
Expand All @@ -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",
}
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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<bool>) -> Self {
Self { show: show.into() }
}
}
impl SetShowWebVitalsParams {
pub fn builder() -> SetShowWebVitalsParamsBuilder {
SetShowWebVitalsParamsBuilder::default()
}
}
#[derive(Default, Clone)]
pub struct SetShowWebVitalsParamsBuilder {
show: Option<bool>,
}
impl SetShowWebVitalsParamsBuilder {
pub fn show(mut self, show: impl Into<bool>) -> Self {
self.show = Some(show.into());
self
}
pub fn build(self) -> Result<SetShowWebVitalsParams, String> {
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 {
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
}
Expand Down
16 changes: 15 additions & 1 deletion chromiumoxide_cdp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ 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);
pub const CURRENT_REVISION: Revision = Revision(1354347);

/// convenience fixups
impl Default for CreateTargetParams {
Expand Down
2 changes: 1 addition & 1 deletion chromiumoxide_cdp/tests/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
3 changes: 3 additions & 0 deletions chromiumoxide_fetcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion chromiumoxide_fetcher/src/browser/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl BrowserFetcherOptions {
BrowserFetcherOptionsBuilder::default()
}

#[allow(clippy::should_implement_trait)]
pub fn default() -> Result<Self> {
Self::builder().build()
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion chromiumoxide_fetcher/src/browser/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl<R: Read + Seek> ZipArchive<R> {
} else {
if let Some(p) = outpath.parent() {
if !p.exists() {
fs::create_dir_all(&p)?;
fs::create_dir_all(p)?;
}
}

Expand Down
19 changes: 18 additions & 1 deletion chromiumoxide_fetcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(1355984);

mod browser;
mod error;
Expand Down
3 changes: 2 additions & 1 deletion chromiumoxide_fetcher/src/platform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion chromiumoxide_fetcher/src/revision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl std::str::FromStr for Revision {
type Err = ParseIntError;

fn from_str(s: &str) -> Result<Self, Self::Err> {
s.parse::<u32>().map(|v| Self(v))
s.parse::<u32>().map(Self)
}
}

Expand Down
Loading

0 comments on commit 6f2392f

Please sign in to comment.