internal-ambient.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. createNativeImage: typeof Electron.nativeImage['createEmpty'];
  9. }
  10. declare const BUILDFLAG: (flag: boolean) => boolean;
  11. declare const ENABLE_DESKTOP_CAPTURER: boolean;
  12. declare const ENABLE_VIEWS_API: boolean;
  13. declare namespace NodeJS {
  14. interface FeaturesBinding {
  15. isBuiltinSpellCheckerEnabled(): boolean;
  16. isDesktopCapturerEnabled(): boolean;
  17. isOffscreenRenderingEnabled(): boolean;
  18. isPDFViewerEnabled(): boolean;
  19. isRunAsNodeEnabled(): boolean;
  20. isFakeLocationProviderEnabled(): boolean;
  21. isViewApiEnabled(): boolean;
  22. isTtsEnabled(): boolean;
  23. isPrintingEnabled(): boolean;
  24. isPictureInPictureEnabled(): boolean;
  25. isExtensionsEnabled(): boolean;
  26. isComponentBuild(): boolean;
  27. isWinDarkModeWindowUiEnabled(): boolean;
  28. }
  29. interface IpcRendererBinding {
  30. send(internal: boolean, channel: string, args: any[]): void;
  31. sendSync(internal: boolean, channel: string, args: any[]): any;
  32. sendToHost(channel: string, args: any[]): void;
  33. sendTo(webContentsId: number, channel: string, args: any[]): void;
  34. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  35. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  36. }
  37. interface V8UtilBinding {
  38. getHiddenValue<T>(obj: any, key: string): T;
  39. setHiddenValue<T>(obj: any, key: string, value: T): void;
  40. deleteHiddenValue(obj: any, key: string): void;
  41. requestGarbageCollectionForTesting(): void;
  42. runUntilIdle(): void;
  43. isSameOrigin(a: string, b: string): boolean;
  44. triggerFatalErrorForTesting(): 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. };
  57. type AsarFileStat = {
  58. size: number;
  59. offset: number;
  60. isFile: boolean;
  61. isDirectory: boolean;
  62. isLink: boolean;
  63. }
  64. interface AsarArchive {
  65. readonly path: string;
  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. getFd(): number | -1;
  72. }
  73. interface AsarBinding {
  74. createArchive(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. contextIsolation: boolean;
  94. guestInstanceId: number;
  95. hiddenPage: boolean;
  96. nativeWindowOpen: boolean;
  97. nodeIntegration: boolean;
  98. openerId: number;
  99. preload: string
  100. preloadScripts: string[];
  101. webviewTag: boolean;
  102. }
  103. interface InternalWebFrame extends Electron.WebFrame {
  104. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  105. getWebFrameId(window: Window): number;
  106. allowGuestViewElementDefinition(context: object, callback: Function): void;
  107. }
  108. interface WebFrameBinding {
  109. mainFrame: InternalWebFrame;
  110. }
  111. type DataPipe = {
  112. write: (buf: Uint8Array) => Promise<void>;
  113. done: () => void;
  114. };
  115. type BodyFunc = (pipe: DataPipe) => void;
  116. type CreateURLLoaderOptions = {
  117. method: string;
  118. url: string;
  119. extraHeaders?: Record<string, string>;
  120. useSessionCookies?: boolean;
  121. credentials?: 'include' | 'omit';
  122. body: Uint8Array | BodyFunc;
  123. session?: Electron.Session;
  124. partition?: string;
  125. referrer?: string;
  126. origin?: string;
  127. hasUserActivation?: boolean;
  128. mode?: string;
  129. destination?: string;
  130. };
  131. type ResponseHead = {
  132. statusCode: number;
  133. statusMessage: string;
  134. httpVersion: { major: number, minor: number };
  135. rawHeaders: { key: string, value: string }[];
  136. };
  137. type RedirectInfo = {
  138. statusCode: number;
  139. newMethod: string;
  140. newUrl: string;
  141. newSiteForCookies: string;
  142. newReferrer: string;
  143. insecureSchemeWasUpgraded: boolean;
  144. isSignedExchangeFallbackRedirect: boolean;
  145. }
  146. interface URLLoader extends EventEmitter {
  147. cancel(): void;
  148. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  149. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  150. on(eventName: 'complete', listener: (event: any) => void): this;
  151. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  152. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  153. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  154. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  155. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  156. }
  157. interface Process {
  158. internalBinding?(name: string): any;
  159. _linkedBinding(name: string): any;
  160. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  161. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  162. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  163. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  164. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  165. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  166. _linkedBinding(name: 'electron_common_native_theme'): { nativeTheme: Electron.NativeTheme };
  167. _linkedBinding(name: 'electron_common_notification'): {
  168. isSupported(): boolean;
  169. Notification: typeof Electron.Notification;
  170. }
  171. _linkedBinding(name: 'electron_common_screen'): { createScreen(): Electron.Screen };
  172. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  173. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  174. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  175. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  176. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  177. _linkedBinding(name: 'electron_browser_crash_reporter'): Omit<Electron.CrashReporter, 'start'> & {
  178. start(submitUrl: string,
  179. uploadToServer: boolean,
  180. ignoreSystemCrashHandler: boolean,
  181. rateLimit: boolean,
  182. compress: boolean,
  183. globalExtra: Record<string, string>,
  184. extra: Record<string, string>,
  185. isNodeProcess: boolean): void;
  186. };
  187. _linkedBinding(name: 'electron_browser_desktop_capturer'): {
  188. createDesktopCapturer(): ElectronInternal.DesktopCapturer;
  189. };
  190. _linkedBinding(name: 'electron_browser_event'): {
  191. createWithSender(sender: Electron.WebContents): Electron.Event;
  192. createEmpty(): Electron.Event;
  193. };
  194. _linkedBinding(name: 'electron_browser_event_emitter'): {
  195. setEventEmitterPrototype(prototype: Object): void;
  196. };
  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'): {
  201. createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain };
  202. };
  203. _linkedBinding(name: 'electron_browser_net'): {
  204. isOnline(): boolean;
  205. isValidHeaderName: (headerName: string) => boolean;
  206. isValidHeaderValue: (headerValue: string) => boolean;
  207. Net: any;
  208. net: any;
  209. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  210. };
  211. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  212. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  213. _linkedBinding(name: 'electron_browser_session'): typeof Electron.Session;
  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'): {
  220. WebFrameMain: typeof Electron.WebFrameMain;
  221. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  222. }
  223. _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
  224. _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
  225. _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
  226. log: NodeJS.WriteStream['write'];
  227. activateUvLoop(): void;
  228. // Additional events
  229. once(event: 'document-start', listener: () => any): this;
  230. once(event: 'document-end', listener: () => any): this;
  231. // Additional properties
  232. _firstFileName?: string;
  233. helperExecPath: string;
  234. mainModule: NodeJS.Module;
  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. ResizeObserver: ResizeObserver;
  273. trustedTypes: TrustedTypePolicyFactory;
  274. }
  275. /**
  276. * The ResizeObserver interface is used to observe changes to Element's content
  277. * rect.
  278. *
  279. * It is modeled after MutationObserver and IntersectionObserver.
  280. */
  281. declare class ResizeObserver {
  282. constructor (callback: ResizeObserverCallback);
  283. /**
  284. * Adds target to the list of observed elements.
  285. */
  286. observe: (target: Element) => void;
  287. /**
  288. * Removes target from the list of observed elements.
  289. */
  290. unobserve: (target: Element) => void;
  291. /**
  292. * Clears both the observationTargets and activeTargets lists.
  293. */
  294. disconnect: () => void;
  295. }
  296. /**
  297. * This callback delivers ResizeObserver's notifications. It is invoked by a
  298. * broadcast active observations algorithm.
  299. */
  300. interface ResizeObserverCallback {
  301. (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
  302. }
  303. interface ResizeObserverEntry {
  304. /**
  305. * @param target The Element whose size has changed.
  306. */
  307. new (target: Element): ResizeObserverEntry;
  308. /**
  309. * The Element whose size has changed.
  310. */
  311. readonly target: Element;
  312. /**
  313. * Element's content rect when ResizeObserverCallback is invoked.
  314. */
  315. readonly contentRect: DOMRectReadOnly;
  316. }
  317. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  318. type TrustedHTML = string;
  319. type TrustedScript = string;
  320. type TrustedScriptURL = string;
  321. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  322. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  323. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  324. interface TrustedTypePolicy {
  325. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  326. createScript(input: string, ...arguments: any[]): TrustedScript;
  327. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  328. }
  329. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  330. interface TrustedTypePolicyOptions {
  331. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  332. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  333. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  334. }
  335. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  336. interface TrustedTypePolicyFactory {
  337. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  338. isHTML(value: any): boolean;
  339. isScript(value: any): boolean;
  340. isScriptURL(value: any): boolean;
  341. readonly emptyHTML: TrustedHTML;
  342. readonly emptyScript: TrustedScript;
  343. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  344. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  345. readonly defaultPolicy: TrustedTypePolicy | null;
  346. }