diff --git a/src/frontend-shared/App.tsx b/src/frontend-shared/App.tsx index b569421..373580c 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