internal-ambient.d.ts 13 KB

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