internal-ambient.d.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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(internal: boolean, 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. weaklyTrackValue(value: any): void;
  43. clearWeaklyTrackedValues(): void;
  44. getWeaklyTrackedValues(): any[];
  45. runUntilIdle(): void;
  46. isSameOrigin(a: string, b: string): boolean;
  47. triggerFatalErrorForTesting(): void;
  48. }
  49. interface EnvironmentBinding {
  50. getVar(name: string): string | null;
  51. hasVar(name: string): boolean;
  52. setVar(name: string, value: string): boolean;
  53. unSetVar(name: string): boolean;
  54. }
  55. type AsarFileInfo = {
  56. size: number;
  57. unpacked: boolean;
  58. offset: number;
  59. };
  60. type AsarFileStat = {
  61. size: number;
  62. offset: number;
  63. isFile: boolean;
  64. isDirectory: boolean;
  65. isLink: boolean;
  66. }
  67. interface AsarArchive {
  68. readonly path: string;
  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. getFd(): number | -1;
  75. }
  76. interface AsarBinding {
  77. createArchive(path: string): AsarArchive;
  78. splitPath(path: string): {
  79. isAsar: false;
  80. } | {
  81. isAsar: true;
  82. asarPath: string;
  83. filePath: string;
  84. };
  85. initAsarSupport(require: NodeJS.Require): void;
  86. }
  87. interface PowerMonitorBinding extends Electron.PowerMonitor {
  88. createPowerMonitor(): PowerMonitorBinding;
  89. setListeningForShutdown(listening: boolean): void;
  90. }
  91. interface WebViewManagerBinding {
  92. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  93. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  94. }
  95. interface InternalWebPreferences {
  96. contextIsolation: boolean;
  97. guestInstanceId: number;
  98. hiddenPage: boolean;
  99. nativeWindowOpen: boolean;
  100. nodeIntegration: boolean;
  101. openerId: number;
  102. preload: string
  103. preloadScripts: string[];
  104. webviewTag: boolean;
  105. }
  106. interface InternalWebFrame extends Electron.WebFrame {
  107. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  108. getWebFrameId(window: Window): number;
  109. allowGuestViewElementDefinition(context: object, callback: Function): void;
  110. }
  111. interface WebFrameBinding {
  112. mainFrame: InternalWebFrame;
  113. }
  114. type DataPipe = {
  115. write: (buf: Uint8Array) => Promise<void>;
  116. done: () => void;
  117. };
  118. type BodyFunc = (pipe: DataPipe) => void;
  119. type CreateURLLoaderOptions = {
  120. method: string;
  121. url: string;
  122. extraHeaders?: Record<string, string>;
  123. useSessionCookies?: boolean;
  124. credentials?: 'include' | 'omit';
  125. body: Uint8Array | BodyFunc;
  126. session?: Electron.Session;
  127. partition?: string;
  128. referrer?: string;
  129. origin?: string;
  130. hasUserActivation?: boolean;
  131. mode?: string;
  132. destination?: string;
  133. };
  134. type ResponseHead = {
  135. statusCode: number;
  136. statusMessage: string;
  137. httpVersion: { major: number, minor: number };
  138. rawHeaders: { key: string, value: string }[];
  139. };
  140. type RedirectInfo = {
  141. statusCode: number;
  142. newMethod: string;
  143. newUrl: string;
  144. newSiteForCookies: string;
  145. newReferrer: string;
  146. insecureSchemeWasUpgraded: boolean;
  147. isSignedExchangeFallbackRedirect: boolean;
  148. }
  149. interface URLLoader extends EventEmitter {
  150. cancel(): void;
  151. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  152. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  153. on(eventName: 'complete', listener: (event: any) => void): this;
  154. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  155. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  156. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  157. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  158. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  159. }
  160. interface Process {
  161. internalBinding?(name: string): any;
  162. _linkedBinding(name: string): any;
  163. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  164. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  165. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  166. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  167. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  168. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  169. _linkedBinding(name: 'electron_common_native_theme'): { nativeTheme: Electron.NativeTheme };
  170. _linkedBinding(name: 'electron_common_notification'): {
  171. isSupported(): boolean;
  172. Notification: typeof Electron.Notification;
  173. }
  174. _linkedBinding(name: 'electron_common_screen'): { createScreen(): Electron.Screen };
  175. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  176. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  177. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  178. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  179. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  180. _linkedBinding(name: 'electron_browser_crash_reporter'): Omit<Electron.CrashReporter, 'start'> & {
  181. start(submitUrl: string,
  182. uploadToServer: boolean,
  183. ignoreSystemCrashHandler: boolean,
  184. rateLimit: boolean,
  185. compress: boolean,
  186. globalExtra: Record<string, string>,
  187. extra: Record<string, string>,
  188. isNodeProcess: boolean): void;
  189. };
  190. _linkedBinding(name: 'electron_browser_desktop_capturer'): {
  191. createDesktopCapturer(): ElectronInternal.DesktopCapturer;
  192. };
  193. _linkedBinding(name: 'electron_browser_event'): {
  194. createWithSender(sender: Electron.WebContents): Electron.Event;
  195. createEmpty(): Electron.Event;
  196. };
  197. _linkedBinding(name: 'electron_browser_event_emitter'): {
  198. setEventEmitterPrototype(prototype: Object): void;
  199. };
  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'): {
  204. createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain };
  205. };
  206. _linkedBinding(name: 'electron_browser_net'): {
  207. isOnline(): boolean;
  208. isValidHeaderName: (headerName: string) => boolean;
  209. isValidHeaderValue: (headerValue: string) => boolean;
  210. Net: any;
  211. net: any;
  212. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  213. };
  214. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  215. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  216. _linkedBinding(name: 'electron_browser_session'): typeof Electron.Session;
  217. _linkedBinding(name: 'electron_browser_system_preferences'): { systemPreferences: Electron.SystemPreferences };
  218. _linkedBinding(name: 'electron_browser_tray'): { Tray: Electron.Tray };
  219. _linkedBinding(name: 'electron_browser_view'): { View: Electron.View };
  220. _linkedBinding(name: 'electron_browser_web_contents_view'): { WebContentsView: typeof Electron.WebContentsView };
  221. _linkedBinding(name: 'electron_browser_web_view_manager'): WebViewManagerBinding;
  222. _linkedBinding(name: 'electron_browser_web_frame_main'): {
  223. WebFrameMain: typeof Electron.WebFrameMain;
  224. fromId(processId: number, routingId: number): Electron.WebFrameMain;
  225. }
  226. _linkedBinding(name: 'electron_renderer_crash_reporter'): Electron.CrashReporter;
  227. _linkedBinding(name: 'electron_renderer_ipc'): { ipc: IpcRendererBinding };
  228. _linkedBinding(name: 'electron_renderer_web_frame'): WebFrameBinding;
  229. log: NodeJS.WriteStream['write'];
  230. activateUvLoop(): void;
  231. // Additional events
  232. once(event: 'document-start', listener: () => any): this;
  233. once(event: 'document-end', listener: () => any): this;
  234. // Additional properties
  235. _firstFileName?: string;
  236. helperExecPath: string;
  237. mainModule: NodeJS.Module;
  238. }
  239. }
  240. declare module NodeJS {
  241. interface Global {
  242. require: NodeRequire;
  243. module: NodeModule;
  244. __filename: string;
  245. __dirname: string;
  246. }
  247. }
  248. interface ContextMenuItem {
  249. id: number;
  250. label: string;
  251. type: 'normal' | 'separator' | 'subMenu' | 'checkbox';
  252. checked: boolean;
  253. enabled: boolean;
  254. subItems: ContextMenuItem[];
  255. }
  256. declare interface Window {
  257. ELECTRON_DISABLE_SECURITY_WARNINGS?: boolean;
  258. ELECTRON_ENABLE_SECURITY_WARNINGS?: boolean;
  259. InspectorFrontendHost?: {
  260. showContextMenuAtPoint: (x: number, y: number, items: ContextMenuItem[]) => void
  261. };
  262. DevToolsAPI?: {
  263. contextMenuItemSelected: (id: number) => void;
  264. contextMenuCleared: () => void
  265. };
  266. UI?: {
  267. createFileSelectorElement: (callback: () => void) => HTMLSpanElement
  268. };
  269. Persistence?: {
  270. FileSystemWorkspaceBinding: {
  271. completeURL: (project: string, path: string) => string;
  272. }
  273. };
  274. WebView: typeof ElectronInternal.WebViewElement;
  275. ResizeObserver: ResizeObserver;
  276. trustedTypes: TrustedTypePolicyFactory;
  277. }
  278. /**
  279. * The ResizeObserver interface is used to observe changes to Element's content
  280. * rect.
  281. *
  282. * It is modeled after MutationObserver and IntersectionObserver.
  283. */
  284. declare class ResizeObserver {
  285. constructor (callback: ResizeObserverCallback);
  286. /**
  287. * Adds target to the list of observed elements.
  288. */
  289. observe: (target: Element) => void;
  290. /**
  291. * Removes target from the list of observed elements.
  292. */
  293. unobserve: (target: Element) => void;
  294. /**
  295. * Clears both the observationTargets and activeTargets lists.
  296. */
  297. disconnect: () => void;
  298. }
  299. /**
  300. * This callback delivers ResizeObserver's notifications. It is invoked by a
  301. * broadcast active observations algorithm.
  302. */
  303. interface ResizeObserverCallback {
  304. (entries: ResizeObserverEntry[], observer: ResizeObserver): void;
  305. }
  306. interface ResizeObserverEntry {
  307. /**
  308. * @param target The Element whose size has changed.
  309. */
  310. new (target: Element): ResizeObserverEntry;
  311. /**
  312. * The Element whose size has changed.
  313. */
  314. readonly target: Element;
  315. /**
  316. * Element's content rect when ResizeObserverCallback is invoked.
  317. */
  318. readonly contentRect: DOMRectReadOnly;
  319. }
  320. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#trusted-types
  321. type TrustedHTML = string;
  322. type TrustedScript = string;
  323. type TrustedScriptURL = string;
  324. type TrustedType = TrustedHTML | TrustedScript | TrustedScriptURL;
  325. type StringContext = 'TrustedHTML' | 'TrustedScript' | 'TrustedScriptURL';
  326. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicy
  327. interface TrustedTypePolicy {
  328. createHTML(input: string, ...arguments: any[]): TrustedHTML;
  329. createScript(input: string, ...arguments: any[]): TrustedScript;
  330. createScriptURL(input: string, ...arguments: any[]): TrustedScriptURL;
  331. }
  332. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyoptions
  333. interface TrustedTypePolicyOptions {
  334. createHTML?: (input: string, ...arguments: any[]) => TrustedHTML;
  335. createScript?: (input: string, ...arguments: any[]) => TrustedScript;
  336. createScriptURL?: (input: string, ...arguments: any[]) => TrustedScriptURL;
  337. }
  338. // https://w3c.github.io/webappsec-trusted-types/dist/spec/#typedef-trustedtypepolicyfactory
  339. interface TrustedTypePolicyFactory {
  340. createPolicy(policyName: string, policyOptions: TrustedTypePolicyOptions): TrustedTypePolicy
  341. isHTML(value: any): boolean;
  342. isScript(value: any): boolean;
  343. isScriptURL(value: any): boolean;
  344. readonly emptyHTML: TrustedHTML;
  345. readonly emptyScript: TrustedScript;
  346. getAttributeType(tagName: string, attribute: string, elementNs?: string, attrNs?: string): StringContext | null;
  347. getPropertyType(tagName: string, property: string, elementNs?: string): StringContext | null;
  348. readonly defaultPolicy: TrustedTypePolicy | null;
  349. }