electron/typings/internal-ambient.d.ts

341 lines
13 KiB
TypeScript
Raw Normal View History

declare const BUILDFLAG: (flag: boolean) => boolean;
declare namespace NodeJS {
interface ModuleInternal extends NodeJS.Module {
new(id: string, parent?: NodeJS.Module | null): NodeJS.Module;
_load(request: string, parent?: NodeJS.Module | null, isMain?: boolean): any;
_resolveFilename(request: string, parent?: NodeJS.Module | null, isMain?: boolean, options?: { paths: string[] }): string;
_preloadModules(requests: string[]): void;
_nodeModulePaths(from: string): string[];
_extensions: Record<string, (module: NodeJS.Module, filename: string) => any>;
_cache: Record<string, NodeJS.Module>;
wrapper: [string, string];
}
interface FeaturesBinding {
isBuiltinSpellCheckerEnabled(): boolean;
isPDFViewerEnabled(): boolean;
isFakeLocationProviderEnabled(): boolean;
isPrintingEnabled(): boolean;
isExtensionsEnabled(): boolean;
isComponentBuild(): boolean;
}
interface IpcRendererBinding {
send(internal: boolean, channel: string, args: any[]): void;
sendSync(internal: boolean, channel: string, args: any[]): any;
sendToHost(channel: string, args: any[]): void;
invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
postMessage(channel: string, message: any, transferables: MessagePort[]): void;
}
interface V8UtilBinding {
getHiddenValue<T>(obj: any, key: string): T;
setHiddenValue<T>(obj: any, key: string, value: T): void;
requestGarbageCollectionForTesting(): void;
runUntilIdle(): void;
triggerFatalErrorForTesting(): void;
}
type CrashReporterBinding = Omit<Electron.CrashReporter, 'start'> & {
start(submitUrl: string,
uploadToServer: boolean,
ignoreSystemCrashHandler: boolean,
rateLimit: boolean,
compress: boolean,
globalExtra: Record<string, string>,
extra: Record<string, string>,
isNodeProcess: boolean): void;
}
interface EnvironmentBinding {
getVar(name: string): string | null;
hasVar(name: string): boolean;
setVar(name: string, value: string): boolean;
}
type AsarFileInfo = {
size: number;
unpacked: boolean;
offset: number;
integrity?: {
algorithm: 'SHA256';
hash: string;
}
};
type AsarFileStat = {
size: number;
offset: number;
type: number;
}
interface AsarArchive {
getFileInfo(path: string): AsarFileInfo | false;
stat(path: string): AsarFileStat | false;
readdir(path: string): string[] | false;
realpath(path: string): string | false;
copyFileOut(path: string): string | false;
getFdAndValidateIntegrityLater(): number | -1;
}
interface AsarBinding {
Archive: { new(path: string): AsarArchive };
splitPath(path: string): {
isAsar: false;
} | {
isAsar: true;
asarPath: string;
filePath: string;
};
}
interface NetBinding {
isOnline(): boolean;
isValidHeaderName: (headerName: string) => boolean;
isValidHeaderValue: (headerValue: string) => boolean;
fileURLToFilePath: (url: string) => string;
Net: any;
net: any;
createURLLoader(options: CreateURLLoaderOptions): URLLoader;
feat: add net module to utility process (#40017) * chore: initial prototype of net api from utility process * chore: update url loader to work on both browser and utility processes * chore: add net files to utility process bundle * chore: re-add app ready check but only on main process * chore: replace browser thread dcheck's with sequence checker * refactor: move url loader from browser to common * refactor: move net-client-request.ts from browser to common * docs: add utility process to net api docs * refactor: move net module app ready check to browser only * refactor: switch import from main to common after moving to common * test: add basic net module test for utility process * refactor: switch browser pid with utility pid * refactor: move electron_api_net from browser to common * chore: add fetch to utility net module * chore: add isOnline and online to utility net module * refactor: move net spec helpers into helper file * refactor: break apart net module tests Adds two additional net module test files: `api-net-session-spec.ts` for tests that depend on a session being available (aka depend on running on the main process) and `api-net-custom-protocols-spec.ts` for custom protocol tests. This enables running `api-net-spec.ts` in the utility process. * test: add utility process mocha runner to run net module tests * docs: add utility process to net module classes * refactor: update imports in lib/utility to use electron/utility * chore: check browser context before using in main process Since the browser context supplied to the SimpleURLLoaderWrapper can now be null for use in the UtilityProcess, adding a null check for the main process before use to get a more sensible error if something goes wrong. Co-authored-by: Cheng Zhao <github@zcbenz.com> * chore: remove test debugging * chore: remove unnecessary header include * docs: add utility process net module limitations * test: run net module tests in utility process individually * refactor: clean up prior utility process net tests * chore: add resolveHost to utility process net module * chore: replace resolve host dcheck with sequence checker * test: add net module tests for net.resolveHost * docs: remove utility process limitation for resolveHost --------- Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Cheng Zhao <github@zcbenz.com>
2024-01-04 21:20:37 +00:00
resolveHost(host: string, options?: Electron.ResolveHostOptions): Promise<Electron.ResolvedHost>;
}
interface NotificationBinding {
isSupported(): boolean;
Notification: typeof Electron.Notification;
}
interface PowerMonitorBinding extends Electron.PowerMonitor {
createPowerMonitor(): PowerMonitorBinding;
setListeningForShutdown(listening: boolean): void;
}
interface SessionBinding {
fromPartition: typeof Electron.Session.fromPartition,
fromPath: typeof Electron.Session.fromPath,
Session: typeof Electron.Session
}
interface WebViewManagerBinding {
addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
}
interface WebFrameMainBinding {
WebFrameMain: typeof Electron.WebFrameMain;
fromId(processId: number, routingId: number): Electron.WebFrameMain;
fromIdOrNull(processId: number, routingId: number): Electron.WebFrameMain | null;
}
interface InternalWebPreferences {
isWebView: boolean;
hiddenPage: boolean;
nodeIntegration: boolean;
webviewTag: boolean;
}
interface InternalWebFrame extends Electron.WebFrame {
getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
getWebFrameId(window: Window): number;
allowGuestViewElementDefinition(context: object, callback: Function): void;
}
interface WebFrameBinding {
mainFrame: InternalWebFrame;
}
2020-05-18 17:22:48 +00:00
type DataPipe = {
write: (buf: Uint8Array) => Promise<void>;
done: () => void;
};
type BodyFunc = (pipe: DataPipe) => void;
type CreateURLLoaderOptions = {
method: string;
url: string;
extraHeaders?: Record<string, string>;
useSessionCookies?: boolean;
2023-02-20 20:57:38 +00:00
credentials?: 'include' | 'omit' | 'same-origin';
2020-05-18 17:22:48 +00:00
body: Uint8Array | BodyFunc;
session?: Electron.Session;
partition?: string;
referrer?: string;
2023-02-20 20:57:38 +00:00
referrerPolicy?: string;
cache?: string;
origin?: string;
hasUserActivation?: boolean;
mode?: string;
destination?: string;
2023-03-27 17:00:55 +00:00
bypassCustomProtocolHandlers?: boolean;
};
2020-05-18 17:22:48 +00:00
type ResponseHead = {
statusCode: number;
statusMessage: string;
httpVersion: { major: number, minor: number };
rawHeaders: { key: string, value: string }[];
headers: Record<string, string[]>;
2020-05-18 17:22:48 +00:00
};
type RedirectInfo = {
statusCode: number;
newMethod: string;
newUrl: string;
newSiteForCookies: string;
newReferrer: string;
insecureSchemeWasUpgraded: boolean;
isSignedExchangeFallbackRedirect: boolean;
}
interface URLLoader extends EventEmitter {
cancel(): void;
on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
2020-05-18 17:22:48 +00:00
on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
on(eventName: 'complete', listener: (event: any) => void): this;
on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
}
interface Process {
internalBinding?(name: string): any;
_linkedBinding(name: string): any;
_linkedBinding(name: 'electron_common_asar'): AsarBinding;
_linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
_linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
_linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
_linkedBinding(name: 'electron_common_features'): FeaturesBinding;
_linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
feat: add net module to utility process (#40017) * chore: initial prototype of net api from utility process * chore: update url loader to work on both browser and utility processes * chore: add net files to utility process bundle * chore: re-add app ready check but only on main process * chore: replace browser thread dcheck's with sequence checker * refactor: move url loader from browser to common * refactor: move net-client-request.ts from browser to common * docs: add utility process to net api docs * refactor: move net module app ready check to browser only * refactor: switch import from main to common after moving to common * test: add basic net module test for utility process * refactor: switch browser pid with utility pid * refactor: move electron_api_net from browser to common * chore: add fetch to utility net module * chore: add isOnline and online to utility net module * refactor: move net spec helpers into helper file * refactor: break apart net module tests Adds two additional net module test files: `api-net-session-spec.ts` for tests that depend on a session being available (aka depend on running on the main process) and `api-net-custom-protocols-spec.ts` for custom protocol tests. This enables running `api-net-spec.ts` in the utility process. * test: add utility process mocha runner to run net module tests * docs: add utility process to net module classes * refactor: update imports in lib/utility to use electron/utility * chore: check browser context before using in main process Since the browser context supplied to the SimpleURLLoaderWrapper can now be null for use in the UtilityProcess, adding a null check for the main process before use to get a more sensible error if something goes wrong. Co-authored-by: Cheng Zhao <github@zcbenz.com> * chore: remove test debugging * chore: remove unnecessary header include * docs: add utility process net module limitations * test: run net module tests in utility process individually * refactor: clean up prior utility process net tests * chore: add resolveHost to utility process net module * chore: replace resolve host dcheck with sequence checker * test: add net module tests for net.resolveHost * docs: remove utility process limitation for resolveHost --------- Co-authored-by: deepak1556 <hop2deep@gmail.com> Co-authored-by: Cheng Zhao <github@zcbenz.com>
2024-01-04 21:20:37 +00:00
_linkedBinding(name: 'electron_common_net'): NetBinding;
_linkedBinding(name: 'electron_common_shell'): Electron.Shell;
_linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
_linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
_linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
_linkedBinding(name: 'electron_browser_crash_reporter'): CrashReporterBinding;
_linkedBinding(name: 'electron_browser_desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer; };
_linkedBinding(name: 'electron_browser_event_emitter'): { setEventEmitterPrototype(prototype: Object): void; };
_linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
_linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
_linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
_linkedBinding(name: 'electron_browser_message_port'): { createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain }; };
_linkedBinding(name: 'electron_browser_native_theme'): { nativeTheme: Electron.NativeTheme };
_linkedBinding(name: 'electron_browser_notification'): NotificationBinding;
_linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
_linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
_linkedBinding(name: 'electron_browser_push_notifications'): { pushNotifications: Electron.PushNotifications };
_linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
_linkedBinding(name: 'electron_browser_session'): SessionBinding;
_linkedBinding(name: 'electron_browser_screen'): { createScreen(): Electron.Screen };
_linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
_linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
_linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
_linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
_linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
_linkedBinding(name: 'electron_browser_web_frame_main'): WebFrameMainBinding;
_linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
_linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
_linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
log: NodeJS.WriteStream['write'];
activateUvLoop(): void;
// Additional events
once(event: 'document-start', listener: () => any): this;
once(event: 'document-end', listener: () => any): this;
// Additional properties
_firstFileName?: string;
feat: UtilityProcess API (#34980) * chore: initial scaffolding * chore: implement interface and docs * chore: address code style review * fix: cleanup of utility process on shutdown * chore: simplify NodeBindings::CreateEnvironment * chore: rename disableLibraryValidation => allowLoadingUnsignedLibraries * chore: implement process.parentPort * chore(posix): implement stdio pipe interface * chore(win): implement stdio interface * chore: reenable SetNodeOptions for utility process * chore: add specs * chore: fix lint * fix: update kill API * fix: update process.parentPort API * fix: exit event * docs: update exit event * fix: tests on linux * chore: expand on some comments * fix: shutdown of pipe reader Avoid logging since it is always the case that reader end of pipe will terminate after the child process. * fix: remove exit code check for crash spec * fix: rm PR_SET_NO_NEW_PRIVS for unsandbox utility process * chore: fix incorrect rebase * fix: address review feedback * chore: rename utility_process -> utility * chore: update docs * chore: cleanup c++ implemantation * fix: leak in NodeServiceHost impl * chore: minor cleanup * chore: cleanup JS implementation * chore: flip default stdio to inherit * fix: some api improvements * Support cwd option * Remove path restriction for modulePath * Rewire impl for env support * fix: add tests for cwd and env option * chore: alt impl for reading stdio handles * chore: support message queuing * chore: fix lint * chore: new UtilityProcess => utilityProcess.fork * fix: support for uncaught exception exits * chore: remove process.execArgv as default * fix: windows build * fix: style changes * fix: docs and style changes * chore: update patches * spec: disable flaky test on win32 arm CI Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com>
2022-10-20 05:49:49 +00:00
_serviceStartupScript: string;
_getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;
helperExecPath: string;
mainModule?: NodeJS.Module | undefined;
feat: I guess it's esm (#37535) * fix: allow ESM loads from within ASAR files * fix: ensure that ESM entry points finish loading before app ready * fix: allow loading ESM entrypoints via default_app * fix: allow ESM loading for renderer preloads * docs: document current known limitations of esm * chore: add patches to support blending esm handlers * refactor: use SetDefersLoading instead of JoinAppCode in renderers Blink has it's own event loop so pumping the uv loop in the renderer is not enough, luckily in blink we can suspend the loading of the frame while we do additional work. * chore: add patch to expose SetDefersLoading * fix: use fileURLToPath instead of pathname * chore: update per PR feedback * fix: fs.exists/existsSync should never throw * fix: convert path to file url before importing * fix: oops * fix: oops * Update docs/tutorial/esm-limitations.md Co-authored-by: Jeremy Rose <jeremya@chromium.org> * windows... * windows... * chore: update patches * spec: fix tests and document empty body edge case * Apply suggestions from code review Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com> Co-authored-by: Jeremy Rose <jeremya@chromium.org> * spec: add tests for esm * spec: windows * chore: update per PR feedback * chore: update patches * Update shell/common/node_bindings.h Co-authored-by: Jeremy Rose <jeremya@chromium.org> * chore: update patches * rebase * use cjs loader by default for preload scripts * chore: fix lint * chore: update patches * chore: update patches * chore: fix patches * build: debug depshash * ? * Revert "build: debug depshash" This reverts commit 0de82523fb93f475226356b37418ce4b69acdcdf. * chore: allow electron as builtin protocol in esm loader * Revert "Revert "build: debug depshash"" This reverts commit ff86b1243ca6d05c9b3b38e0a6d717fb380343a4. * chore: fix esm doc * chore: update node patches --------- Co-authored-by: Jeremy Rose <jeremya@chromium.org> Co-authored-by: electron-patch-conflict-fixer[bot] <83340002+electron-patch-conflict-fixer[bot]@users.noreply.github.com> Co-authored-by: PatchUp <73610968+patchup[bot]@users.noreply.github.com> Co-authored-by: Daniel Scalzi <d_scalzi@yahoo.com>
2023-08-31 00:38:07 +00:00
appCodeLoaded?: () => void;
}
}
declare module NodeJS {
interface Global {
require: NodeRequire;
module: NodeModule;
__filename: string;
__dirname: string;
}
}
interface ContextMenuItem {
id: number;
label: string;
type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
checked: boolean;
enabled: boolean;
subItems: ContextMenuItem[];
}
declare interface Window {
ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
InspectorFrontendHost?: {
showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
};
DevToolsAPI?: {
contextMenuItemSelected: (id: number) => void;
contextMenuCleared: () => void
};
UI?: {
createFileSelectorElement: (callback: () => void) => HTMLSpanElement
};
Persistence?: {
FileSystemWorkspaceBinding: {
completeURL: (project: string, path: string) => string;
}
};
WebView: typeof ElectronInternal.WebViewElement;
trustedTypes: TrustedTypePolicyFactory;
}
// https://github.com/electron/electron/blob/main/docs/tutorial/message-ports.md#extension-close-event
interface MessagePort {
onclose: () => void;
}
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
type TrustedHTML = string;
type TrustedScript = string;
type TrustedScriptURL = string;
type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
interface TrustedTypePolicy {
createHTML(input: string, ...arguments: any[]): TrustedHTML;
createScript(input: string, ...arguments: any[]): TrustedScript;
createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
}
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
interface TrustedTypePolicyOptions {
createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
createScript?: (input: string, ...arguments: any[]) => TrustedScript;
createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
}
// https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
interface TrustedTypePolicyFactory {
createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
isHTML(value: any): boolean;
isScript(value: any): boolean;
isScriptURL(value: any): boolean;
readonly emptyHTML: TrustedHTML;
readonly emptyScript: TrustedScript;
getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
readonly defaultPolicy: TrustedTypePolicy | null;
}