From dc9432b9c5c7f3835bf92a70a9394b184c4aa39b Mon Sep 17 00:00:00 2001 From: jonasnobile Date: Fri, 15 May 2026 15:59:27 +0200 Subject: [PATCH] fix: suppress native context menu in production builds MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The webview's default right-click menu exposes "Inspect Element" and other dev tooling to end users — not the experience we want from a shipped database client. Register a global contextmenu listener that prevents the default, gated on import.meta.env.PROD so dev builds still get DOM inspection. Component-level context menus already call preventDefault and render their own menu via the ContextMenu component, so they're unaffected. Co-Authored-By: Claude Opus 4.7 --- src/frontend-shared/App.tsx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/frontend-shared/App.tsx b/src/frontend-shared/App.tsx index b5694211..373580cc 100644 --- a/src/frontend-shared/App.tsx +++ b/src/frontend-shared/App.tsx @@ -3,6 +3,14 @@ import AppShell from './components/layout/AppShell' import { connectionsStore, initConnectionsListener } from './stores/connections' import { editorStore } from './stores/editor' +// Suppress the webview's native context menu (with "Inspect Element" etc.) in +// production builds. In dev we keep it so we can inspect the DOM. Component- +// level context menus call e.preventDefault() themselves and render their own +// menu via the ContextMenu component, so they keep working either way. +function preventNativeContextMenu(e: MouseEvent) { + e.preventDefault() +} + export default function App() { let cleanup: (() => void) | undefined @@ -14,12 +22,19 @@ export default function App() { connectionsStore.setOnConnectionLost((connectionId) => { editorStore.rejectPendingQueriesForConnection(connectionId) }) + + if (import.meta.env.PROD) { + document.addEventListener('contextmenu', preventNativeContextMenu) + } }) onCleanup(() => { cleanup?.() connectionsStore.setOnTransactionLost(null) connectionsStore.setOnConnectionLost(null) + if (import.meta.env.PROD) { + document.removeEventListener('contextmenu', preventNativeContextMenu) + } }) return