Skip to content

Commit

Permalink
Add devtools support on Android/iOS (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngo Iok Ui (Wu Yu Wei) committed Apr 11, 2022
1 parent 427cf92 commit 1c5d77a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/mobile-devtools.md
@@ -0,0 +1,5 @@
---
"wry": patch
---

Add devtools support on Android/iOS.
14 changes: 14 additions & 0 deletions src/webview/android/mod.rs
Expand Up @@ -60,6 +60,7 @@ impl InnerWebView {
custom_protocols,
initialization_scripts,
ipc_handler,
devtools,
..
} = self.attributes;

Expand All @@ -69,6 +70,19 @@ impl InnerWebView {
*ipc = i;
}

if devtools {
#[cfg(any(debug_assertions, feature = "devtools"))]
{
let class = env.find_class("android/webkit/WebView")?;
env.call_static_method(
class,
"setWebContentsDebuggingEnabled",
"(Z)V",
&[devtools.into()],
)?;
}
}

if let Some(u) = url {
let mut url_string = String::from(u.as_str());
let schemes = custom_protocols
Expand Down
18 changes: 12 additions & 6 deletions src/webview/mod.rs
Expand Up @@ -143,11 +143,14 @@ pub struct WebViewAttributes {
/// Enable web inspector which is usually called dev tool.
///
/// Note this only enables dev tool to the webview. To open it, you can call
/// [`WebView::devtool`], or right click the page and open it from the context menu.
/// [`WebView::open_devtools`], or right click the page and open it from the context menu.
///
/// # Warning
/// This will call private functions on **macOS**. It's still enabled if set in **debug** build on mac,
/// but requires `devtool` feature flag to actually enable it in **release** build.
/// ## Platform-specific
///
/// - macOS: This will call private functions on **macOS**. It's still enabled if set in **debug** build on mac,
/// but requires `devtools` feature flag to actually enable it in **release** build.
/// - Android: Open `chrome://inspect/#devices` in Chrome to get the devtools window. Wry's `WebView` devtools API isn't supported on Android.
/// - iOS: Open Safari > Develop > [Your Device Name] > [Your WebView] to get the devtools window.
pub devtools: bool,
}

Expand Down Expand Up @@ -321,9 +324,12 @@ impl<'a> WebViewBuilder<'a> {
/// Note this only enables dev tool to the webview. To open it, you can call
/// [`WebView::open_devtools`], or right click the page and open it from the context menu.
///
/// # Warning
/// This will call private functions on **macOS**. It's still enabled if set in **debug** build on mac,
/// ## Platform-specific
///
/// - macOS: This will call private functions on **macOS**. It's still enabled if set in **debug** build on mac,
/// but requires `devtools` feature flag to actually enable it in **release** build.
/// - Android: Open `chrome://inspect/#devices` in Chrome to get the devtools window. Wry's `WebView` devtools API isn't supported on Android.
/// - iOS: Open Safari > Develop > [Your Device Name] > [Your WebView] to get the devtools window.
pub fn with_devtools(mut self, devtools: bool) -> Self {
self.webview.devtools = devtools;
self
Expand Down

0 comments on commit 1c5d77a

Please sign in to comment.