internal-ambient.d.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /* eslint-disable no-var */
  2. declare var internalBinding: any;
  3. declare var binding: { get: (name: string) => any; process: NodeJS.Process; createPreloadScript: (src: string) => Function };
  4. declare var isolatedApi: {
  5. guestViewInternal: any;
  6. allowGuestViewElementDefinition: NodeJS.InternalWebFrame['allowGuestViewElementDefinition'];
  7. setIsWebView: (iframe: HTMLIFrameElement) => void;
  8. }
  9. declare const BUILDFLAG: (flag: boolean) => boolean;
  10. declare const ENABLE_DESKTOP_CAPTURER: boolean;
  11. declare const ENABLE_VIEWS_API: boolean;
  12. declare namespace NodeJS {
  13. interface FeaturesBinding {
  14. isBuiltinSpellCheckerEnabled(): boolean;
  15. isDesktopCapturerEnabled(): boolean;
  16. isOffscreenRenderingEnabled(): boolean;
  17. isPDFViewerEnabled(): boolean;
  18. isRunAsNodeEnabled(): boolean;
  19. isFakeLocationProviderEnabled(): boolean;
  20. isViewApiEnabled(): boolean;
  21. isTtsEnabled(): boolean;
  22. isPrintingEnabled(): boolean;
  23. isPictureInPictureEnabled(): boolean;
  24. isExtensionsEnabled(): boolean;
  25. isComponentBuild(): boolean;
  26. }
  27. interface IpcRendererBinding {
  28. send(internal: boolean, channel: string, args: any[]): void;
  29. sendSync(internal: boolean, channel: string, args: any[]): any;
  30. sendToHost(channel: string, args: any[]): void;
  31. sendTo(webContentsId: number, channel: string, args: any[]): void;
  32. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  33. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  34. }
  35. interface V8UtilBinding {
  36. getHiddenValue<T>(obj: any, key: string): T;
  37. setHiddenValue<T>(obj: any, key: string, value: T): void;
  38. deleteHiddenValue(obj: any, key: string): void;
  39. requestGarbageCollectionForTesting(): void;
  40. runUntilIdle(): void;
  41. triggerFatalErrorForTesting(): void;
  42. }
  43. interface EnvironmentBinding {
  44. getVar(name: string): string | null;
  45. hasVar(name: string): boolean;
  46. setVar(name: string, value: string): boolean;
  47. unSetVar(name: string): boolean;
  48. }
  49. type AsarFileInfo = {
  50. size: number;
  51. unpacked: boolean;
  52. offset: number;
  53. integrity?: {
  54. algorithm: 'SHA256';
  55. hash: string;
  56. }
  57. };
  58. type AsarFileStat = {
  59. size: number;
  60. offset: number;
  61. isFile: boolean;
  62. isDirectory: boolean;
  63. isLink: boolean;
  64. }
  65. interface AsarArchive {
  66. getFileInfo(path: string): AsarFileInfo | false;
  67. stat(path: string): AsarFileStat | false;
  68. readdir(path: string): string[] | false;
  69. realpath(path: string): string | false;
  70. copyFileOut(path: string): string | false;
  71. getFdAndValidateIntegrityLater(): number | -1;
  72. }
  73. interface AsarBinding {
  74. Archive: { new(path: string): AsarArchive };
  75. splitPath(path: string): {
  76. isAsar: false;
  77. } | {
  78. isAsar: true;
  79. asarPath: string;
  80. filePath: string;
  81. };
  82. initAsarSupport(require: NodeJS.Require): void;
  83. }
  84. interface PowerMonitorBinding extends Electron.PowerMonitor {
  85. createPowerMonitor(): PowerMonitorBinding;
  86. setListeningForShutdown(listening: boolean): void;
  87. }
  88. interface WebViewManagerBinding {
  89. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  90. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  91. }
  92. interface InternalWebPreferences {
  93. isWebView: boolean;
  94. hiddenPage: boolean;
  95. nodeIntegration: boolean;
  96. webviewTag: boolean;
  97. }
  98. interface InternalWebFrame extends Electron.WebFrame {
  99. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  100. getWebFrameId(window: Window): number;
  101. allowGuestViewElementDefinition(context: object, callback: Function): void;
  102. }
  103. interface WebFrameBinding {
  104. mainFrame: InternalWebFrame;
  105. }
  106. type DataPipe = {
  107. write: (buf: Uint8Array) => Promise<void>;
  108. done: () => void;
  109. };
  110. type BodyFunc = (pipe: DataPipe) => void;
  111. type CreateURLLoaderOptions = {
  112. method: string;
  113. url: string;
  114. extraHeaders?: Record<string, string>;
  115. useSessionCookies?: boolean;
  116. credentials?: 'include' | 'omit';
  117. body: Uint8Array | BodyFunc;
  118. session?: Electron.Session;
  119. partition?: string;
  120. referrer?: string;
  121. origin?: string;
  122. hasUserActivation?: boolean;
  123. mode?: string;
  124. destination?: string;
  125. };
  126. type ResponseHead = {
  127. statusCode: number;
  128. statusMessage: string;
  129. httpVersion: { major: number, minor: number };
  130. rawHeaders: { key: string, value: string }[];
  131. };
  132. type RedirectInfo = {
  133. statusCode: number;
  134. newMethod: string;
  135. newUrl: string;
  136. newSiteForCookies: string;
  137. newReferrer: string;
  138. insecureSchemeWasUpgraded: boolean;
  139. isSignedExchangeFallbackRedirect: boolean;
  140. }
  141. interface URLLoader extends EventEmitter {
  142. cancel(): void;
  143. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  144. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  145. on(eventName: 'complete', listener: (event: any) => void): this;
  146. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  147. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  148. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  149. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  150. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  151. }
  152. interface Process {
  153. internalBinding?(name: string): any;
  154. _linkedBinding(name: string): any;
  155. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  156. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  157. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  158. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  159. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  160. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  161. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  162. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  163. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  164. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  165. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  166. _linkedBinding(name: 'electron_browser_crash_reporter'): Omit<Electron.CrashReporter, 'start'> & {
  167. start(submitUrl: string,
  168. uploadToServer: boolean,
  169. ignoreSystemCrashHandler: boolean,
  170. rateLimit: boolean,
  171. compress: boolean,
  172. globalExtra: Record<string, string>,
  173. extra: Record<string, string>,
  174. isNodeProcess: boolean): void;
  175. };
  176. _linkedBinding(name: 'electron_browser_desktop_capturer'): {
  177. createDesktopCapturer(): ElectronInternal.DesktopCapturer;
  178. };
  179. _linkedBinding(name: 'electron_browser_event'): {
  180. createWithSender(sender: Electron.WebContents): Electron.Event;
  181. createEmpty(): Electron.Event;
  182. };
  183. _linkedBinding(name: 'electron_browser_event_emitter'): {
  184. setEventEmitterPrototype(prototype: Object): void;
  185. };
  186. _linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
  187. _linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
  188. _linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
  189. _linkedBinding(name: 'electron_browser_message_port'): {
  190. createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain };
  191. };
  192. _linkedBinding(name: 'electron_browser_native_theme'): { nativeTheme: Electron.NativeTheme };
  193. _linkedBinding(name: 'electron_browser_net'): {
  194. isOnline(): boolean;
  195. isValidHeaderName: (headerName: string) => boolean;
  196. isValidHeaderValue: (headerValue: string) => boolean;
  197. fileURLToFilePath: (url: string) => string;
  198. Net: any;
  199. net: any;
  200. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  201. };
  202. _linkedBinding(name: 'electron_browser_notification'): {
  203. isSupported(): boolean;
  204. Notification: typeof Electron.Notification;
  205. }
  206. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  207. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  208. _linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
  209. _linkedBinding(name: 'electron_browser_session'): typeof Electron.Session;
  210. _linkedBinding(name: 'electron_browser_screen'): { createScreen(): Electron.Screen };
  211. _linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
  212. _linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
  213. _linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
  214. _linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
  215. _linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
  216. _linkedBinding(name: 'electron_browser_web_frame_main'): {
  217. WebFrameMain: typeof Electron.WebFrameMain;
  218. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  219. }
  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. helperExecPath: string;
  231. mainModule?: NodeJS.Module | undefined;
  232. }
  233. }
  234. declare module NodeJS {
  235. interface Global {
  236. require: NodeRequire;
  237. module: NodeModule;
  238. __filename: string;
  239. __dirname: string;
  240. }
  241. }
  242. interface ContextMenuItem {
  243. id: number;
  244. label: string;
  245. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  246. checked: boolean;
  247. enabled: boolean;
  248. subItems: ContextMenuItem[];
  249. }
  250. declare interface Window {
  251. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  252. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  253. InspectorFrontendHost?: {
  254. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  255. };
  256. DevToolsAPI?: {
  257. contextMenuItemSelected: (id: number) => void;
  258. contextMenuCleared: () => void
  259. };
  260. UI?: {
  261. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  262. };
  263. Persistence?: {
  264. FileSystemWorkspaceBinding: {
  265. completeURL: (project: string, path: string) => string;
  266. }
  267. };
  268. WebView: typeof ElectronInternal.WebViewElement;
  269. trustedTypes: TrustedTypePolicyFactory;
  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. }