Files
electron/lib/renderer/inspector.ts
Sam Attard b84ffddc3a chore: apply oxfmt formatting to JS and TS sources
Runs `yarn format` across lib/, spec/, script/, build/, default_app/,
and npm/ to bring the codebase in line with the .oxfmtrc.json settings
added in the previous commit. This is a pure formatting pass: import
statements are sorted into the groups defined by the config, method
chains longer than printWidth are broken, single-quoted strings
containing apostrophes are switched to double quotes, and a handful of
single-statement `if` bodies are re-wrapped and get braces added by
`oxlint --fix` to satisfy the `curly: multi-line` rule.

No behavior changes.
2026-04-06 16:17:00 +00:00

50 lines
1.8 KiB
TypeScript

import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';
import { internalContextBridge } from '@electron/internal/renderer/api/context-bridge';
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
import * as ipcRendererUtils from '@electron/internal/renderer/ipc-renderer-internal-utils';
import { webFrame } from 'electron/renderer';
const { contextIsolationEnabled } = internalContextBridge;
/* Corrects for some Inspector adaptations needed in Electron.
* 1) Use menu API to show context menu.
*/
window.onload = function () {
if (contextIsolationEnabled) {
internalContextBridge.tryOverrideGlobalValueFromIsolatedWorld(
['InspectorFrontendHost', 'showContextMenuAtPoint'],
createMenu
);
} else {
window.InspectorFrontendHost!.showContextMenuAtPoint = createMenu;
}
};
// The DOM implementation expects (message?: string) => boolean
window.confirm = function (message?: string, title?: string) {
return ipcRendererUtils.invokeSync(IPC_MESSAGES.INSPECTOR_CONFIRM, message, title) as boolean;
};
const useEditMenuItems = function (x: number, y: number, items: ContextMenuItem[]) {
return (
items.length === 0 &&
document.elementsFromPoint(x, y).some((element) => {
return (
element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA' || (element as HTMLElement).isContentEditable
);
})
);
};
const createMenu = function (x: number, y: number, items: ContextMenuItem[]) {
const isEditMenu = useEditMenuItems(x, y, items);
ipcRendererInternal.invoke<number>(IPC_MESSAGES.INSPECTOR_CONTEXT_MENU, items, isEditMenu).then((id) => {
if (typeof id === 'number') {
webFrame.executeJavaScript(`window.DevToolsAPI.contextMenuItemSelected(${JSON.stringify(id)})`);
}
webFrame.executeJavaScript('window.DevToolsAPI.contextMenuCleared()');
});
};