internal-ambient.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. declare const BUILDFLAG: (flag: boolean) => boolean;
  2. declare namespace NodeJS {
  3. interface ModuleInternal extends NodeJS.Module {
  4. new(id: string, parent?: NodeJS.Module | null): NodeJS.Module;
  5. _load(request: string, parent?: NodeJS.Module | null, isMain?: boolean): any;
  6. _resolveFilename(request: string, parent?: NodeJS.Module | null, isMain?: boolean, options?: { paths: string[] }): string;
  7. _preloadModules(requests: string[]): void;
  8. _nodeModulePaths(from: string): string[];
  9. _extensions: Record<string, (module: NodeJS.Module, filename: string) => any>;
  10. _cache: Record<string, NodeJS.Module>;
  11. wrapper: [string, string];
  12. }
  13. interface FeaturesBinding {
  14. isBuiltinSpellCheckerEnabled(): boolean;
  15. isPDFViewerEnabled(): boolean;
  16. isFakeLocationProviderEnabled(): boolean;
  17. isPrintingEnabled(): boolean;
  18. isExtensionsEnabled(): boolean;
  19. isComponentBuild(): boolean;
  20. }
  21. interface IpcRendererBinding {
  22. send(internal: boolean, channel: string, args: any[]): void;
  23. sendSync(internal: boolean, channel: string, args: any[]): any;
  24. sendToHost(channel: string, args: any[]): void;
  25. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  26. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  27. }
  28. interface V8UtilBinding {
  29. getHiddenValue<T>(obj: any, key: string): T;
  30. setHiddenValue<T>(obj: any, key: string, value: T): void;
  31. requestGarbageCollectionForTesting(): void;
  32. runUntilIdle(): void;
  33. triggerFatalErrorForTesting(): void;
  34. }
  35. type CrashReporterBinding = Omit<Electron.CrashReporter, 'start'> & {
  36. start(submitUrl: string,
  37. uploadToServer: boolean,
  38. ignoreSystemCrashHandler: boolean,
  39. rateLimit: boolean,
  40. compress: boolean,
  41. globalExtra: Record<string, string>,
  42. extra: Record<string, string>,
  43. isNodeProcess: boolean): void;
  44. }
  45. interface EnvironmentBinding {
  46. getVar(name: string): string | null;
  47. hasVar(name: string): boolean;
  48. setVar(name: string, value: string): boolean;
  49. }
  50. type AsarFileInfo = {
  51. size: number;
  52. unpacked: boolean;
  53. offset: number;
  54. integrity?: {
  55. algorithm: 'SHA256';
  56. hash: string;
  57. }
  58. };
  59. type AsarFileStat = {
  60. size: number;
  61. offset: number;
  62. type: number;
  63. }
  64. interface AsarArchive {
  65. getFileInfo(path: string): AsarFileInfo | false;
  66. stat(path: string): AsarFileStat | false;
  67. readdir(path: string): string[] | false;
  68. realpath(path: string): string | false;
  69. copyFileOut(path: string): string | false;
  70. getFdAndValidateIntegrityLater(): number | -1;
  71. }
  72. interface AsarBinding {
  73. Archive: { new(path: string): AsarArchive };
  74. splitPath(path: string): {
  75. isAsar: false;
  76. } | {
  77. isAsar: true;
  78. asarPath: string;
  79. filePath: string;
  80. };
  81. }
  82. interface NetBinding {
  83. isOnline(): boolean;
  84. isValidHeaderName: (headerName: string) => boolean;
  85. isValidHeaderValue: (headerValue: string) => boolean;
  86. fileURLToFilePath: (url: string) => string;
  87. Net: any;
  88. net: any;
  89. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  90. resolveHost(host: string, options?: Electron.ResolveHostOptions): Promise<Electron.ResolvedHost>;
  91. }
  92. interface NotificationBinding {
  93. isSupported(): boolean;
  94. Notification: typeof Electron.Notification;
  95. }
  96. interface PowerMonitorBinding extends Electron.PowerMonitor {
  97. createPowerMonitor(): PowerMonitorBinding;
  98. setListeningForShutdown(listening: boolean): void;
  99. }
  100. interface SessionBinding {
  101. fromPartition: typeof Electron.Session.fromPartition,
  102. fromPath: typeof Electron.Session.fromPath,
  103. Session: typeof Electron.Session
  104. }
  105. interface WebViewManagerBinding {
  106. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  107. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  108. }
  109. interface WebFrameMainBinding {
  110. WebFrameMain: typeof Electron.WebFrameMain;
  111. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  112. fromIdOrNull(processId: number, routingId: number): Electron.WebFrameMain | null;
  113. }
  114. interface InternalWebPreferences {
  115. isWebView: boolean;
  116. hiddenPage: boolean;
  117. nodeIntegration: boolean;
  118. webviewTag: boolean;
  119. }
  120. interface InternalWebFrame extends Electron.WebFrame {
  121. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  122. getWebFrameId(window: Window): number;
  123. allowGuestViewElementDefinition(context: object, callback: Function): void;
  124. }
  125. interface WebFrameBinding {
  126. mainFrame: InternalWebFrame;
  127. }
  128. type DataPipe = {
  129. write: (buf: Uint8Array) => Promise<void>;
  130. done: () => void;
  131. };
  132. type BodyFunc = (pipe: DataPipe) => void;
  133. type CreateURLLoaderOptions = {
  134. method: string;
  135. url: string;
  136. extraHeaders?: Record<string, string>;
  137. useSessionCookies?: boolean;
  138. credentials?: 'include' | 'omit' | 'same-origin';
  139. body: Uint8Array | BodyFunc;
  140. session?: Electron.Session;
  141. partition?: string;
  142. referrer?: string;
  143. referrerPolicy?: string;
  144. cache?: string;
  145. origin?: string;
  146. hasUserActivation?: boolean;
  147. mode?: string;
  148. destination?: string;
  149. bypassCustomProtocolHandlers?: boolean;
  150. };
  151. type ResponseHead = {
  152. statusCode: number;
  153. statusMessage: string;
  154. httpVersion: { major: number, minor: number };
  155. rawHeaders: { key: string, value: string }[];
  156. headers: Record<string, string[]>;
  157. };
  158. type RedirectInfo = {
  159. statusCode: number;
  160. newMethod: string;
  161. newUrl: string;
  162. newSiteForCookies: string;
  163. newReferrer: string;
  164. insecureSchemeWasUpgraded: boolean;
  165. isSignedExchangeFallbackRedirect: boolean;
  166. }
  167. interface URLLoader extends EventEmitter {
  168. cancel(): void;
  169. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  170. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  171. on(eventName: 'complete', listener: (event: any) => void): this;
  172. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  173. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  174. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  175. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  176. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  177. }
  178. interface Process {
  179. internalBinding?(name: string): any;
  180. _linkedBinding(name: string): any;
  181. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  182. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  183. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  184. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  185. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  186. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  187. _linkedBinding(name: 'electron_common_net'): NetBinding;
  188. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  189. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  190. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  191. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  192. _linkedBinding(name: 'electron_browser_crash_reporter'): CrashReporterBinding;
  193. _linkedBinding(name: 'electron_browser_desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer; isDisplayMediaSystemPickerAvailable(): boolean; };
  194. _linkedBinding(name: 'electron_browser_event_emitter'): { setEventEmitterPrototype(prototype: Object): void; };
  195. _linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
  196. _linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
  197. _linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
  198. _linkedBinding(name: 'electron_browser_message_port'): { createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain }; };
  199. _linkedBinding(name: 'electron_browser_native_theme'): { nativeTheme: Electron.NativeTheme };
  200. _linkedBinding(name: 'electron_browser_notification'): NotificationBinding;
  201. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  202. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  203. _linkedBinding(name: 'electron_browser_push_notifications'): { pushNotifications: Electron.PushNotifications };
  204. _linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
  205. _linkedBinding(name: 'electron_browser_session'): SessionBinding;
  206. _linkedBinding(name: 'electron_browser_screen'): { createScreen(): Electron.Screen };
  207. _linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
  208. _linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
  209. _linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
  210. _linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
  211. _linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
  212. _linkedBinding(name: 'electron_browser_web_frame_main'): WebFrameMainBinding;
  213. _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
  214. _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
  215. _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
  216. log: NodeJS.WriteStream['write'];
  217. activateUvLoop(): void;
  218. // Additional events
  219. once(event: 'document-start', listener: () => any): this;
  220. once(event: 'document-end', listener: () => any): this;
  221. // Additional properties
  222. _firstFileName?: string;
  223. _serviceStartupScript: string;
  224. _getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;
  225. helperExecPath: string;
  226. mainModule?: NodeJS.Module | undefined;
  227. appCodeLoaded?: () => void;
  228. }
  229. }
  230. declare module NodeJS {
  231. interface Global {
  232. require: NodeRequire;
  233. module: NodeModule;
  234. __filename: string;
  235. __dirname: string;
  236. }
  237. }
  238. interface ContextMenuItem {
  239. id: number;
  240. label: string;
  241. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  242. checked: boolean;
  243. enabled: boolean;
  244. subItems: ContextMenuItem[];
  245. }
  246. declare interface Window {
  247. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  248. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  249. InspectorFrontendHost?: {
  250. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  251. };
  252. DevToolsAPI?: {
  253. contextMenuItemSelected: (id: number) => void;
  254. contextMenuCleared: () => void
  255. };
  256. UI?: {
  257. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  258. };
  259. Persistence?: {
  260. FileSystemWorkspaceBinding: {
  261. completeURL: (project: string, path: string) => string;
  262. }
  263. };
  264. WebView: typeof ElectronInternal.WebViewElement;
  265. trustedTypes: TrustedTypePolicyFactory;
  266. }
  267. // https://github.com/electron/electron/blob/main/docs/tutorial/message-ports.md#extension-close-event
  268. interface MessagePort {
  269. onclose: () => void;
  270. }
  271. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  272. type TrustedHTML = string;
  273. type TrustedScript = string;
  274. type TrustedScriptURL = string;
  275. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  276. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  277. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  278. interface TrustedTypePolicy {
  279. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  280. createScript(input: string, ...arguments: any[]): TrustedScript;
  281. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  282. }
  283. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  284. interface TrustedTypePolicyOptions {
  285. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  286. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  287. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  288. }
  289. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  290. interface TrustedTypePolicyFactory {
  291. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  292. isHTML(value: any): boolean;
  293. isScript(value: any): boolean;
  294. isScriptURL(value: any): boolean;
  295. readonly emptyHTML: TrustedHTML;
  296. readonly emptyScript: TrustedScript;
  297. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  298. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  299. readonly defaultPolicy: TrustedTypePolicy | null;
  300. }