internal-ambient.d.ts 13 KB

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