-
-
Notifications
You must be signed in to change notification settings - Fork 807
add clear history/storage for web widgets #2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -411,19 +411,19 @@ export class WebViewModel implements ViewModel { | |
| const searchTemplate = globalStore.get(defaultSearchAtom); | ||
| const nextUrl = this.ensureUrlScheme(newUrl, searchTemplate); | ||
| console.log("webview loadUrlPromise", reason, nextUrl, "cur=", this.webviewRef.current?.getURL()); | ||
|
|
||
| if (!this.webviewRef.current) { | ||
| return Promise.reject(new Error("WebView ref not available")); | ||
| } | ||
|
|
||
| if (newUrl != nextUrl) { | ||
| globalStore.set(this.url, nextUrl); | ||
| } | ||
|
|
||
| if (this.webviewRef.current.getURL() != nextUrl) { | ||
| return this.webviewRef.current.loadURL(nextUrl); | ||
| } | ||
|
|
||
| return Promise.resolve(); | ||
| } | ||
|
|
||
|
|
@@ -495,6 +495,25 @@ export class WebViewModel implements ViewModel { | |
| } | ||
| } | ||
|
|
||
| clearHistory() { | ||
| try { | ||
| this.webviewRef.current?.clearHistory(); | ||
| } catch (e) { | ||
| console.error("Failed to clear history", e); | ||
| } | ||
| } | ||
|
|
||
| async clearCookiesAndStorage() { | ||
| try { | ||
| const webContentsId = this.webviewRef.current?.getWebContentsId(); | ||
| if (webContentsId) { | ||
| await getApi().clearWebviewStorage(webContentsId); | ||
| } | ||
| } catch (e) { | ||
| console.error("Failed to clear cookies and storage", e); | ||
| } | ||
| } | ||
|
Comment on lines
+506
to
+515
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add user feedback for clearCookiesAndStorage operation. The Consider one of these solutions: Option 1: Update the menu label to reflect the actual behavior: - label: "Clear Cookies and Storage (All Web Widgets)",
+ label: "Clear Cookies and Storage (This Widget)",Option 2: If clearing all web widgets is intended, you'll need to iterate over all webview instances and clear each one's storage. In that case, you should also add user feedback: async clearCookiesAndStorage() {
try {
const webContentsId = this.webviewRef.current?.getWebContentsId();
if (webContentsId) {
await getApi().clearWebviewStorage(webContentsId);
// Add success notification
console.log("Successfully cleared cookies and storage");
}
} catch (e) {
console.error("Failed to clear cookies and storage", e);
// Consider showing user-facing error notification
}
}🤖 Prompt for AI Agents |
||
|
|
||
| keyDownHandler(e: WaveKeyboardEvent): boolean { | ||
| if (checkKeyPressed(e, "Cmd:l")) { | ||
| this.urlInputRef?.current?.focus(); | ||
|
|
@@ -619,6 +638,17 @@ export class WebViewModel implements ViewModel { | |
| } | ||
| }, | ||
| }, | ||
| { | ||
| type: "separator", | ||
| }, | ||
| { | ||
| label: "Clear History", | ||
| click: () => this.clearHistory(), | ||
| }, | ||
| { | ||
| label: "Clear Cookies and Storage (All Web Widgets)", | ||
| click: () => fireAndForget(() => this.clearCookiesAndStorage()), | ||
| }, | ||
|
Comment on lines
+641
to
+651
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verify clearCookiesAndStorage scope matches label. The menu label states "Clear Cookies and Storage (All Web Widgets)" but the implementation only clears storage for the current webview instance (via Please clarify the intended behavior:
Related to the comment on lines 506-515. |
||
| ]; | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate webContentsId parameter.
The handler doesn't validate the
webContentsIdparameter before using it. If a malformed or negative value is passed,electron.webContents.fromId()will returnundefined, but the code should explicitly validate the input.Consider adding parameter validation:
electron.ipcMain.handle("clear-webview-storage", async (event, webContentsId: number) => { try { + if (!webContentsId || typeof webContentsId !== 'number' || webContentsId <= 0) { + throw new Error("Invalid webContentsId"); + } const wc = electron.webContents.fromId(webContentsId); if (wc && wc.session) { await wc.session.clearStorageData(); console.log("Cleared cookies and storage for webContentsId:", webContentsId); + } else { + console.warn("WebContents not found for webContentsId:", webContentsId); } } catch (e) { console.error("Failed to clear cookies and storage:", e); throw e; } });📝 Committable suggestion
🤖 Prompt for AI Agents