Skip to content

Conversation

sawka
Copy link
Member

@sawka sawka commented Sep 29, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented Sep 29, 2025

Walkthrough

  • emain/emain.ts: Adds an IPC handler clear-webview-storage that takes a webContentsId, looks up the corresponding webContents, and if a session exists calls clearStorageData(); logs success and propagates errors.
  • emain/preload.ts: Exposes clearWebviewStorage(webContentsId: number) on the renderer API via ipcRenderer.invoke("clear-webview-storage", webContentsId).
  • frontend/app/view/webview/webview.tsx: Adds clearHistory() and async clearCookiesAndStorage() methods to WebViewModel; wires these into the webview context/menu with a separator and two new menu items ("Clear History" and "Clear Cookies and Storage (All Web Widgets)").
  • frontend/types/custom.d.ts: Extends ElectronApi with clearWebviewStorage(webContentsId: number): Promise<void>.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The pull request has no description, so it offers no context or summary of the functionality being introduced. Please add a brief description summarizing the new clear history and storage functionality for web widgets and how it integrates with the existing API.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately describes the main feature added by the changeset, namely the ability to clear browsing history and storage for web widgets.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch sawka/webview-clearstorage

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d505536 and 12e030a.

📒 Files selected for processing (3)
  • emain/emain.ts (1 hunks)
  • emain/preload.ts (1 hunks)
  • frontend/types/custom.d.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • emain/preload.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Build for TestDriver.ai
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (1)
frontend/types/custom.d.ts (1)

109-109: LGTM!

The type declaration correctly matches the IPC handler signature, with appropriate parameter and return types.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (1)
frontend/app/view/webview/webview.tsx (1)

414-428: Verify unintended whitespace changes.

These lines appear to contain only whitespace changes in the diff. If these are unintentional formatting changes, consider removing them to keep the PR focused on the feature implementation.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bbe5d90 and d505536.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (4)
  • emain/emain.ts (1 hunks)
  • emain/preload.ts (1 hunks)
  • frontend/app/view/webview/webview.tsx (3 hunks)
  • frontend/types/custom.d.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
frontend/app/view/webview/webview.tsx (2)
frontend/app/store/global.ts (2)
  • globalStore (783-783)
  • getApi (772-772)
frontend/util/util.ts (1)
  • fireAndForget (411-411)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: Build for TestDriver.ai
🔇 Additional comments (4)
emain/emain.ts (1)

376-376: Consider scope of clearStorageData().

The clearStorageData() call without arguments clears all storage types (appcache, cookies, filesystem, indexdb, localstorage, shadercache, websql, serviceworkers, cachestorage). Verify this is the intended behavior, as it may clear more than expected.

If more granular control is needed, consider specifying which storage types to clear:

await wc.session.clearStorageData({
    storages: ['cookies', 'localstorage', 'indexdb', 'websql']
});

Confirm that clearing all storage types is the desired behavior for this feature.

frontend/types/custom.d.ts (1)

106-106: LGTM!

The type definition correctly declares the new API method with an appropriate signature matching the implementation.

emain/preload.ts (1)

56-56: LGTM!

The API method is correctly exposed via contextBridge and properly uses ipcRenderer.invoke for the async IPC call, consistent with other methods in this file.

frontend/app/view/webview/webview.tsx (1)

498-504: LGTM!

The clearHistory() method correctly invokes the webview's clearHistory API with appropriate error handling.

Comment on lines +372 to +383
electron.ipcMain.handle("clear-webview-storage", async (event, webContentsId: number) => {
try {
const wc = electron.webContents.fromId(webContentsId);
if (wc && wc.session) {
await wc.session.clearStorageData();
console.log("Cleared cookies and storage for webContentsId:", webContentsId);
}
} catch (e) {
console.error("Failed to clear cookies and storage:", e);
throw e;
}
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate webContentsId parameter.

The handler doesn't validate the webContentsId parameter before using it. If a malformed or negative value is passed, electron.webContents.fromId() will return undefined, 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

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
electron.ipcMain.handle("clear-webview-storage", async (event, webContentsId: number) => {
try {
const wc = electron.webContents.fromId(webContentsId);
if (wc && wc.session) {
await wc.session.clearStorageData();
console.log("Cleared cookies and storage for webContentsId:", webContentsId);
}
} catch (e) {
console.error("Failed to clear cookies and storage:", e);
throw e;
}
});
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;
}
});
🤖 Prompt for AI Agents
In emain/emain.ts around lines 372 to 383, the IPC handler uses webContentsId
without validating it; add explicit parameter validation (ensure webContentsId
is a number, finite, and a positive integer) before calling
electron.webContents.fromId(), and return or throw a descriptive error when
validation fails; after validating, continue to resolve the webContents and
check wc exists and has a session before clearing storage, and include brief
error messages when validation or lookup fails so malformed or negative values
are handled safely.

Comment on lines +506 to +515
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);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Add user feedback for clearCookiesAndStorage operation.

The clearCookiesAndStorage() method clears storage for the current webview instance but the menu label says "All Web Widgets". This creates a discrepancy between the UI text and the actual behavior. Additionally, users receive no feedback when the operation completes or fails.

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
frontend/app/view/webview/webview.tsx lines 506-515: the clearCookiesAndStorage
method behavior (clears current webview only) mismatches the menu label "All Web
Widgets" and provides no user feedback; either change the menu label to indicate
it only clears the current widget, or implement the intended "clear all"
behavior by enumerating all webview instances (or retrieving all webContentsIds
from the managing component/state) and calling getApi().clearWebviewStorage for
each id, awaiting all operations and collecting errors, then surface a
user-facing notification on success (e.g., "Cleared cookies and storage for N
widgets") and show an error notification if any failures occur while still
attempting to clear others; ensure console.error remains for debug logging.

Comment on lines +641 to +651
{
type: "separator",
},
{
label: "Clear History",
click: () => this.clearHistory(),
},
{
label: "Clear Cookies and Storage (All Web Widgets)",
click: () => fireAndForget(() => this.clearCookiesAndStorage()),
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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 this.webviewRef.current?.getWebContentsId()). This is inconsistent.

Please clarify the intended behavior:

  • If it should clear only the current widget, update the label to remove "(All Web Widgets)"
  • If it should clear all widgets, the implementation needs to be modified to iterate over all webview instances

Related to the comment on lines 506-515.

@sawka sawka merged commit a6c160f into main Oct 8, 2025
8 checks passed
@sawka sawka deleted the sawka/webview-clearstorage branch October 8, 2025 00:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant