internal-ambient.d.ts 13 KB

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