Skip to content

Commit 9014a3f

Browse files
feat: add webview.clear_all_browsing_data (#11066)
* feat: add `webview.clear_all_browsing_data` closes #6567 * fix build on iOS and android * fix command name references --------- Co-authored-by: Lucas Nogueira <[email protected]>
1 parent 0ddfc59 commit 9014a3f

File tree

12 files changed

+96
-1
lines changed

12 files changed

+96
-1
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"@tauri-apps/api": "patch:feat"
3+
---
4+
5+
Add `WebviewWindow.clearAllBrowsingData` and `Webview.clearAllBrowsingData` to clear the webview browsing data.
6+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"tauri": "patch:feat"
3+
"tauri-runtime": "patch:feat"
4+
"tauri-runtime-wry": "patch:feat"
5+
---
6+
7+
Add `WebviewWindow::clear_all_browsing_data` and `Webview::clear_all_browsing_data` to clear the webview browsing data.
8+

crates/tauri-runtime-wry/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,7 @@ pub enum WebviewMessage {
12391239
Reparent(WindowId, Sender<Result<()>>),
12401240
SetAutoResize(bool),
12411241
SetZoom(f64),
1242+
ClearAllBrowsingData,
12421243
// Getters
12431244
Url(Sender<Result<String>>),
12441245
Bounds(Sender<Result<tauri_runtime::Rect>>),
@@ -1516,6 +1517,17 @@ impl<T: UserEvent> WebviewDispatch<T> for WryWebviewDispatcher<T> {
15161517
),
15171518
)
15181519
}
1520+
1521+
fn clear_all_browsing_data(&self) -> Result<()> {
1522+
send_user_message(
1523+
&self.context,
1524+
Message::Webview(
1525+
*self.window_id.lock().unwrap(),
1526+
self.webview_id,
1527+
WebviewMessage::ClearAllBrowsingData,
1528+
),
1529+
)
1530+
}
15191531
}
15201532

15211533
/// The Tauri [`WindowDispatch`] for [`Wry`].
@@ -3157,6 +3169,11 @@ fn handle_user_message<T: UserEvent>(
31573169
log::error!("failed to set webview zoom: {e}");
31583170
}
31593171
}
3172+
WebviewMessage::ClearAllBrowsingData => {
3173+
if let Err(e) = webview.clear_all_browsing_data() {
3174+
log::error!("failed to clear webview browsing data: {e}");
3175+
}
3176+
}
31603177
// Getters
31613178
WebviewMessage::Url(tx) => {
31623179
tx.send(

crates/tauri-runtime/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ pub trait WebviewDispatch<T: UserEvent>: Debug + Clone + Send + Sync + Sized + '
512512

513513
/// Set the webview zoom level
514514
fn set_zoom(&self, scale_factor: f64) -> Result<()>;
515+
516+
/// Clear all browsing data for this webview.
517+
fn clear_all_browsing_data(&self) -> Result<()>;
515518
}
516519

517520
/// Window dispatcher. A thread-safe handle to the window APIs.

crates/tauri/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ const PLUGINS: &[(&str, &[(&str, bool)])] = &[
127127
("set_webview_zoom", false),
128128
("print", false),
129129
("reparent", false),
130+
("clear_all_browsing_data", false),
130131
// internal
131132
("internal_toggle_devtools", true),
132133
],

crates/tauri/permissions/webview/autogenerated/reference.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,32 @@ Default permissions for the plugin.
1616
</tr>
1717

1818

19+
<tr>
20+
<td>
21+
22+
`core:webview:allow-clear-all-browsing-data`
23+
24+
</td>
25+
<td>
26+
27+
Enables the clear_all_browsing_data command without any pre-configured scope.
28+
29+
</td>
30+
</tr>
31+
32+
<tr>
33+
<td>
34+
35+
`core:webview:deny-clear-all-browsing-data`
36+
37+
</td>
38+
<td>
39+
40+
Denies the clear_all_browsing_data command without any pre-configured scope.
41+
42+
</td>
43+
</tr>
44+
1945
<tr>
2046
<td>
2147

crates/tauri/scripts/bundle.global.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/tauri/src/test/mock_runtime.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,10 @@ impl<T: UserEvent> WebviewDispatch<T> for MockWebviewDispatcher {
572572
fn set_auto_resize(&self, auto_resize: bool) -> Result<()> {
573573
Ok(())
574574
}
575+
576+
fn clear_all_browsing_data(&self) -> Result<()> {
577+
Ok(())
578+
}
575579
}
576580

577581
impl<T: UserEvent> WindowDispatch<T> for MockWindowDispatcher {

crates/tauri/src/webview/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,15 @@ tauri::Builder::default()
14721472
.set_zoom(scale_factor)
14731473
.map_err(Into::into)
14741474
}
1475+
1476+
/// Clear all browsing data for this webview.
1477+
pub fn clear_all_browsing_data(&self) -> crate::Result<()> {
1478+
self
1479+
.webview
1480+
.dispatcher
1481+
.clear_all_browsing_data()
1482+
.map_err(Into::into)
1483+
}
14751484
}
14761485

14771486
impl<R: Runtime> Listener<R> for Webview<R> {

crates/tauri/src/webview/plugin.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ mod desktop_commands {
177177
setter!(set_webview_position, set_position, Position);
178178
setter!(set_webview_focus, set_focus);
179179
setter!(set_webview_zoom, set_zoom, f64);
180+
setter!(clear_all_browsing_data, clear_all_browsing_data);
180181

181182
#[command(root = "crate")]
182183
pub async fn reparent<R: Runtime>(
@@ -262,6 +263,7 @@ pub fn init<R: Runtime>() -> TauriPlugin<R> {
262263
desktop_commands::set_webview_zoom,
263264
desktop_commands::print,
264265
desktop_commands::reparent,
266+
desktop_commands::clear_all_browsing_data,
265267
#[cfg(any(debug_assertions, feature = "devtools"))]
266268
desktop_commands::internal_toggle_devtools,
267269
]);

0 commit comments

Comments
 (0)