internal-ambient.d.ts 14 KB

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