Skip to content

Commit

Permalink
[EdgeChromium] delete user data on exit
Browse files Browse the repository at this point in the history
  • Loading branch information
r0x0r committed Dec 27, 2024
1 parent 5f935c2 commit 1ef7feb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
19 changes: 18 additions & 1 deletion webview/platforms/edgechromium.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import logging
import os
import shutil
import webbrowser
import winreg
from threading import Semaphore
Expand All @@ -16,8 +17,9 @@
clr.AddReference('System.Threading')

import System.Windows.Forms as WinForms
from System import Action, Func, String, Type, Uri, Object
from System import Action, Convert, Func, String, Type, Uri, Object
from System.Collections.Generic import List
from System.Diagnostics import Process
from System.Drawing import Color
from System.Globalization import CultureInfo
from System.Threading.Tasks import Task, TaskScheduler
Expand All @@ -41,6 +43,7 @@ def __init__(self, form, window, cache_dir):
self.webview = WebView2()
props = CoreWebView2CreationProperties()
props.UserDataFolder = cache_dir
self.user_data_folder = props.UserDataFolder
props.set_IsInPrivateModeEnabled(_state['private_mode'])
props.AdditionalBrowserArguments = '--disable-features=ElasticOverscroll'

Expand Down Expand Up @@ -78,6 +81,20 @@ def __init__(self, form, window, cache_dir):
else:
self.webview.EnsureCoreWebView2Async(None)

def clear_user_data(self):
if not _state['private_mode']:
return

process_id = Convert.ToInt32(self.webview.CoreWebView2.BrowserProcessId)
process = Process.GetProcessById(process_id)
self.webview.Dispose()
process.WaitForExit(3000)

try:
shutil.rmtree(self.user_data_folder)
except Exception as e:
logger.exception(e)

def setup_webview2_environment(self):
def _callback(task):
self.webview.EnsureCoreWebView2Async(task.Result)
Expand Down
3 changes: 3 additions & 0 deletions webview/platforms/winforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,9 @@ def on_close(self, *_):
def _shutdown():
if is_cef:
CEF.shutdown()
elif is_chromium:
self.browser.clear_user_data()

WinForms.Application.Exit()

if not is_cef:
Expand Down

0 comments on commit 1ef7feb

Please sign in to comment.