Skip to content

Commit 184277d

Browse files
committed
Add emulation setLocaleOverride, setScreenOrientationOverride and setTimezoneOverride commands
1 parent 8b6d362 commit 184277d

File tree

9 files changed

+289
-241
lines changed

9 files changed

+289
-241
lines changed

Cargo.lock

Lines changed: 75 additions & 147 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
[package]
22
name = "webdriverbidi"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2024"
55
authors = ["Taha Hachana <tahahachana@gmail.com>"]
66
description = "WebDriver BiDi client implementation in Rust."
77
license = "MIT"
88
repository = "https://github.com/TahaHachana/webdriverbidi"
99

1010
[dependencies]
11-
tokio = { version = "1.44.2", features = ["full"] }
12-
tokio-tungstenite = "0.26.2"
11+
tokio = { version = "1.47.0", features = ["full"] }
12+
tokio-tungstenite = "0.27.0"
1313
serde = { version = "1.0.219", features = ["derive"] }
14-
serde_json = "1.0.140"
14+
serde_json = "1.0.141"
1515
futures = "0.3.31"
16-
reqwest = { version = "0.12.15", default-features = false, features = ["json"] }
16+
reqwest = { version = "0.12.22", default-features = false, features = ["json"] }
1717
thiserror = "2.0.12"
1818
log = "0.4.27"
1919

@@ -22,9 +22,9 @@ simplelog = "0.12.2"
2222
time = "0.3.41"
2323
env_logger = "0.11.8"
2424
base64 = "0.22.1"
25-
ctor = "0.4.1"
25+
ctor = "0.4.3"
2626
anyhow = "1.0.98"
2727
url = "2.5.4"
28-
axum = "0.8.3"
28+
axum = "0.8.4"
2929
tower = { version = "0.5.2", features = ["util"] }
3030
tower-http = { version = "0.6.2", features = ["fs"] }

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ async fn main() -> Result<()> {
178178
### emulation
179179
#### Commands
180180
- [x] emulation.setGeolocationOverride
181+
- [x] emulation.setLocaleOverride
182+
- [x] emulation.setScreenOrientationOverride
183+
- [x] emulation.setTimezoneOverride
181184

182185
### network
183186
#### Types

src/commands/emulation.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,30 @@ define_command!(
1717
set_geolocation_override,
1818
EmptyResult
1919
);
20+
21+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setLocaleOverride
22+
define_command!(
23+
SetLocaleOverrideCommand,
24+
SetLocaleOverride,
25+
SetLocaleOverrideParameters,
26+
set_locale_override,
27+
EmptyResult
28+
);
29+
30+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setScreenOrientationOverride
31+
define_command!(
32+
SetScreenOrientationOverrideCommand,
33+
SetScreenOrientationOverride,
34+
SetScreenOrientationOverrideParameters,
35+
set_screen_orientation_override,
36+
EmptyResult
37+
);
38+
39+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setTimezoneOverride
40+
define_command!(
41+
SetTimezoneOverrideCommand,
42+
SetTimezoneOverride,
43+
SetTimezoneOverrideParameters,
44+
set_timezone_override,
45+
EmptyResult
46+
);

src/model/browser.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::{commands::session, model::common::{EmptyParams, JsInt, JsUint}};
43
use crate::model::session::{ProxyConfiguration, UserPromptHandler};
4+
use crate::{
5+
commands::session,
6+
model::common::{EmptyParams, JsInt, JsUint},
7+
};
58

69
#[derive(Debug, Serialize, Deserialize)]
710
#[serde(untagged)]
@@ -106,11 +109,17 @@ impl CreateUserContext {
106109

107110
#[derive(Debug, Serialize, Deserialize)]
108111
pub struct CreateUserContextParameters {
109-
#[serde(rename = "acceptInsecureCerts", skip_serializing_if = "Option::is_none")]
112+
#[serde(
113+
rename = "acceptInsecureCerts",
114+
skip_serializing_if = "Option::is_none"
115+
)]
110116
pub accept_insecure_certs: Option<bool>,
111117
#[serde(skip_serializing_if = "Option::is_none")]
112118
pub proxy: Option<ProxyConfiguration>,
113-
#[serde(rename = "unhandledPromptBehavior", skip_serializing_if = "Option::is_none")]
119+
#[serde(
120+
rename = "unhandledPromptBehavior",
121+
skip_serializing_if = "Option::is_none"
122+
)]
114123
pub unhandled_prompt_behavior: Option<UserPromptHandler>,
115124
}
116125

src/model/emulation.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ impl SetGeolocationOverride {
2727
}
2828
}
2929

