internal-ambient.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  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. 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 SessionBinding {
  105. fromPartition: typeof Electron.Session.fromPartition,
  106. fromPath: typeof Electron.Session.fromPath,
  107. Session: typeof Electron.Session
  108. }
  109. interface WebViewManagerBinding {
  110. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  111. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  112. }
  113. interface WebFrameMainBinding {
  114. WebFrameMain: typeof Electron.WebFrameMain;
  115. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  116. fromIdOrNull(processId: number, routingId: number): Electron.WebFrameMain | null;
  117. }
  118. interface InternalWebPreferences {
  119. isWebView: boolean;
  120. hiddenPage: boolean;
  121. nodeIntegration: boolean;
  122. webviewTag: boolean;
  123. }
  124. interface InternalWebFrame extends Electron.WebFrame {
  125. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  126. getWebFrameId(window: Window): number;
  127. allowGuestViewElementDefinition(context: object, callback: Function): void;
  128. }
  129. interface WebFrameBinding {
  130. mainFrame: InternalWebFrame;
  131. }
  132. type DataPipe = {
  133. write: (buf: Uint8Array) => Promise<void>;
  134. done: () => void;
  135. };
  136. type BodyFunc = (pipe: DataPipe) => void;
  137. type CreateURLLoaderOptions = {
  138. method: string;
  139. url: string;
  140. extraHeaders?: Record<string, string>;
  141. useSessionCookies?: boolean;
  142. credentials?: 'include' | 'omit' | 'same-origin';
  143. body: Uint8Array | BodyFunc;
  144. session?: Electron.Session;
  145. partition?: string;
  146. referrer?: string;
  147. referrerPolicy?: string;
  148. cache?: string;
  149. origin?: string;
  150. hasUserActivation?: boolean;
  151. mode?: string;
  152. destination?: string;
  153. bypassCustomProtocolHandlers?: boolean;
  154. };
  155. type ResponseHead = {
  156. statusCode: number;
  157. statusMessage: string;
  158. httpVersion: { major: number, minor: number };
  159. rawHeaders: { key: string, value: string }[];
  160. headers: Record<string, string[]>;
  161. };
  162. type RedirectInfo = {
  163. statusCode: number;
  164. newMethod: string;
  165. newUrl: string;
  166. newSiteForCookies: string;
  167. newReferrer: string;
  168. insecureSchemeWasUpgraded: boolean;
  169. isSignedExchangeFallbackRedirect: boolean;
  170. }
  171. interface URLLoader extends EventEmitter {
  172. cancel(): void;
  173. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  174. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  175. on(eventName: 'complete', listener: (event: any) => void): this;
  176. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  177. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  178. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  179. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  180. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  181. }
  182. interface Process {
  183. internalBinding?(name: string): any;
  184. _linkedBinding(name: string): any;
  185. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  186. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  187. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  188. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  189. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  190. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  191. _linkedBinding(name: 'electron_common_net'): NetBinding;
  192. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  193. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  194. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  195. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  196. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  197. _linkedBinding(name: 'electron_browser_crash_reporter'): CrashReporterBinding;
  198. _linkedBinding(name: 'electron_browser_desktop_capturer'): { createDesktopCapturer(): ElectronInternal.DesktopCapturer; };
  199. _linkedBinding(name: 'electron_browser_event_emitter'): { setEventEmitterPrototype(prototype: Object): void; };
  200. _linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
  201. _linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
  202. _linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
  203. _linkedBinding(name: 'electron_browser_message_port'): { createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain }; };
  204. _linkedBinding(name: 'electron_browser_native_theme'): { nativeTheme: Electron.NativeTheme };
  205. _linkedBinding(name: 'electron_browser_notification'): NotificationBinding;
  206. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  207. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  208. _linkedBinding(name: 'electron_browser_push_notifications'): { pushNotifications: Electron.PushNotifications };
  209. _linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
  210. _linkedBinding(name: 'electron_browser_session'): SessionBinding;
  211. _linkedBinding(name: 'electron_browser_screen'): { createScreen(): Electron.Screen };
  212. _linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
  213. _linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
  214. _linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
  215. _linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
  216. _linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
  217. _linkedBinding(name: 'electron_browser_web_frame_main'): WebFrameMainBinding;
  218. _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
  219. _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
  220. _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
  221. log: NodeJS.WriteStream['write'];
  222. activateUvLoop(): void;
  223. // Additional events
  224. once(event: 'document-start', listener: () => any): this;
  225. once(event: 'document-end', listener: () => any): this;
  226. // Additional properties
  227. _firstFileName?: string;
  228. _serviceStartupScript: string;
  229. _getOrCreateArchive?: (path: string) => NodeJS.AsarArchive | null;
  230. helperExecPath: string;
  231. mainModule?: NodeJS.Module | undefined;
  232. appCodeLoaded?: () => void;
  233. }
  234. }
  235. declare module NodeJS {
  236. interface Global {
  237. require: NodeRequire;
  238. module: NodeModule;
  239. __filename: string;
  240. __dirname: string;
  241. }
  242. }
  243. interface ContextMenuItem {
  244. id: number;
  245. label: string;
  246. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  247. checked: boolean;
  248. enabled: boolean;
  249. subItems: ContextMenuItem[];
  250. }
  251. declare interface Window {
  252. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  253. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  254. InspectorFrontendHost?: {
  255. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  256. };
  257. DevToolsAPI?: {
  258. contextMenuItemSelected: (id: number) => void;
  259. contextMenuCleared: () => void
  260. };
  261. UI?: {
  262. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  263. };
  264. Persistence?: {
  265. FileSystemWorkspaceBinding: {
  266. completeURL: (project: string, path: string) => string;
  267. }
  268. };
  269. WebView: typeof ElectronInternal.WebViewElement;
  270. trustedTypes: TrustedTypePolicyFactory;
  271. }
  272. // https://github.com/electron/electron/blob/main/docs/tutorial/message-ports.md#extension-close-event
  273. interface MessagePort {
  274. onclose: () => void;
  275. }
  276. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  277. type TrustedHTML = string;
  278. type TrustedScript = string;
  279. type TrustedScriptURL = string;
  280. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  281. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  282. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  283. interface TrustedTypePolicy {
  284. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  285. createScript(input: string, ...arguments: any[]): TrustedScript;
  286. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  287. }
  288. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  289. interface TrustedTypePolicyOptions {
  290. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  291. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  292. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  293. }
  294. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  295. interface TrustedTypePolicyFactory {
  296. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  297. isHTML(value: any): boolean;
  298. isScript(value: any): boolean;
  299. isScriptURL(value: any): boolean;
  300. readonly emptyHTML: TrustedHTML;
  301. readonly emptyScript: TrustedScript;
  302. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  303. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  304. readonly defaultPolicy: TrustedTypePolicy | null;
  305. }