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. }
  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. isWinDarkModeWindowUiEnabled(): boolean;
  27. }
  28. interface IpcRendererBinding {
  29. send(internal: boolean, channel: string, args: any[]): void;
  30. sendSync(internal: boolean, channel: string, args: any[]): any;
  31. sendToHost(channel: string, args: any[]): void;
  32. sendTo(webContentsId: number, channel: string, args: any[]): void;
  33. invoke<T>(internal: boolean, channel: string, args: any[]): Promise<{ error: string, result: T }>;
  34. postMessage(channel: string, message: any, transferables: MessagePort[]): void;
  35. }
  36. interface V8UtilBinding {
  37. getHiddenValue<T>(obj: any, key: string): T;
  38. setHiddenValue<T>(obj: any, key: string, value: T): void;
  39. deleteHiddenValue(obj: any, key: string): void;
  40. requestGarbageCollectionForTesting(): void;
  41. runUntilIdle(): void;
  42. isSameOrigin(a: string, b: string): boolean;
  43. triggerFatalErrorForTesting(): void;
  44. }
  45. interface EnvironmentBinding {
  46. getVar(name: string): string | null;
  47. hasVar(name: string): boolean;
  48. setVar(name: string, value: string): boolean;
  49. unSetVar(name: string): boolean;
  50. }
  51. type AsarFileInfo = {
  52. size: number;
  53. unpacked: boolean;
  54. offset: number;
  55. integrity?: {
  56. algorithm: 'SHA256';
  57. hash: string;
  58. }
  59. };
  60. type AsarFileStat = {
  61. size: number;
  62. offset: number;
  63. isFile: boolean;
  64. isDirectory: boolean;
  65. isLink: boolean;
  66. }
  67. interface AsarArchive {
  68. getFileInfo(path: string): AsarFileInfo | false;
  69. stat(path: string): AsarFileStat | false;
  70. readdir(path: string): string[] | false;
  71. realpath(path: string): string | false;
  72. copyFileOut(path: string): string | false;
  73. getFdAndValidateIntegrityLater(): number | -1;
  74. }
  75. interface AsarBinding {
  76. createArchive(path: string): AsarArchive;
  77. splitPath(path: string): {
  78. isAsar: false;
  79. } | {
  80. isAsar: true;
  81. asarPath: string;
  82. filePath: string;
  83. };
  84. initAsarSupport(require: NodeJS.Require): void;
  85. }
  86. interface PowerMonitorBinding extends Electron.PowerMonitor {
  87. createPowerMonitor(): PowerMonitorBinding;
  88. setListeningForShutdown(listening: boolean): void;
  89. }
  90. interface WebViewManagerBinding {
  91. addGuest(guestInstanceId: number, embedder: Electron.WebContents, guest: Electron.WebContents, webPreferences: Electron.WebPreferences): void;
  92. removeGuest(embedder: Electron.WebContents, guestInstanceId: number): void;
  93. }
  94. interface InternalWebPreferences {
  95. contextIsolation: boolean;
  96. isWebView: boolean;
  97. hiddenPage: boolean;
  98. nativeWindowOpen: boolean;
  99. nodeIntegration: boolean;
  100. openerId: number;
  101. preload: string
  102. preloadScripts: string[];
  103. webviewTag: boolean;
  104. }
  105. interface InternalWebFrame extends Electron.WebFrame {
  106. getWebPreference<K extends keyof InternalWebPreferences>(name: K): InternalWebPreferences[K];
  107. getWebFrameId(window: Window): number;
  108. allowGuestViewElementDefinition(context: object, callback: Function): void;
  109. }
  110. interface WebFrameBinding {
  111. mainFrame: InternalWebFrame;
  112. }
  113. type DataPipe = {
  114. write: (buf: Uint8Array) => Promise<void>;
  115. done: () => void;
  116. };
  117. type BodyFunc = (pipe: DataPipe) => void;
  118. type CreateURLLoaderOptions = {
  119. method: string;
  120. url: string;
  121. extraHeaders?: Record<string, string>;
  122. useSessionCookies?: boolean;
  123. credentials?: 'include' | 'omit';
  124. body: Uint8Array | BodyFunc;
  125. session?: Electron.Session;
  126. partition?: string;
  127. referrer?: string;
  128. origin?: string;
  129. hasUserActivation?: boolean;
  130. mode?: string;
  131. destination?: string;
  132. };
  133. type ResponseHead = {
  134. statusCode: number;
  135. statusMessage: string;
  136. httpVersion: { major: number, minor: number };
  137. rawHeaders: { key: string, value: string }[];
  138. };
  139. type RedirectInfo = {
  140. statusCode: number;
  141. newMethod: string;
  142. newUrl: string;
  143. newSiteForCookies: string;
  144. newReferrer: string;
  145. insecureSchemeWasUpgraded: boolean;
  146. isSignedExchangeFallbackRedirect: boolean;
  147. }
  148. interface URLLoader extends EventEmitter {
  149. cancel(): void;
  150. on(eventName: 'data', listener: (event: any, data: ArrayBuffer, resume: () => void) => void): this;
  151. on(eventName: 'response-started', listener: (event: any, finalUrl: string, responseHead: ResponseHead) => void): this;
  152. on(eventName: 'complete', listener: (event: any) => void): this;
  153. on(eventName: 'error', listener: (event: any, netErrorString: string) => void): this;
  154. on(eventName: 'login', listener: (event: any, authInfo: Electron.AuthInfo, callback: (username?: string, password?: string) => void) => void): this;
  155. on(eventName: 'redirect', listener: (event: any, redirectInfo: RedirectInfo, headers: Record<string, string>) => void): this;
  156. on(eventName: 'upload-progress', listener: (event: any, position: number, total: number) => void): this;
  157. on(eventName: 'download-progress', listener: (event: any, current: number) => void): this;
  158. }
  159. interface Process {
  160. internalBinding?(name: string): any;
  161. _linkedBinding(name: string): any;
  162. _linkedBinding(name: 'electron_common_asar'): AsarBinding;
  163. _linkedBinding(name: 'electron_common_clipboard'): Electron.Clipboard;
  164. _linkedBinding(name: 'electron_common_command_line'): Electron.CommandLine;
  165. _linkedBinding(name: 'electron_common_environment'): EnvironmentBinding;
  166. _linkedBinding(name: 'electron_common_features'): FeaturesBinding;
  167. _linkedBinding(name: 'electron_common_native_image'): { nativeImage: typeof Electron.NativeImage };
  168. _linkedBinding(name: 'electron_common_native_theme'): { nativeTheme: Electron.NativeTheme };
  169. _linkedBinding(name: 'electron_common_notification'): {
  170. isSupported(): boolean;
  171. Notification: typeof Electron.Notification;
  172. }
  173. _linkedBinding(name: 'electron_common_screen'): { createScreen(): Electron.Screen };
  174. _linkedBinding(name: 'electron_common_shell'): Electron.Shell;
  175. _linkedBinding(name: 'electron_common_v8_util'): V8UtilBinding;
  176. _linkedBinding(name: 'electron_browser_app'): { app: Electron.App, App: Function };
  177. _linkedBinding(name: 'electron_browser_auto_updater'): { autoUpdater: Electron.AutoUpdater };
  178. _linkedBinding(name: 'electron_browser_browser_view'): { BrowserView: typeof Electron.BrowserView };
  179. _linkedBinding(name: 'electron_browser_crash_reporter'): Omit<Electron.CrashReporter, 'start'> & {
  180. start(submitUrl: string,
  181. uploadToServer: boolean,
  182. ignoreSystemCrashHandler: boolean,
  183. rateLimit: boolean,
  184. compress: boolean,
  185. globalExtra: Record<string, string>,
  186. extra: Record<string, string>,
  187. isNodeProcess: boolean): void;
  188. };
  189. _linkedBinding(name: 'electron_browser_desktop_capturer'): {
  190. createDesktopCapturer(): ElectronInternal.DesktopCapturer;
  191. };
  192. _linkedBinding(name: 'electron_browser_event'): {
  193. createWithSender(sender: Electron.WebContents): Electron.Event;
  194. createEmpty(): Electron.Event;
  195. };
  196. _linkedBinding(name: 'electron_browser_event_emitter'): {
  197. setEventEmitterPrototype(prototype: Object): void;
  198. };
  199. _linkedBinding(name: 'electron_browser_global_shortcut'): { globalShortcut: Electron.GlobalShortcut };
  200. _linkedBinding(name: 'electron_browser_image_view'): { ImageView: any };
  201. _linkedBinding(name: 'electron_browser_in_app_purchase'): { inAppPurchase: Electron.InAppPurchase };
  202. _linkedBinding(name: 'electron_browser_message_port'): {
  203. createPair(): { port1: Electron.MessagePortMain, port2: Electron.MessagePortMain };
  204. };
  205. _linkedBinding(name: 'electron_browser_net'): {
  206. isOnline(): boolean;
  207. isValidHeaderName: (headerName: string) => boolean;
  208. isValidHeaderValue: (headerValue: string) => boolean;
  209. Net: any;
  210. net: any;
  211. createURLLoader(options: CreateURLLoaderOptions): URLLoader;
  212. };
  213. _linkedBinding(name: 'electron_browser_power_monitor'): PowerMonitorBinding;
  214. _linkedBinding(name: 'electron_browser_power_save_blocker'): { powerSaveBlocker: Electron.PowerSaveBlocker };
  215. _linkedBinding(name: 'electron_browser_safe_storage'): { safeStorage: Electron.SafeStorage };
  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. }