@@ -411,19 +411,19 @@ export class WebViewModel implements ViewModel {
411411 const searchTemplate = globalStore . get ( defaultSearchAtom ) ;
412412 const nextUrl = this . ensureUrlScheme ( newUrl , searchTemplate ) ;
413413 console . log ( "webview loadUrlPromise" , reason , nextUrl , "cur=" , this . webviewRef . current ?. getURL ( ) ) ;
414-
414+
415415 if ( ! this . webviewRef . current ) {
416416 return Promise . reject ( new Error ( "WebView ref not available" ) ) ;
417417 }
418-
418+
419419 if ( newUrl != nextUrl ) {
420420 globalStore . set ( this . url , nextUrl ) ;
421421 }
422-
422+
423423 if ( this . webviewRef . current . getURL ( ) != nextUrl ) {
424424 return this . webviewRef . current . loadURL ( nextUrl ) ;
425425 }
426-
426+
427427 return Promise . resolve ( ) ;
428428 }
429429
@@ -495,6 +495,25 @@ export class WebViewModel implements ViewModel {
495495 }
496496 }
497497
498+ clearHistory ( ) {
499+ try {
500+ this . webviewRef . current ?. clearHistory ( ) ;
501+ } catch ( e ) {
502+ console . error ( "Failed to clear history" , e ) ;
503+ }
504+ }
505+
506+ async clearCookiesAndStorage ( ) {
507+ try {
508+ const webContentsId = this . webviewRef . current ?. getWebContentsId ( ) ;
509+ if ( webContentsId ) {
510+ await getApi ( ) . clearWebviewStorage ( webContentsId ) ;
511+ }
512+ } catch ( e ) {
513+ console . error ( "Failed to clear cookies and storage" , e ) ;
514+ }
515+ }
516+
498517 keyDownHandler ( e : WaveKeyboardEvent ) : boolean {
499518 if ( checkKeyPressed ( e , "Cmd:l" ) ) {
500519 this . urlInputRef ?. current ?. focus ( ) ;
@@ -619,6 +638,17 @@ export class WebViewModel implements ViewModel {
619638 }
620639 } ,
621640 } ,
641+ {
642+ type : "separator" ,
643+ } ,
644+ {
645+ label : "Clear History" ,
646+ click : ( ) => this . clearHistory ( ) ,
647+ } ,
648+ {
649+ label : "Clear Cookies and Storage (All Web Widgets)" ,
650+ click : ( ) => fireAndForget ( ( ) => this . clearCookiesAndStorage ( ) ) ,
651+ } ,
622652 ] ;
623653 }
624654}
0 commit comments