30-
3130
#[derive(Debug, Serialize, Deserialize)]
3231
#[serde(untagged)]
3332
pub enum SetGeolocationOverrideParameters {
@@ -132,6 +131,14 @@ pub struct SetLocaleOverride {
132131
pub params: SetLocaleOverrideParameters,
133132
}
134133

134+
impl SetLocaleOverride {
135+
pub fn new(params: SetLocaleOverrideParameters) -> Self {
136+
Self {
137+
method: "emulation.setLocaleOverride".to_string(),
138+
params,
139+
}
140+
}
141+
}
135142
#[derive(Debug, Serialize, Deserialize)]
136143
pub struct SetLocaleOverrideParameters {
137144
pub locale: Option<String>,
@@ -147,12 +154,21 @@ pub struct SetScreenOrientationOverride {
147154
pub params: SetScreenOrientationOverrideParameters,
148155
}
149156

157+
impl SetScreenOrientationOverride {
158+
pub fn new(params: SetScreenOrientationOverrideParameters) -> Self {
159+
Self {
160+
method: "emulation.setScreenOrientationOverride".to_string(),
161+
params,
162+
}
163+
}
164+
}
165+
150166
#[derive(Debug, Serialize, Deserialize)]
151167
#[serde(rename_all = "lowercase", untagged)]
152168
pub enum ScreenOrientationNatural {
153169
Portrait,
154170
Landscape,
155-
}
171+
}
156172

157173
#[derive(Debug, Serialize, Deserialize)]
158174
#[serde(rename_all = "kebab-case", untagged)]
@@ -186,6 +202,15 @@ pub struct SetTimezoneOverride {
186202
pub params: SetTimezoneOverrideParameters,
187203
}
188204

205+
impl SetTimezoneOverride {
206+
pub fn new(params: SetTimezoneOverrideParameters) -> Self {
207+
Self {
208+
method: "emulation.setTimezoneOverride".to_string(),
209+
params,
210+
}
211+
}
212+
}
213+
189214
#[derive(Debug, Serialize, Deserialize)]
190215
pub struct SetTimezoneOverrideParameters {
191216
pub timezone: Option<String>,

src/model/network.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::{Deserialize, Serialize};
22

3-
use crate::model::browsing_context::{BrowsingContext, Navigation};
43
use crate::model::browser::UserContext;
4+
use crate::model::browsing_context::{BrowsingContext, Navigation};
55
use crate::model::common::{Extensible, JsInt, JsUint};
66
use crate::model::script::StackTrace;
77

@@ -357,7 +357,11 @@ pub struct AddDataCollectorParameters {
357357
pub data_types: Vec<DataType>,
358358
#[serde(rename = "maxEncodedDataSize")]
359359
pub max_encoded_data_size: JsUint,
360-
#[serde(rename = "collectorType", default, skip_serializing_if = "Option::is_none")]
360+
#[serde(
361+
rename = "collectorType",
362+
default,
363+
skip_serializing_if = "Option::is_none"
364+
)]
361365
pub collector_type: Option<CollectorType>,
362366
#[serde(skip_serializing_if = "Option::is_none")]
363367
pub contexts: Option<Vec<BrowsingContext>>,
@@ -370,8 +374,6 @@ pub struct AddDataCollectorResult {
370374
pub collector: Collector,
371375
}
372376

373-
374-
375377
#[derive(Debug, Serialize, Deserialize)]
376378
pub struct AddIntercept {
377379
pub method: String,

src/session.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,60 @@ impl WebDriverBiDiSession {
642642
) -> Result<EmptyResult, CommandError> {
643643
commands::emulation::set_geolocation_override(self, params).await
644644
}
645+
646+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setLocaleOverride
647+
648+
/// Modifies locale on the given top-level traversables or user contexts.
649+
///
650+
/// # Arguments
651+
///
652+
/// * `params` - The parameters as a `SetLocaleOverrideParameters` instance.
653+
///
654+
/// # Returns
655+
///
656+
/// A result containing the `EmptyResult` or a `CommandError`.
657+
pub async fn set_locale_override(
658+
&mut self,
659+
params: SetLocaleOverrideParameters,
660+
) -> Result<EmptyResult, CommandError> {
661+
commands::emulation::set_locale_override(self, params).await
662+
}
663+
664+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setScreenOrientationOverride
665+
666+
/// Emulates screen orientation of the given top-level traversables or user contexts.
667+
///
668+
/// # Arguments
669+
///
670+
/// * `params` - The parameters as a `SetScreenOrientationOverrideParameters` instance.
671+
///
672+
/// # Returns
673+
///
674+
/// A result containing the `EmptyResult` or a `CommandError`.
675+
pub async fn set_screen_orientation_override(
676+
&mut self,
677+
params: SetScreenOrientationOverrideParameters,
678+
) -> Result<EmptyResult, CommandError> {
679+
commands::emulation::set_screen_orientation_override(self, params).await
680+
}
681+
682+
// https://w3c.github.io/webdriver-bidi/#command-emulation-setTimezoneOverride
683+
684+
/// Modifies timezone on the given top-level traversables or user contexts.
685+
///
686+
/// # Arguments
687+
///
688+
/// * `params` - The parameters as a `SetTimezoneOverrideParameters` instance.
689+
///
690+
/// # Returns
691+
///
692+
/// A result containing the `EmptyResult` or a `CommandError`.
693+
pub async fn set_timezone_override(
694+
&mut self,
695+
params: SetTimezoneOverrideParameters,
696+
) -> Result<EmptyResult, CommandError> {
697+
commands::emulation::set_timezone_override(self, params).await
698+
}
645699
}
646700

647701
// Network commands

0 commit comments

Comments
 (0)