Skip to content

Commit cfe7e1f

Browse files
authored
[rust] Fix webview2 support (#12966)
[rust] Improve support for webview2
1 parent b008e15 commit cfe7e1f

File tree

3 files changed

+82
-54
lines changed

3 files changed

+82
-54
lines changed

rust/src/edge.rs

Lines changed: 70 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::metadata::{
2525
};
2626
use crate::{
2727
create_http_client, get_binary_extension, path_to_string, Logger, SeleniumManager, BETA,
28-
DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES_X86, NIGHTLY, OFFLINE_REQUEST_ERR_MSG,
28+
DASH_DASH_VERSION, DEV, ENV_PROGRAM_FILES_X86, NIGHTLY, OFFLINE_REQUEST_ERR_MSG, REG_PV_ARG,
2929
REG_VERSION_ARG, STABLE,
3030
};
3131
use anyhow::Error;
@@ -104,54 +104,79 @@ impl SeleniumManager for EdgeManager {
104104
}
105105

106106
fn get_browser_path_map(&self) -> HashMap<BrowserPath, &str> {
107-
HashMap::from([
108-
(
107+
if self.is_webview2() {
108+
HashMap::from([(
109109
BrowserPath::new(WINDOWS, STABLE),
110-
r#"Microsoft\Edge\Application\msedge.exe"#,
111-
),
112-
(
113-
BrowserPath::new(WINDOWS, BETA),
114-
r#"Microsoft\Edge Beta\Application\msedge.exe"#,
115-
),
116-
(
117-
BrowserPath::new(WINDOWS, DEV),
118-
r#"Microsoft\Edge Dev\Application\msedge.exe"#,
119-
),
120-
(
121-
BrowserPath::new(WINDOWS, NIGHTLY),
122-
r#"Microsoft\Edge SxS\Application\msedge.exe"#,
123-
),
124-
(
125-
BrowserPath::new(MACOS, STABLE),
126-
r#"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"#,
127-
),
128-
(
129-
BrowserPath::new(MACOS, BETA),
130-
r#"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta"#,
131-
),
132-
(
133-
BrowserPath::new(MACOS, DEV),
134-
r#"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"#,
135-
),
136-
(
137-
BrowserPath::new(MACOS, NIGHTLY),
138-
r#"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary"#,
139-
),
140-
(BrowserPath::new(LINUX, STABLE), "/usr/bin/microsoft-edge"),
141-
(
142-
BrowserPath::new(LINUX, BETA),
143-
"/usr/bin/microsoft-edge-beta",
144-
),
145-
(BrowserPath::new(LINUX, DEV), "/usr/bin/microsoft-edge-dev"),
146-
])
110+
r#"Microsoft\EdgeWebView\Application"#,
111+
)])
112+
} else {
113+
HashMap::from([
114+
(
115+
BrowserPath::new(WINDOWS, STABLE),
116+
r#"Microsoft\Edge\Application\msedge.exe"#,
117+
),
118+
(
119+
BrowserPath::new(WINDOWS, BETA),
120+
r#"Microsoft\Edge Beta\Application\msedge.exe"#,
121+
),
122+
(
123+
BrowserPath::new(WINDOWS, DEV),
124+
r#"Microsoft\Edge Dev\Application\msedge.exe"#,
125+
),
126+
(
127+
BrowserPath::new(WINDOWS, NIGHTLY),
128+
r#"Microsoft\Edge SxS\Application\msedge.exe"#,
129+
),
130+
(
131+
BrowserPath::new(MACOS, STABLE),
132+
r#"/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"#,
133+
),
134+
(
135+
BrowserPath::new(MACOS, BETA),
136+
r#"/Applications/Microsoft Edge Beta.app/Contents/MacOS/Microsoft Edge Beta"#,
137+
),
138+
(
139+
BrowserPath::new(MACOS, DEV),
140+
r#"/Applications/Microsoft Edge Dev.app/Contents/MacOS/Microsoft Edge Dev"#,
141+
),
142+
(
143+
BrowserPath::new(MACOS, NIGHTLY),
144+
r#"/Applications/Microsoft Edge Canary.app/Contents/MacOS/Microsoft Edge Canary"#,
145+
),
146+
(BrowserPath::new(LINUX, STABLE), "/usr/bin/microsoft-edge"),
147+
(
148+
BrowserPath::new(LINUX, BETA),
149+
"/usr/bin/microsoft-edge-beta",
150+
),
151+
(BrowserPath::new(LINUX, DEV), "/usr/bin/microsoft-edge-dev"),
152+
])
153+
}
147154
}
148155

149156
fn discover_browser_version(&mut self) -> Result<Option<String>, Error> {
150-
self.general_discover_browser_version(
151-
r#"HKCU\Software\Microsoft\Edge\BLBeacon"#,
152-
REG_VERSION_ARG,
153-
DASH_DASH_VERSION,
154-
)
157+
let (reg_key, reg_version_arg, cmd_version_arg) = if self.is_webview2() {
158+
let arch = self.get_arch();
159+
if X32.is(arch) {
160+
(
161+
r#"HKLM\SOFTWARE\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#,
162+
REG_PV_ARG,
163+
"",
164+
)
165+
} else {
166+
(
167+
r#"HKLM\SOFTWARE\WOW6432Node\Microsoft\EdgeUpdate\Clients\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}"#,
168+
REG_PV_ARG,
169+
"",
170+
)
171+
}
172+
} else {
173+
(
174+
r#"HKCU\Software\Microsoft\Edge\BLBeacon"#,
175+
REG_VERSION_ARG,
176+
DASH_DASH_VERSION,
177+
)
178+
};
179+
self.general_discover_browser_version(reg_key, reg_version_arg, cmd_version_arg)
155180
}
156181

157182
fn get_driver_name(&self) -> &str {

rust/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub const WMIC_COMMAND: &str = r#"wmic datafile where name='{}' get Version /val
7373
pub const WMIC_COMMAND_OS: &str = r#"wmic os get osarchitecture"#;
7474
pub const REG_VERSION_ARG: &str = "version";
7575
pub const REG_CURRENT_VERSION_ARG: &str = "CurrentVersion";
76+
pub const REG_PV_ARG: &str = "pv";
7677
pub const PLIST_COMMAND: &str =
7778
r#"/usr/libexec/PlistBuddy -c "print :CFBundleShortVersionString" {}/Contents/Info.plist"#;
7879
pub const PKGUTIL_COMMAND: &str = "pkgutil --expand-full {} {}";
@@ -483,6 +484,15 @@ pub trait SeleniumManager {
483484
} else {
484485
self.set_browser_version(discovered_version);
485486
}
487+
if self.is_webview2() {
488+
let browser_path = format!(
489+
r#"{}\{}\msedge{}"#,
490+
self.get_browser_path(),
491+
&self.get_browser_version(),
492+
get_binary_extension(self.get_os())
493+
);
494+
self.set_browser_path(browser_path);
495+
}
486496
}
487497
None => {
488498
self.get_logger().debug(format!(
@@ -984,7 +994,7 @@ pub trait SeleniumManager {
984994
let mut commands = Vec::new();
985995

986996
if WINDOWS.is(self.get_os()) {
987-
if !escaped_browser_path.is_empty() {
997+
if !escaped_browser_path.is_empty() && !self.is_webview2() {
988998
let wmic_command =
989999
Command::new_single(format_one_arg(WMIC_COMMAND, &escaped_browser_path));
9901000
commands.push(wmic_command);
@@ -1159,7 +1169,7 @@ pub trait SeleniumManager {
11591169
}
11601170

11611171
fn set_browser_path(&mut self, browser_path: String) {
1162-
if !browser_path.is_empty() && !self.is_webview2() {
1172+
if !browser_path.is_empty() {
11631173
self.get_config_mut().browser_path = browser_path;
11641174
}
11651175
}

rust/tests/browser_tests.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
use crate::common::{assert_driver, assert_output};
1919
use assert_cmd::Command;
2020
use rstest::rstest;
21-
use selenium_manager::logger::JsonOutput;
2221
use std::env::consts::OS;
2322

2423
mod common;
@@ -157,10 +156,4 @@ fn webview2_test() {
157156
.code(0);
158157

159158
assert_driver(&mut cmd);
160-
161-
let stdout = &cmd.unwrap().stdout;
162-
let output = std::str::from_utf8(stdout).unwrap();
163-
let json: JsonOutput = serde_json::from_str(output).unwrap();
164-
let browser_path = json.result.browser_path;
165-
assert!(browser_path.is_empty());
166159
}

0 commit comments

Comments
 (0)