Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.d.ts 83KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. // Type definitions for puppeteer 5.4
  2. // Project: https://github.com/GoogleChrome/puppeteer#readme
  3. // Definitions by: Marvin Hagemeister <https://github.com/marvinhagemeister>
  4. // Christopher Deutsch <https://github.com/cdeutsch>
  5. // Konstantin Simon Maria Möllers <https://github.com/ksm2>
  6. // Simon Schick <https://github.com/SimonSchick>
  7. // Serban Ghita <https://github.com/SerbanGhita>
  8. // Jason Kaczmarsky <https://github.com/JasonKaz>
  9. // Dave Cardwell <https://github.com/davecardwell>
  10. // Andrés Ortiz <https://github.com/angrykoala>
  11. // Piotr Błażejewicz <https://github.com/peterblazejewicz>
  12. // Cameron Hunter <https://github.com/cameronhunter>
  13. // Pirasis Leelatanon <https://github.com/1pete>
  14. // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
  15. // TypeScript Version: 3.0
  16. /// <reference types="node" />
  17. import { ChildProcess } from 'child_process';
  18. export namespace devices {
  19. interface Device {
  20. name: string;
  21. userAgent: string;
  22. viewport: {
  23. width: number;
  24. height: number;
  25. deviceScaleFactor: number;
  26. isMobile: boolean;
  27. hasTouch: boolean;
  28. isLandscape: boolean;
  29. };
  30. }
  31. }
  32. export const devices: { [name: string]: devices.Device };
  33. declare class CustomError extends Error {
  34. constructor(message: string);
  35. }
  36. /**
  37. * TimeoutError is emitted whenever certain operations are terminated due to timeout.
  38. *
  39. * Example operations are {@link Page.waitForSelector | page.waitForSelector}
  40. * or {@link PuppeteerNode.launch | puppeteer.launch}.
  41. */
  42. declare class TimeoutError extends CustomError {}
  43. export namespace errors {
  44. class TimeoutError extends CustomError {}
  45. }
  46. /** Wraps a DOM element into an ElementHandle instance */
  47. export type WrapElementHandle<X> = X extends Element ? ElementHandle<X> : X;
  48. /** Unwraps a DOM element out of an ElementHandle instance */
  49. export type UnwrapElementHandle<X> = X extends ElementHandle<infer E> ? E : X;
  50. export type Serializable = number | string | boolean | null | JSONArray | JSONObject;
  51. export interface JSONArray extends Array<Serializable> {}
  52. export interface JSONObject {
  53. [key: string]: Serializable;
  54. }
  55. export type SerializableOrJSHandle = Serializable | JSHandle;
  56. /**
  57. * We want to maintain intellisense for known values but remain open to unknown values. This type is a workaround for
  58. * [Microsoft/TypeScript#29729](https://github.com/Microsoft/TypeScript/issues/29729). It will be removed as soon as
  59. * it's not needed anymore.
  60. */
  61. type LiteralUnion<LiteralType> = LiteralType | (string & { _?: never });
  62. export type Platform = LiteralUnion<'mac' | 'win32' | 'win64' | 'linux'>;
  63. export type Product = LiteralUnion<'chrome' | 'firefox'>;
  64. /** Defines `$eval` and `$$eval` for Page, Frame and ElementHandle. */
  65. export interface Evalable {
  66. /**
  67. * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
  68. * If there's no element matching `selector`, the method throws an error.
  69. *
  70. * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
  71. *
  72. * @param selector A selector to query for
  73. * @param pageFunction Function to be evaluated in browser context
  74. * @returns Promise which resolves to the return value of pageFunction
  75. */
  76. $eval<R>(selector: string, pageFunction: (element: Element) => R | Promise<R>): Promise<WrapElementHandle<R>>;
  77. /**
  78. * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
  79. * If there's no element matching `selector`, the method throws an error.
  80. *
  81. * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
  82. *
  83. * @param selector A selector to query for
  84. * @param pageFunction Function to be evaluated in browser context
  85. * @param x1 First argument to pass to pageFunction
  86. * @returns Promise which resolves to the return value of pageFunction
  87. */
  88. $eval<R, X1>(
  89. selector: string,
  90. pageFunction: (element: Element, x1: UnwrapElementHandle<X1>) => R | Promise<R>,
  91. x1: X1,
  92. ): Promise<WrapElementHandle<R>>;
  93. /**
  94. * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
  95. * If there's no element matching `selector`, the method throws an error.
  96. *
  97. * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
  98. *
  99. * @param selector A selector to query for
  100. * @param pageFunction Function to be evaluated in browser context
  101. * @param x1 First argument to pass to pageFunction
  102. * @param x2 Second argument to pass to pageFunction
  103. * @returns Promise which resolves to the return value of pageFunction
  104. */
  105. $eval<R, X1, X2>(
  106. selector: string,
  107. pageFunction: (element: Element, x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
  108. x1: X1,
  109. x2: X2,
  110. ): Promise<WrapElementHandle<R>>;
  111. /**
  112. * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
  113. * If there's no element matching `selector`, the method throws an error.
  114. *
  115. * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
  116. *
  117. * @param selector A selector to query for
  118. * @param pageFunction Function to be evaluated in browser context
  119. * @param x1 First argument to pass to pageFunction
  120. * @param x2 Second argument to pass to pageFunction
  121. * @param x3 Third argument to pass to pageFunction
  122. * @returns Promise which resolves to the return value of pageFunction
  123. */
  124. $eval<R, X1, X2, X3>(
  125. selector: string,
  126. pageFunction: (
  127. element: Element,
  128. x1: UnwrapElementHandle<X1>,
  129. x2: UnwrapElementHandle<X2>,
  130. x3: UnwrapElementHandle<X3>,
  131. ) => R | Promise<R>,
  132. x1: X1,
  133. x2: X2,
  134. x3: X3,
  135. ): Promise<WrapElementHandle<R>>;
  136. /**
  137. * This method runs `document.querySelector` within the context and passes it as the first argument to `pageFunction`.
  138. * If there's no element matching `selector`, the method throws an error.
  139. *
  140. * If `pageFunction` returns a Promise, then `$eval` would wait for the promise to resolve and return its value.
  141. *
  142. * @param selector A selector to query for
  143. * @param pageFunction Function to be evaluated in browser context
  144. * @param args Arguments to pass to pageFunction
  145. * @returns Promise which resolves to the return value of pageFunction
  146. */
  147. $eval<R>(
  148. selector: string,
  149. pageFunction: (element: Element, ...args: any[]) => R | Promise<R>,
  150. ...args: SerializableOrJSHandle[]
  151. ): Promise<WrapElementHandle<R>>;
  152. /**
  153. * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
  154. * first argument to `pageFunction`.
  155. *
  156. * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
  157. *
  158. * @param selector A selector to query for
  159. * @param pageFunction Function to be evaluated in browser context
  160. * @returns Promise which resolves to the return value of pageFunction
  161. */
  162. $$eval<R>(selector: string, pageFunction: (elements: Element[]) => R | Promise<R>): Promise<WrapElementHandle<R>>;
  163. /**
  164. * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
  165. * first argument to `pageFunction`.
  166. *
  167. * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
  168. *
  169. * @param selector A selector to query for
  170. * @param pageFunction Function to be evaluated in browser context
  171. * @param x1 First argument to pass to pageFunction
  172. * @returns Promise which resolves to the return value of pageFunction
  173. */
  174. $$eval<R, X1>(
  175. selector: string,
  176. pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>) => R | Promise<R>,
  177. x1: X1,
  178. ): Promise<WrapElementHandle<R>>;
  179. /**
  180. * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
  181. * first argument to `pageFunction`.
  182. *
  183. * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
  184. *
  185. * @param selector A selector to query for
  186. * @param pageFunction Function to be evaluated in browser context
  187. * @param x1 First argument to pass to pageFunction
  188. * @param x2 Second argument to pass to pageFunction
  189. * @returns Promise which resolves to the return value of pageFunction
  190. */
  191. $$eval<R, X1, X2>(
  192. selector: string,
  193. pageFunction: (elements: Element[], x1: UnwrapElementHandle<X1>, x2: UnwrapElementHandle<X2>) => R | Promise<R>,
  194. x1: X1,
  195. x2: X2,
  196. ): Promise<WrapElementHandle<R>>;
  197. /**
  198. * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
  199. * first argument to `pageFunction`.
  200. *
  201. * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
  202. *
  203. * @param selector A selector to query for
  204. * @param pageFunction Function to be evaluated in browser context
  205. * @param x1 First argument to pass to pageFunction
  206. * @param x2 Second argument to pass to pageFunction
  207. * @param x3 Third argument to pass to pageFunction
  208. * @returns Promise which resolves to the return value of pageFunction
  209. */
  210. $$eval<R, X1, X2, X3>(
  211. selector: string,
  212. pageFunction: (
  213. elements: Element[],
  214. x1: UnwrapElementHandle<X1>,
  215. x2: UnwrapElementHandle<X2>,
  216. x3: UnwrapElementHandle<X3>,
  217. ) => R | Promise<R>,
  218. x1: X1,
  219. x2: X2,
  220. x3: X3,
  221. ): Promise<WrapElementHandle<R>>;
  222. /**
  223. * This method runs `Array.from(document.querySelectorAll(selector))` within the context and passes it as the
  224. * first argument to `pageFunction`.
  225. *
  226. * If `pageFunction` returns a Promise, then `$$eval` would wait for the promise to resolve and return its value.
  227. *
  228. * @param selector A selector to query for
  229. * @param pageFunction Function to be evaluated in browser context
  230. * @param args Arguments to pass to pageFunction
  231. * @returns Promise which resolves to the return value of pageFunction
  232. */
  233. $$eval<R>(
  234. selector: string,
  235. pageFunction: (elements: Element[], ...args: any[]) => R | Promise<R>,
  236. ...args: SerializableOrJSHandle[]
  237. ): Promise<WrapElementHandle<R>>;
  238. }
  239. export interface JSEvalable<A = any> {
  240. /**
  241. * Evaluates a function in the browser context.
  242. * If the function, passed to the frame.evaluate, returns a Promise, then frame.evaluate would wait for the promise to resolve and return its value.
  243. * If the function passed into frame.evaluate returns a non-Serializable value, then frame.evaluate resolves to undefined.
  244. * @param fn Function to be evaluated in browser context
  245. * @param args Arguments to pass to `fn`
  246. */
  247. evaluate<T extends EvaluateFn<A>>(
  248. pageFunction: T,
  249. ...args: SerializableOrJSHandle[]
  250. ): Promise<EvaluateFnReturnType<T> extends PromiseLike<infer U> ? U : EvaluateFnReturnType<T>>;
  251. /**
  252. * The only difference between `evaluate` and `evaluateHandle` is that `evaluateHandle` returns in-page object (`JSHandle`).
  253. * If the function, passed to the `evaluateHandle`, returns a `Promise`, then `evaluateHandle` would wait for the
  254. * promise to resolve and return its value.
  255. * The TypeScript definitions assume that `evaluateHandle` returns a `JSHandle`, but if you know it's going to return an
  256. * `ElementHandle`, pass it as the generic argument:
  257. * @param pageFunction - a function that is run within the page
  258. * @param args - arguments to be passed to the pageFunction
  259. */
  260. // tslint:disable-next-line no-unnecessary-generics (This generic is meant to be passed explicitly.) # https://github.com/Microsoft/dtslint/issues/76
  261. evaluateHandle<HandlerType extends JSHandle = JSHandle>(
  262. pageFunction: string | ((arg1: A, ...args: any[]) => any),
  263. ...args: SerializableOrJSHandle[]
  264. // tslint:disable-next-line no-unnecessary-generics (This generic is meant to be passed explicitly.) # https://github.com/Microsoft/dtslint/issues/76
  265. ): Promise<HandlerType>;
  266. }
  267. /** Keyboard provides an api for managing a virtual keyboard. */
  268. export interface Keyboard {
  269. /**
  270. * Dispatches a keydown event.
  271. * @param key Name of key to press, such as ArrowLeft.
  272. * @param options Specifies a input text event.
  273. */
  274. down(key: string, options?: { text?: string }): Promise<void>;
  275. /** Shortcut for `keyboard.down` and `keyboard.up`. */
  276. press(key: string, options?: { text?: string; delay?: number }): Promise<void>;
  277. /** Dispatches a `keypress` and `input` event. This does not send a `keydown` or keyup `event`. */
  278. sendCharacter(char: string): Promise<void>;
  279. /**
  280. * Sends a keydown, keypress/input, and keyup event for each character in the text.
  281. * @param text A text to type into a focused element.
  282. * @param options Specifies the typing options.
  283. */
  284. type(text: string, options?: { delay?: number }): Promise<void>;
  285. /**
  286. * Dispatches a keyup event.
  287. * @param key Name of key to release, such as ArrowLeft.
  288. */
  289. up(key: string): Promise<void>;
  290. }
  291. export interface MousePressOptions {
  292. /**
  293. * left, right, or middle.
  294. * @default left
  295. */
  296. button?: MouseButtons;
  297. /**
  298. * The number of clicks.
  299. * @default 1
  300. */
  301. clickCount?: number;
  302. }
  303. export interface MouseWheelOptions {
  304. deltaX?: number;
  305. deltaY?: number;
  306. }
  307. export interface MouseWheelOptions {
  308. /**
  309. * X delta in CSS pixels for mouse wheel event. Positive values emulate a scroll up and negative values a scroll down event.
  310. * @default 0
  311. */
  312. deltaX?: number;
  313. /**
  314. * Y delta in CSS pixels for mouse wheel event. Positive values emulate a scroll right and negative values a scroll left event.
  315. * @default 0
  316. */
  317. deltaY?: number;
  318. }
  319. export interface Mouse {
  320. /**
  321. * Shortcut for `mouse.move`, `mouse.down` and `mouse.up`.
  322. * @param x The x position.
  323. * @param y The y position.
  324. * @param options The click options.
  325. */
  326. click(x: number, y: number, options?: ClickOptions): Promise<void>;
  327. /**
  328. * Dispatches a `mousedown` event.
  329. * @param options The mouse press options.
  330. */
  331. down(options?: MousePressOptions): Promise<void>;
  332. /**
  333. * Dispatches a `mousemove` event.
  334. * @param x The x position.
  335. * @param y The y position.
  336. * @param options The mouse move options.
  337. */
  338. move(x: number, y: number, options?: { steps: number }): Promise<void>;
  339. /**
  340. * Dispatches a `mouseup` event.
  341. * @param options The mouse press options.
  342. */
  343. up(options?: MousePressOptions): Promise<void>;
  344. /**
  345. * Dispatches a `mousewheel` event.
  346. * @param options - Optional: `MouseWheelOptions`.
  347. *
  348. * @example
  349. * An example of zooming into an element:
  350. * ```js
  351. * await page.goto('https://mdn.mozillademos.org/en-US/docs/Web/API/Element/wheel_event$samples/Scaling_an_element_via_the_wheel?revision=1587366');
  352. *
  353. * const elem = await page.$('div');
  354. * const boundingBox = await elem.boundingBox();
  355. * await page.mouse.move(
  356. * boundingBox.x + boundingBox.width / 2,
  357. * boundingBox.y + boundingBox.height / 2
  358. * );
  359. *
  360. * await page.mouse.wheel({ deltaY: -100 })
  361. * ```
  362. */
  363. wheel(options?: MouseWheelOptions): Promise<void>;
  364. }
  365. export interface Touchscreen {
  366. /**
  367. * Dispatches a touchstart and touchend event.
  368. * @param x The x position.
  369. * @param y The y position.
  370. */
  371. tap(x: number, y: number): Promise<void>;
  372. }
  373. /**
  374. * You can use `tracing.start` and `tracing.stop` to create a trace file which can be opened in Chrome DevTools or timeline viewer.
  375. */
  376. export interface Tracing {
  377. start(options: TracingStartOptions): Promise<void>;
  378. stop(): Promise<Buffer>;
  379. }
  380. export interface TracingStartOptions {
  381. path?: string;
  382. screenshots?: boolean;
  383. categories?: string[];
  384. }
  385. export type DialogType = 'alert' | 'beforeunload' | 'confirm' | 'prompt';
  386. /** Dialog objects are dispatched by page via the 'dialog' event. */
  387. export interface Dialog {
  388. /**
  389. * Accepts the dialog.
  390. * @param promptText A text to enter in prompt. Does not cause any effects if the dialog's type is not prompt.
  391. */
  392. accept(promptText?: string): Promise<void>;
  393. /** If dialog is prompt, returns default prompt value. Otherwise, returns empty string. */
  394. defaultValue(): string;
  395. /** Dismiss the dialog */
  396. dismiss(): Promise<void>;
  397. /** Returns the message displayed in the dialog. */
  398. message(): string;
  399. /** The dialog type. Dialog's type, can be one of `alert`, `beforeunload`, `confirm` or `prompt`. */
  400. type(): DialogType;
  401. }
  402. export type ConsoleMessageType =
  403. | 'log'
  404. | 'debug'
  405. | 'info'
  406. | 'error'
  407. | 'warning'
  408. | 'dir'
  409. | 'dirxml'
  410. | 'table'
  411. | 'trace'
  412. | 'clear'
  413. | 'startGroup'
  414. | 'startGroupCollapsed'
  415. | 'endGroup'
  416. | 'assert'
  417. | 'profile'
  418. | 'profileEnd'
  419. | 'count'
  420. | 'timeEnd';
  421. export interface ConsoleMessageLocation {
  422. /**
  423. * URL of the resource if known.
  424. */
  425. url?: string;
  426. /**
  427. * Line number in the resource if known
  428. */
  429. lineNumber?: number;
  430. /**
  431. * Column number in the resource if known.
  432. */
  433. columnNumber?: number;
  434. }
  435. /** ConsoleMessage objects are dispatched by page via the 'console' event. */
  436. export interface ConsoleMessage {
  437. /** The message arguments. */
  438. args(): JSHandle[];
  439. /** The location the message originated from */
  440. location(): ConsoleMessageLocation;
  441. /** The message text. */
  442. text(): string;
  443. type(): ConsoleMessageType;
  444. }
  445. export interface AuthOptions {
  446. username: string;
  447. password: string;
  448. }
  449. export type MouseButtons = 'left' | 'right' | 'middle';
  450. export interface ClickOptions {
  451. /** @default MouseButtons.Left */
  452. button?: MouseButtons;
  453. /** @default 1 */
  454. clickCount?: number;
  455. /**
  456. * Time to wait between mousedown and mouseup in milliseconds.
  457. * @default 0
  458. */
  459. delay?: number;
  460. }
  461. export type SameSiteSetting = 'Strict' | 'Lax';
  462. /** Represents a browser cookie. */
  463. export interface Cookie {
  464. /** The cookie name. */
  465. name: string;
  466. /** The cookie value. */
  467. value: string;
  468. /** The cookie domain. */
  469. domain: string;
  470. /** The cookie path. */
  471. path: string;
  472. /** The cookie Unix expiration time in seconds. */
  473. expires: number;
  474. /** The cookie size */
  475. size: number;
  476. /** The cookie http only flag. */
  477. httpOnly: boolean;
  478. /** The session cookie flag. */
  479. session: boolean;
  480. /** The cookie secure flag. */
  481. secure: boolean;
  482. /** The cookie same site definition. */
  483. sameSite: SameSiteSetting;
  484. }
  485. export interface DeleteCookie {
  486. /** The cookie name. */
  487. name: string;
  488. url?: string;
  489. domain?: string;
  490. path?: string;
  491. }
  492. export interface SetCookie {
  493. /** The cookie name. */
  494. name: string;
  495. /** The cookie value. */
  496. value: string;
  497. /** The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie. */
  498. url?: string;
  499. /** The cookie domain. */
  500. domain?: string;
  501. /** The cookie path. */
  502. path?: string;
  503. /** The cookie Unix expiration time in seconds. */
  504. expires?: number;
  505. /** The cookie http only flag. */
  506. httpOnly?: boolean;
  507. /** The session cookie flag. */
  508. session?: boolean;
  509. /** The cookie secure flag. */
  510. secure?: boolean;
  511. /** The cookie same site definition. */
  512. sameSite?: SameSiteSetting;
  513. }
  514. export interface Viewport {
  515. /** The page width in pixels. */
  516. width: number;
  517. /** The page height in pixels. */
  518. height: number;
  519. /**
  520. * Specify device scale factor (can be thought of as dpr).
  521. * @default 1
  522. */
  523. deviceScaleFactor?: number;
  524. /**
  525. * Whether the `meta viewport` tag is taken into account.
  526. * @default false
  527. */
  528. isMobile?: boolean;
  529. /**
  530. * Specifies if viewport supports touch events.
  531. * @default false
  532. */
  533. hasTouch?: boolean;
  534. /**
  535. * Specifies if viewport is in landscape mode.
  536. * @default false
  537. */
  538. isLandscape?: boolean;
  539. }
  540. /** Page emulation options. */
  541. export interface EmulateOptions {
  542. /** The viewport emulation options. */
  543. viewport: Viewport;
  544. /** The emulated user-agent. */
  545. userAgent: string;
  546. }
  547. export type EvaluateFn<T = any> = string | ((arg1: T, ...args: any[]) => any);
  548. export type EvaluateFnReturnType<T extends EvaluateFn> = T extends (...args: any[]) => infer R ? R : unknown;
  549. export type LoadEvent = 'load' | 'domcontentloaded' | 'networkidle0' | 'networkidle2';
  550. export interface Timeoutable {
  551. /**
  552. * Maximum navigation time in milliseconds, pass 0 to disable timeout.
  553. * @default 30000
  554. */
  555. timeout?: number;
  556. }
  557. /** The navigation options. */
  558. export interface NavigationOptions extends Timeoutable {
  559. /**
  560. * When to consider navigation succeeded.
  561. * @default load Navigation is consider when the `load` event is fired.
  562. */
  563. waitUntil?: LoadEvent | LoadEvent[];
  564. }
  565. /**
  566. * Navigation options for `page.goto`.
  567. */
  568. export interface DirectNavigationOptions extends NavigationOptions {
  569. /**
  570. * Referer header value.
  571. * If provided it will take preference over the referer header value set by
  572. * [page.setExtraHTTPHeaders()](#pagesetextrahttpheadersheaders).
  573. */
  574. referer?: string;
  575. }
  576. /** Accepts values labeled with units. If number, treat as pixels. */
  577. export type LayoutDimension = string | number;
  578. export type PDFFormat = 'Letter' | 'Legal' | 'Tabloid' | 'Ledger' | 'A0' | 'A1' | 'A2' | 'A3' | 'A4' | 'A5' | 'A6';
  579. export interface PDFOptions {
  580. /**
  581. * The file path to save the PDF to.
  582. * If `path` is a relative path, then it is resolved relative to current working directory.
  583. * If no path is provided, the PDF won't be saved to the disk.
  584. */
  585. path?: string;
  586. /**
  587. * Scale of the webpage rendering.
  588. * @default 1
  589. */
  590. scale?: number;
  591. /**
  592. * Display header and footer.
  593. * @default false
  594. */
  595. displayHeaderFooter?: boolean;
  596. /**
  597. * HTML template for the print header. Should be valid HTML markup with following classes used to inject printing values into them:
  598. * - `date` formatted print date
  599. * - `title` document title
  600. * - `url` document location
  601. * - `pageNumber` current page number
  602. * - `totalPages` total pages in the document
  603. */
  604. headerTemplate?: string;
  605. /**
  606. * HTML template for the print footer. Should be valid HTML markup with following classes used to inject printing values into them:
  607. * - `date` formatted print date
  608. * - `title` document title
  609. * - `url` document location
  610. * - `pageNumber` current page number
  611. * - `totalPages` total pages in the document
  612. */
  613. footerTemplate?: string;
  614. /**
  615. * Print background graphics.
  616. * @default false
  617. */
  618. printBackground?: boolean;
  619. /**
  620. * Paper orientation.
  621. * @default false
  622. */
  623. landscape?: boolean;
  624. /**
  625. * Paper ranges to print, e.g., '1-5, 8, 11-13'.
  626. * @default '' which means print all pages.
  627. */
  628. pageRanges?: string;
  629. /**
  630. * Paper format. If set, takes priority over width or height options.
  631. * @default 'Letter'
  632. */
  633. format?: PDFFormat;
  634. /** Paper width. */
  635. width?: LayoutDimension;
  636. /** Paper height. */
  637. height?: LayoutDimension;
  638. /** Paper margins, defaults to none. */
  639. margin?: {
  640. /** Top margin. */
  641. top?: LayoutDimension;
  642. /** Right margin. */
  643. right?: LayoutDimension;
  644. /** Bottom margin. */
  645. bottom?: LayoutDimension;
  646. /** Left margin. */
  647. left?: LayoutDimension;
  648. };
  649. /**
  650. * Give any CSS @page size declared in the page priority over what is declared in width and
  651. * height or format options.
  652. * @default false which will scale the content to fit the paper size.
  653. */
  654. preferCSSPageSize?: boolean;
  655. }
  656. /** Defines the screenshot options. */
  657. export interface ScreenshotOptions {
  658. /**
  659. * The file path to save the image to. The screenshot type will be inferred from file extension.
  660. * If `path` is a relative path, then it is resolved relative to current working directory.
  661. * If no path is provided, the image won't be saved to the disk.
  662. */
  663. path?: string;
  664. /**
  665. * The screenshot type.
  666. * @default png
  667. */
  668. type?: 'jpeg' | 'png';
  669. /** The quality of the image, between 0-100. Not applicable to png images. */
  670. quality?: number;
  671. /**
  672. * When true, takes a screenshot of the full scrollable page.
  673. * @default false
  674. */
  675. fullPage?: boolean;
  676. /**
  677. * An object which specifies clipping region of the page.
  678. */
  679. clip?: BoundingBox;
  680. /**
  681. * Hides default white background and allows capturing screenshots with transparency.
  682. * @default false
  683. */
  684. omitBackground?: boolean;
  685. /**
  686. * The encoding of the image, can be either base64 or binary.
  687. * @default binary
  688. */
  689. encoding?: 'base64' | 'binary';
  690. }
  691. export interface BinaryScreenShotOptions extends ScreenshotOptions {
  692. encoding?: 'binary';
  693. }
  694. export interface Base64ScreenShotOptions extends ScreenshotOptions {
  695. encoding: 'base64';
  696. }
  697. /** Options for `addStyleTag` */
  698. export interface StyleTagOptions {
  699. /** Url of the <link> tag. */
  700. url?: string;
  701. /** Path to the CSS file to be injected into frame. If `path` is a relative path, then it is resolved relative to current working directory. */
  702. path?: string;
  703. /** Raw CSS content to be injected into frame. */
  704. content?: string;
  705. }
  706. /** Options for `addScriptTag` */
  707. export interface ScriptTagOptions {
  708. /** Url of a script to be added. */
  709. url?: string;
  710. /** Path to the JavaScript file to be injected into frame. If `path` is a relative path, then it is resolved relative to current working directory. */
  711. path?: string;
  712. /** Raw JavaScript content to be injected into frame. */
  713. content?: string;
  714. /** Script type. Use 'module' in order to load a Javascript ES6 module. */
  715. type?: string;
  716. }
  717. export interface PageFnOptions extends Timeoutable {
  718. polling?: 'raf' | 'mutation' | number;
  719. }
  720. export interface BoundingBox {
  721. /** The x-coordinate of top-left corner. */
  722. x: number;
  723. /** The y-coordinate of top-left corner. */
  724. y: number;
  725. /** The width. */
  726. width: number;
  727. /** The height. */
  728. height: number;
  729. }
  730. export interface BoxModel {
  731. /** Content box, represented as an array of {x, y} points. */
  732. content: Box[];
  733. /** Padding box, represented as an array of {x, y} points. */
  734. padding: Box[];
  735. /** Border box, represented as an array of {x, y} points. */
  736. border: Box[];
  737. /** Margin box, represented as an array of {x, y} points. */
  738. margin: Box[];
  739. width: number;
  740. height: number;
  741. }
  742. export interface Box {
  743. x: number;
  744. y: number;
  745. }
  746. /**
  747. * The Worker class represents a WebWorker.
  748. * The events workercreated and workerdestroyed are emitted on the page object to signal the worker lifecycle.
  749. */
  750. export interface Worker extends JSEvalable {
  751. executionContext(): Promise<ExecutionContext>;
  752. url(): string;
  753. }
  754. /**
  755. * Represents an in-page DOM element. ElementHandles can be created with the page.$ method.
  756. */
  757. export interface ElementHandle<E extends Element = Element> extends JSHandle<E>, Evalable {
  758. /**
  759. * The method runs element.querySelector within the page.
  760. * If no element matches the selector, the return value resolve to null.
  761. * @param selector A selector to query element for
  762. * @since 0.13.0
  763. */
  764. $(selector: string): Promise<ElementHandle | null>;
  765. /**
  766. * The method runs element.querySelectorAll within the page.
  767. * If no elements match the selector, the return value resolve to [].
  768. * @param selector A selector to query element for
  769. * @since 0.13.0
  770. */
  771. $$(selector: string): Promise<ElementHandle[]>;
  772. /**
  773. * @param selector XPath expression to evaluate.
  774. */
  775. $x(expression: string): Promise<ElementHandle[]>;
  776. /**
  777. * This method returns the value resolve to the bounding box of the element (relative to the main frame), or null if the element is not visible.
  778. */
  779. boundingBox(): Promise<BoundingBox | null>;
  780. /**
  781. * This method returns boxes of the element, or null if the element is not visible.
  782. * Boxes are represented as an array of points; each Point is an object {x, y}. Box points are sorted clock-wise.
  783. */
  784. boxModel(): Promise<BoxModel | null>;
  785. /**
  786. * This method scrolls element into view if needed, and then uses page.mouse to click in the center of the element.
  787. * If the element is detached from DOM, the method throws an error.
  788. * @param options Specifies the options.
  789. * @since 0.9.0
  790. */
  791. click(options?: ClickOptions): Promise<void>;
  792. /**
  793. * @returns Resolves to the content frame for element handles referencing iframe nodes, or null otherwise.
  794. * @since 1.2.0
  795. */
  796. contentFrame(): Promise<Frame | null>;
  797. /**
  798. * Calls focus on the element.
  799. */
  800. focus(): Promise<void>;
  801. /**
  802. * This method scrolls element into view if needed, and then uses page.mouse to hover over the center of the element.
  803. * If the element is detached from DOM, the method throws an error.
  804. */
  805. hover(): Promise<void>;
  806. /**
  807. * Resolves to true if the element is visible in the current viewport.
  808. */
  809. isIntersectingViewport(): Promise<boolean>;
  810. /**
  811. * Focuses the element, and then uses keyboard.down and keyboard.up.
  812. * @param key Name of key to press, such as ArrowLeft. See USKeyboardLayout for a list of all key names.
  813. * @param options The text and delay options.
  814. */
  815. press(key: string, options?: { text?: string; delay?: number }): Promise<void>;
  816. /**
  817. * This method scrolls element into view if needed, and then uses page.screenshot to take a screenshot of the element.
  818. * If the element is detached from DOM, the method throws an error.
  819. * @param options Same options as in page.screenshot.
  820. */
  821. screenshot(options?: Base64ScreenShotOptions): Promise<string>;
  822. screenshot(options?: BinaryScreenShotOptions): Promise<Buffer>;
  823. screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
  824. /**
  825. * Triggers a change and input event once all the provided options have been selected. If there's no <select> element
  826. * matching selector, the method throws an error.
  827. * @param values Values of options to select. If the <select> has the multiple attribute, all values are considered, otherwise only the first one is taken into account.
  828. * @returns An array of option values that have been successfully selected.
  829. * @since 1.12.0
  830. */
  831. select(...values: string[]): Promise<string[]>;
  832. /**
  833. * This method scrolls element into view if needed, and then uses touchscreen.tap to tap in the center of the element.
  834. * If the element is detached from DOM, the method throws an error.
  835. */
  836. tap(): Promise<void>;
  837. toString(): string;
  838. /**
  839. * Focuses the element, and then sends a keydown, keypress/input, and keyup event for each character in the text.
  840. * @param text A text to type into a focused element.
  841. * @param options The typing options.
  842. */
  843. type(text: string, options?: { delay: number }): Promise<void>;
  844. /**
  845. * This method expects elementHandle to point to an input element.
  846. * @param filePaths Sets the value of the file input these paths. If some of the filePaths are relative paths, then they are resolved relative to current working directory.
  847. */
  848. uploadFile(...filePaths: string[]): Promise<void>;
  849. }
  850. /** The class represents a context for JavaScript execution. */
  851. export interface ExecutionContext extends JSEvalable {
  852. queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;
  853. }
  854. /** JSHandle represents an in-page JavaScript object. */
  855. export interface JSHandle<T = any> extends JSEvalable<T> {
  856. /**
  857. * Returns a ElementHandle
  858. */
  859. asElement(): ElementHandle | null;
  860. /**
  861. * Stops referencing the element handle.
  862. */
  863. dispose(): Promise<void>;
  864. /**
  865. * Gets the execution context.
  866. */
  867. executionContext(): ExecutionContext;
  868. /**
  869. * Returns a map with property names as keys and JSHandle instances for the property values.
  870. */
  871. getProperties(): Promise<Map<string, JSHandle>>;
  872. /**
  873. * Fetches a single property from the objectHandle.
  874. * @param propertyName The property to get.
  875. */
  876. getProperty(propertyName: string): Promise<JSHandle>;
  877. /**
  878. * Returns a JSON representation of the object.
  879. * The JSON is generated by running JSON.stringify on the object in page and consequent JSON.parse in puppeteer.
  880. * @throws The method will throw if the referenced object is not stringifiable.
  881. */
  882. jsonValue(): Promise<unknown>;
  883. }
  884. export interface Metrics {
  885. /** The timestamp when the metrics sample was taken. */
  886. Timestamp: number;
  887. /** Number of documents in the page. */
  888. Documents: number;
  889. /** Number of frames in the page. */
  890. Frames: number;
  891. /** Number of events in the page. */
  892. JSEventListeners: number;
  893. /** Number of DOM nodes in the page. */
  894. Nodes: number;
  895. /** Total number of full or partial page layout. */
  896. LayoutCount: number;
  897. /** Total number of page style recalculations. */
  898. RecalcStyleCount: number;
  899. /** Combined durations of all page layouts. */
  900. LayoutDuration: number;
  901. /** Combined duration of all page style recalculations. */
  902. RecalcStyleDuration: number;
  903. /** Combined duration of JavaScript execution. */
  904. ScriptDuration: number;
  905. /** Combined duration of all tasks performed by the browser. */
  906. TaskDuration: number;
  907. /** Used JavaScript heap size. */
  908. JSHeapUsedSize: number;
  909. /** Total JavaScript heap size. */
  910. JSHeapTotalSize: number;
  911. }
  912. export type Headers = Record<string, string>;
  913. export type HttpMethod = 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE' | 'OPTIONS';
  914. export type ResourceType =
  915. | 'document'
  916. | 'stylesheet'
  917. | 'image'
  918. | 'media'
  919. | 'font'
  920. | 'script'
  921. | 'texttrack'
  922. | 'xhr'
  923. | 'fetch'
  924. | 'eventsource'
  925. | 'websocket'
  926. | 'manifest'
  927. | 'other';
  928. export type ErrorCode =
  929. | 'aborted'
  930. | 'accessdenied'
  931. | 'addressunreachable'
  932. | 'blockedbyclient'
  933. | 'blockedbyresponse'
  934. | 'connectionaborted'
  935. | 'connectionclosed'
  936. | 'connectionfailed'
  937. | 'connectionrefused'
  938. | 'connectionreset'
  939. | 'internetdisconnected'
  940. | 'namenotresolved'
  941. | 'timedout'
  942. | 'failed';
  943. export interface Overrides {
  944. url?: string;
  945. method?: HttpMethod;
  946. postData?: string;
  947. headers?: Headers;
  948. }
  949. /** Represents a page request. */
  950. export interface Request {
  951. /**
  952. * Aborts request.
  953. * To use this, request interception should be enabled with `page.setRequestInterception`.
  954. * @throws An exception is immediately thrown if the request interception is not enabled.
  955. */
  956. abort(errorCode?: ErrorCode): Promise<void>;
  957. /**
  958. * Continues request with optional request overrides.
  959. * To use this, request interception should be enabled with `page.setRequestInterception`.
  960. * @throws An exception is immediately thrown if the request interception is not enabled.
  961. */
  962. continue(overrides?: Overrides): Promise<void>;
  963. /**
  964. * @returns An object if the request failed, null otherwise.
  965. */
  966. failure(): { errorText: string } | null;
  967. /**
  968. * @returns The `Frame` object that initiated the request, or `null` if navigating to error pages
  969. */
  970. frame(): Frame | null;
  971. /**
  972. * An object with HTTP headers associated with the request.
  973. * All header names are lower-case.
  974. */
  975. headers(): Headers;
  976. /** Whether this request is driving frame's navigation. */
  977. isNavigationRequest(): boolean;
  978. /** Returns the request's method (GET, POST, etc.) */
  979. method(): HttpMethod;
  980. /** Contains the request's post body, if any. */
  981. postData(): string | undefined;
  982. /**
  983. * A `redirectChain` is a chain of requests initiated to fetch a resource.
  984. *
  985. * - If there are no redirects and the request was successful, the chain will be empty.
  986. * - If a server responds with at least a single redirect, then the chain will contain all the requests that were redirected.
  987. *
  988. * `redirectChain` is shared between all the requests of the same chain.
  989. *
  990. * @since 1.2.0
  991. */
  992. redirectChain(): Request[];
  993. /** Contains the request's resource type as it was perceived by the rendering engine. */
  994. resourceType(): ResourceType;
  995. /**
  996. * Fulfills request with given response.
  997. * To use this, request interception should be enabled with `page.setRequestInterception`.
  998. * @throws An exception is immediately thrown if the request interception is not enabled.
  999. * @param response The response options that will fulfill this request.
  1000. */
  1001. respond(response: RespondOptions): Promise<void>;
  1002. /** A matching `Response` object, or `null` if the response has not been received yet. */
  1003. response(): Response | null;
  1004. /** Contains the URL of the request. */
  1005. url(): string;
  1006. }
  1007. /** Options for `Request.respond` method */
  1008. export interface RespondOptions {
  1009. /**
  1010. * Specifies the response status code.
  1011. * @default 200
  1012. */
  1013. status?: number;
  1014. /** Specifies the response headers. */
  1015. headers?: Headers;
  1016. /** Specifies the Content-Type response header. */
  1017. contentType?: string;
  1018. /** Specifies the response body. */
  1019. body?: Buffer | string;
  1020. }
  1021. export interface RemoteInfo {
  1022. /** the IP address of the remote server */
  1023. ip: string;
  1024. /** the port used to connect to the remote server */
  1025. port: number;
  1026. }
  1027. export interface SecurityDetails {
  1028. /** A string with the name of issuer of the certificate. (e.g. "Let's Encrypt Authority X3"). */
  1029. issuer(): string;
  1030. /** String with the security protocol (e.g. TLS 1.2). */
  1031. protocol(): string;
  1032. /** Name of the subject to which the certificate was issued to (e.g. "www.example.com"). */
  1033. subjectName(): string;
  1034. /** Timestamp stating the start of validity of the certificate. */
  1035. validFrom(): number;
  1036. /** Timestamp stating the end of validity of the certificate. */
  1037. validTo(): number;
  1038. }
  1039. /** Response class represents responses which are received by page. */
  1040. export interface Response {
  1041. /** Promise which resolves to a buffer with response body. */
  1042. buffer(): Promise<Buffer>;
  1043. /** A Frame that initiated this response, or null if navigating to error pages. */
  1044. frame(): Frame | null;
  1045. /** True if the response was served from either the browser's disk cache or memory cache. */
  1046. fromCache(): boolean;
  1047. /** True if the response was served by a service worker. */
  1048. fromServiceWorker(): boolean;
  1049. /** An object with HTTP headers associated with the response. All header names are lower-case. */
  1050. headers(): Headers;
  1051. /**
  1052. * Promise which resolves to a JSON representation of response body.
  1053. * @throws This method will throw if the response body is not parsable via `JSON.parse`.
  1054. */
  1055. json(): Promise<unknown>;
  1056. /** Contains a boolean stating whether the response was successful (status in the range 200-299) or not. */
  1057. ok(): boolean;
  1058. /** Returns remote connection info */
  1059. remoteAddress(): RemoteInfo;
  1060. /** Returns an object with security details associated with the response. */
  1061. securityDetails(): SecurityDetails | null;
  1062. /** A matching Request object. */
  1063. request(): Request;
  1064. /** Contains the status code of the response (e.g., 200 for a success). */
  1065. status(): number;
  1066. /** Contains the status text of the response (e.g. usually an "OK" for a success). */
  1067. statusText(): string;
  1068. /** Promise which resolves to a text representation of response body. */
  1069. text(): Promise<string>;
  1070. /** Contains the URL of the response. */
  1071. url(): string;
  1072. }
  1073. export interface WaitForSelectorOptions extends Timeoutable {
  1074. /**
  1075. * Wait for element to be present in DOM and to be visible,
  1076. * i.e. to not have display: none or visibility: hidden CSS properties.
  1077. * @default false
  1078. */
  1079. visible?: boolean;
  1080. /**
  1081. * Wait for element to not be found in the DOM or to be hidden,
  1082. * i.e. have display: none or visibility: hidden CSS properties.
  1083. * @default false
  1084. */
  1085. hidden?: boolean;
  1086. }
  1087. export interface WaitForSelectorOptionsHidden extends WaitForSelectorOptions {
  1088. hidden: true;
  1089. }
  1090. export interface FrameBase extends Evalable, JSEvalable {
  1091. /**
  1092. * The method queries frame for the selector.
  1093. * If there's no such element within the frame, the method will resolve to null.
  1094. */
  1095. $(selector: string): Promise<ElementHandle | null>;
  1096. /**
  1097. * The method runs document.querySelectorAll within the frame.
  1098. * If no elements match the selector, the return value resolve to [].
  1099. */
  1100. $$(selector: string): Promise<ElementHandle[]>;
  1101. /**
  1102. * The method evaluates the XPath expression.
  1103. * @param expression XPath expression to evaluate.
  1104. */
  1105. $x(expression: string): Promise<ElementHandle[]>;
  1106. /** Adds a `<script>` tag into the page with the desired url or content. */
  1107. addScriptTag(options: ScriptTagOptions): Promise<void>;
  1108. /** Adds a `<link rel="stylesheet">` tag into the page with the desired url or a `<style type="text/css">` tag with the content. */
  1109. addStyleTag(options: StyleTagOptions): Promise<void>;
  1110. /**
  1111. * This method fetches an element with selector, scrolls it into view if needed, and
  1112. * then uses `page.mouse` to click in the center of the element. If there's no element
  1113. * matching selector, the method throws an error.
  1114. * @param selector A selector to search for element to click. If there are multiple elements satisfying the selector, the first will be clicked.
  1115. * @param options Specifies the click options.
  1116. */
  1117. click(selector: string, options?: ClickOptions): Promise<void>;
  1118. /** Gets the full HTML contents of the page, including the doctype. */
  1119. content(): Promise<string>;
  1120. /**
  1121. * Navigates to a URL.
  1122. * @param url URL to navigate page to. The url should include scheme, e.g. `https://`
  1123. * @param options The navigation parameters.
  1124. */
  1125. goto(url: string, options?: DirectNavigationOptions): Promise<Response | null>;
  1126. /** This method fetches an element with selector and focuses it. */
  1127. focus(selector: string): Promise<void>;
  1128. /**
  1129. * This method fetches an element with `selector`, scrolls it into view if needed,
  1130. * and then uses page.mouse to hover over the center of the element. If there's no
  1131. * element matching `selector`, the method throws an error.
  1132. * @param selector A selector to search for element to hover. If there are multiple elements satisfying the selector, the first will be hovered.
  1133. */
  1134. hover(selector: string): Promise<void>;
  1135. /**
  1136. * Triggers a `change` and `input` event once all the provided options have been selected.
  1137. * If there's no `<select>` element matching selector, the method throws an error.
  1138. * @param selector A selector to query page for.
  1139. * @param values Values of options to select. If the `<select>` has the `multiple` attribute,
  1140. * all values are considered, otherwise only the first one is taken into account.
  1141. */
  1142. select(selector: string, ...values: string[]): Promise<string[]>;
  1143. /**
  1144. * Sets the page content.
  1145. * @param html HTML markup to assign to the page.
  1146. * @param options The navigation parameters.
  1147. */
  1148. setContent(html: string, options?: NavigationOptions): Promise<void>;
  1149. /**
  1150. * This method fetches an element with `selector`, scrolls it into view if needed,
  1151. * and then uses page.touchscreen to tap in the center of the element.
  1152. * @param selector A `selector` to search for element to tap. If there are multiple elements
  1153. * satisfying the selector, the first will be tapped.
  1154. */
  1155. tap(selector: string): Promise<void>;
  1156. /** Returns page's title. */
  1157. title(): Promise<string>;
  1158. /**
  1159. * Sends a `keydown`, `keypress/input`, and `keyup` event for each character in the text.
  1160. * @param selector A selector of an element to type into. If there are multiple elements satisfying the selector, the first will be used.
  1161. * @param text: A text to type into a focused element.
  1162. * @param options: The typing parameters.
  1163. */
  1164. type(selector: string, text: string, options?: { delay: number }): Promise<void>;
  1165. /** Returns frame's url. */
  1166. url(): string;
  1167. /**
  1168. * @remarks
  1169. *
  1170. * This method behaves differently depending on the first parameter. If it's a
  1171. * `string`, it will be treated as a `selector` or `xpath` (if the string
  1172. * starts with `//`). This method then is a shortcut for
  1173. * {@link Frame.waitForSelector} or {@link Frame.waitForXPath}.
  1174. *
  1175. * If the first argument is a function this method is a shortcut for
  1176. * {@link Frame.waitForFunction}.
  1177. *
  1178. * If the first argument is a `number`, it's treated as a timeout in
  1179. * milliseconds and the method returns a promise which resolves after the
  1180. * timeout.
  1181. *
  1182. * @param selectorOrFunctionOrTimeout - a selector, predicate or timeout to
  1183. * wait for.
  1184. * @param options - optional waiting parameters.
  1185. * @param args - arguments to pass to `pageFunction`.
  1186. *
  1187. * @deprecated Don't use this method directly. Instead use the more explicit
  1188. * methods available: {@link Frame.waitForSelector},
  1189. * {@link Frame.waitForXPath}, {@link Frame.waitForFunction} or
  1190. * {@link Frame.waitForTimeout}.
  1191. */
  1192. waitFor(duration: number): Promise<void>;
  1193. waitFor(selector: string, options: WaitForSelectorOptionsHidden): Promise<ElementHandle | null>;
  1194. waitFor(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
  1195. waitFor(
  1196. selector: EvaluateFn,
  1197. options?: WaitForSelectorOptions,
  1198. ...args: SerializableOrJSHandle[]
  1199. ): Promise<JSHandle>;
  1200. /**
  1201. * Allows waiting for various conditions.
  1202. */
  1203. waitForFunction(fn: EvaluateFn, options?: PageFnOptions, ...args: SerializableOrJSHandle[]): Promise<JSHandle>;
  1204. /**
  1205. * Wait for the page navigation occur.
  1206. * @param options The navigation parameters.
  1207. */
  1208. waitForNavigation(options?: NavigationOptions): Promise<Response>;
  1209. waitForSelector(selector: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
  1210. waitForSelector(selector: string, options?: WaitForSelectorOptionsHidden): Promise<ElementHandle | null>;
  1211. /**
  1212. * Causes your script to wait for the given number of milliseconds.
  1213. *
  1214. * @remarks
  1215. * It's generally recommended to not wait for a number of seconds, but instead
  1216. * use {@link Frame.waitForSelector}, {@link Frame.waitForXPath} or
  1217. * {@link Frame.waitForFunction} to wait for exactly the conditions you want.
  1218. *
  1219. * @example
  1220. *
  1221. * Wait for 1 second:
  1222. *
  1223. * ```
  1224. * await frame.waitForTimeout(1000);
  1225. * ```
  1226. *
  1227. * @param milliseconds - the number of milliseconds to wait.
  1228. */
  1229. waitForTimeout(milliseconds: number): Promise<void>;
  1230. waitForXPath(xpath: string, options?: WaitForSelectorOptions): Promise<ElementHandle>;
  1231. }
  1232. export interface Frame extends FrameBase {
  1233. childFrames(): Frame[];
  1234. /** Execution context associated with this frame. */
  1235. executionContext(): Promise<ExecutionContext>;
  1236. /** Returns `true` if the frame has been detached, or `false` otherwise. */
  1237. isDetached(): boolean;
  1238. /** Returns frame's name attribute as specified in the tag. */
  1239. name(): string;
  1240. /** Returns parent frame, if any. Detached frames and main frames return null. */
  1241. parentFrame(): Frame | null;
  1242. }
  1243. export interface PageEventObj {
  1244. /** Emitted when the page closes. */
  1245. close: undefined;
  1246. /**
  1247. * Emitted when JavaScript within the page calls one of console API methods, e.g. console.log or console.dir.
  1248. * Also emitted if the page throws an error or a warning.
  1249. */
  1250. console: ConsoleMessage;
  1251. /**
  1252. * Emitted when a JavaScript dialog appears, such as alert, prompt, confirm or beforeunload.
  1253. * Puppeteer can respond to the dialog via Dialog's accept or dismiss methods.
  1254. */
  1255. dialog: Dialog;
  1256. /**
  1257. * Emitted when the initial HTML document has been completely loaded and parsed,
  1258. * without waiting for stylesheets, images, and subframes to finish loading.
  1259. */
  1260. domcontentloaded: never;
  1261. /** Emitted when the page crashes. */
  1262. error: Error;
  1263. /** Emitted when a frame is attached. */
  1264. frameattached: Frame;
  1265. /** Emitted when a frame is detached. */
  1266. framedetached: Frame;
  1267. /** Emitted when a frame is navigated to a new url. */
  1268. framenavigated: Frame;
  1269. /** Emitted when the JavaScript load event is dispatched. */
  1270. load: undefined;
  1271. /**
  1272. * Emitted when the JavaScript code makes a call to `console.timeStamp`.
  1273. * For the list of metrics see `page.metrics`.
  1274. */
  1275. metrics: { title: string; metrics: Metrics };
  1276. /** Emitted when an uncaught exception happens within the page. */
  1277. pageerror: Error;
  1278. /** Emitted when the page opens a new tab or window. */
  1279. popup: Page;
  1280. /**
  1281. * Emitted when a page issues a request. The request object is read-only.
  1282. * In order to intercept and mutate requests, see page.setRequestInterceptionEnabled.
  1283. */
  1284. request: Request;
  1285. /** Emitted when a request fails, for example by timing out. */
  1286. requestfailed: Request;
  1287. /** Emitted when a request finishes successfully. */
  1288. requestfinished: Request;
  1289. /** Emitted when a response is received. */
  1290. response: Response;
  1291. /** Emitted when a dedicated WebWorker is spawned by the page. */
  1292. workercreated: Worker;
  1293. /** Emitted when a dedicated WebWorker is terminated. */
  1294. workerdestroyed: Worker;
  1295. }
  1296. export interface PageCloseOptions {
  1297. /**
  1298. * Whether to run the before unload page handlers.
  1299. * @default false
  1300. */
  1301. runBeforeUnload?: boolean;
  1302. }
  1303. export interface GeoOptions {
  1304. /**
  1305. * Latitude between -90 and 90.
  1306. */
  1307. latitude: number;
  1308. /**
  1309. * Longitude between -180 and 180.
  1310. */
  1311. longitude: number;
  1312. /**
  1313. * Non-negative accuracy value.
  1314. */
  1315. accuracy?: number;
  1316. }
  1317. export type MediaType = 'screen' | 'print';
  1318. export interface AXNode {
  1319. /**
  1320. * The role.
  1321. */
  1322. role: string;
  1323. /**
  1324. * A human readable name for the node.
  1325. */
  1326. name: string;
  1327. /**
  1328. * The current value of the node.
  1329. */
  1330. value: string | number;
  1331. /**
  1332. * An additional human readable description of the node.
  1333. */
  1334. description: string;
  1335. /**
  1336. * Keyboard shortcuts associated with this node.
  1337. */
  1338. keyshortcuts: string;
  1339. /**
  1340. * A human readable alternative to the role.
  1341. */
  1342. roledescription: string;
  1343. /**
  1344. * A description of the current value.
  1345. */
  1346. valuetext: string;
  1347. /**
  1348. * Whether the node is disabled.
  1349. */
  1350. disabled: boolean;
  1351. /**
  1352. * Whether the node is expanded or collapsed.
  1353. */
  1354. expanded: boolean;
  1355. /**
  1356. * Whether the node is focused.
  1357. */
  1358. focused: boolean;
  1359. /**
  1360. * Whether the node is modal.
  1361. */
  1362. modal: boolean;
  1363. /**
  1364. * Whether the node text input supports multiline.
  1365. */
  1366. multiline: boolean;
  1367. /**
  1368. * Whether more than one child can be selected.
  1369. */
  1370. multiselectable: boolean;
  1371. /**
  1372. * Whether the node is read only.
  1373. */
  1374. readonly: boolean;
  1375. /**
  1376. * Whether the node is required.
  1377. */
  1378. required: boolean;
  1379. /**
  1380. * Whether the node is selected in its parent node.
  1381. */
  1382. selected: boolean;
  1383. /**
  1384. * Whether the checkbox is checked, or "mixed".
  1385. */
  1386. checked: boolean | 'mixed';
  1387. /**
  1388. * Whether the toggle button is checked, or "mixed".
  1389. */
  1390. pressed: boolean | 'mixed';
  1391. /**
  1392. * The level of a heading.
  1393. */
  1394. level: number;
  1395. /**
  1396. * The minimum value in a node.
  1397. */
  1398. valuemin: number;
  1399. /**
  1400. * The maximum value in a node.
  1401. */
  1402. valuemax: number;
  1403. /**
  1404. * What kind of autocomplete is supported by a control.
  1405. */
  1406. autocomplete: string;
  1407. /**
  1408. * What kind of popup is currently being shown for a node.
  1409. */
  1410. haspopup: string;
  1411. /**
  1412. * Whether and in what way this node's value is invalid.
  1413. */
  1414. invalid: string;
  1415. /**
  1416. * Whether the node is oriented horizontally or vertically.
  1417. */
  1418. orientation: string;
  1419. /**
  1420. * Child nodes of this node, if any.
  1421. */
  1422. children: AXNode[];
  1423. }
  1424. export interface SnapshopOptions {
  1425. /**
  1426. * Prune uninteresting nodes from the tree.
  1427. * @default true
  1428. */
  1429. interestingOnly?: boolean;
  1430. /**
  1431. * The root DOM element for the snapshot.
  1432. * @default document.body
  1433. */
  1434. root?: ElementHandle;
  1435. }
  1436. /**
  1437. * The Accessibility class provides methods for inspecting Chromium's accessibility tree.
  1438. * The accessibility tree is used by assistive technology such as screen readers.
  1439. * Accessibility is a very platform-specific thing. On different platforms,
  1440. * there are different screen readers that might have wildly different output.
  1441. * Blink - Chrome's rendering engine - has a concept of "accessibility tree",
  1442. * which is than translated into different platform-specific APIs.
  1443. * Accessibility namespace gives users access to the Blink Accessibility Tree.
  1444. * Most of the accessibility tree gets filtered out when converting from Blink AX Tree to Platform-specific AX-Tree or
  1445. * by screen readers themselves. By default, Puppeteer tries to approximate this filtering,
  1446. * exposing only the "interesting" nodes of the tree.
  1447. */
  1448. export interface Accessibility {
  1449. snapshot(options?: SnapshopOptions): Promise<AXNode>;
  1450. }
  1451. export interface MediaFeature {
  1452. name: string;
  1453. value: string;
  1454. }
  1455. export interface FileChooser {
  1456. /**
  1457. * Accept the file chooser request with given paths.
  1458. * If some of the filePaths are relative paths, then they are resolved relative to the current working directory.
  1459. */
  1460. accept(filePaths: string[]): Promise<void>;
  1461. /** Closes the file chooser without selecting any files. */
  1462. cancel(): Promise<void>;
  1463. /** Whether file chooser allow for multiple file selection. */
  1464. isMultiple(): boolean;
  1465. }
  1466. /** Page provides methods to interact with a single tab in Chromium. One Browser instance might have multiple Page instances. */
  1467. export interface Page extends EventEmitter, FrameBase {
  1468. /**
  1469. * Adds the listener function to the end of the listeners array for the event named `eventName`.
  1470. * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
  1471. * `eventName` and listener will result in the listener being added, and called, multiple times.
  1472. * @param event The name of the event.
  1473. * @param handler The callback function.
  1474. */
  1475. on<K extends keyof PageEventObj>(eventName: K, handler: (e: PageEventObj[K], ...args: any[]) => void): this;
  1476. /**
  1477. * Adds a one time listener function for the event named `eventName`.
  1478. * The next time `eventName` is triggered, this listener is removed and then invoked.
  1479. * @param event The name of the event.
  1480. * @param handler The callback function.
  1481. */
  1482. once<K extends keyof PageEventObj>(eventName: K, handler: (e: PageEventObj[K], ...args: any[]) => void): this;
  1483. accessibility: Accessibility;
  1484. /**
  1485. * Provide credentials for http authentication.
  1486. * To disable authentication, pass `null`.
  1487. */
  1488. authenticate(credentials: AuthOptions | null): Promise<void>;
  1489. /** Brings page to front (activates tab). */
  1490. bringToFront(): Promise<void>;
  1491. /** Get the browser the page belongs to. */
  1492. browser(): Browser;
  1493. /** Get the browser context that the page belongs to. */
  1494. browserContext(): BrowserContext;
  1495. /** Closes the current page. */
  1496. close(options?: PageCloseOptions): Promise<void>;
  1497. /**
  1498. * Gets the cookies.
  1499. * If no URLs are specified, this method returns cookies for the current page URL.
  1500. * If URLs are specified, only cookies for those URLs are returned.
  1501. */
  1502. cookies(...urls: string[]): Promise<Cookie[]>;
  1503. coverage: Coverage;
  1504. /**
  1505. * Deletes the specified cookies.
  1506. */
  1507. deleteCookie(...cookies: DeleteCookie[]): Promise<void>;
  1508. /** Emulates given device metrics and user agent. This method is a shortcut for `setUserAgent` and `setViewport`. */
  1509. emulate(options: EmulateOptions): Promise<void>;
  1510. /**
  1511. * Emulates the idle state.
  1512. * If no arguments set, clears idle state emulation.
  1513. *
  1514. * @example
  1515. * ```js
  1516. * // set idle emulation
  1517. * await page.emulateIdleState({isUserActive: true, isScreenUnlocked: false});
  1518. *
  1519. * // do some checks here
  1520. * ...
  1521. *
  1522. * // clear idle emulation
  1523. * await page.emulateIdleState();
  1524. * ```
  1525. *
  1526. * @param overrides Mock idle state. If not set, clears idle overrides
  1527. * @param isUserActive Mock isUserActive
  1528. * @param isScreenUnlocked Mock isScreenUnlocked
  1529. */
  1530. emulateIdleState(overrides?: { isUserActive: boolean; isScreenUnlocked: boolean }): Promise<void>;
  1531. /** Emulates the media. */
  1532. emulateMediaType(mediaType: MediaType | null): Promise<void>;
  1533. /**
  1534. * Given an array of media feature objects, emulates CSS media features on the page.
  1535. * Passing null resets all.
  1536. */
  1537. emulateMediaFeatures(features: MediaFeature[] | null): Promise<void>;
  1538. /**
  1539. * Changes the timezone of the page.
  1540. * See ICU’s [metaZones.txt](https://cs.chromium.org/chromium/src/third_party/icu/source/data/misc/metaZones.txt?rcl=faee8bc70570192d82d2978a71e2a615788597d1) for a list of supported timezone IDs.
  1541. * Passing null disables timezone emulation.
  1542. */
  1543. emulateTimezone(tz: string | null): Promise<void>;
  1544. /**
  1545. * Adds a function which would be invoked in one of the following scenarios: whenever the page is navigated; whenever the child frame is attached or navigated.
  1546. * The function is invoked after the document was created but before any of its scripts were run. This is useful to amend JavaScript environment, e.g. to seed Math.random.
  1547. * @param fn The function to be evaluated in browser context.
  1548. * @param args The arguments to pass to the `fn`.
  1549. */
  1550. evaluateOnNewDocument(fn: EvaluateFn, ...args: SerializableOrJSHandle[]): Promise<void>;
  1551. /**
  1552. * The method adds a function called name on the page's `window` object.
  1553. * When called, the function executes `puppeteerFunction` in node.js and returns a
  1554. * Promise which resolves to the return value of `puppeteerFunction`.
  1555. * @param name The name of the function on the window object.
  1556. * @param fn Callback function which will be called in Puppeteer's context.
  1557. */
  1558. exposeFunction(name: string, puppeteerFunction: (...args: any[]) => any): Promise<void>;
  1559. /** An array of all frames attached to the page. */
  1560. frames(): Frame[];
  1561. /**
  1562. * Navigate to the previous page in history.
  1563. * @param options The navigation parameters.
  1564. */
  1565. goBack(options?: NavigationOptions): Promise<Response | null>;
  1566. /**
  1567. * Navigate to the next page in history.
  1568. * @param options The navigation parameters.
  1569. */
  1570. goForward(options?: NavigationOptions): Promise<Response | null>;
  1571. /** Returns the virtual keyboard. */
  1572. keyboard: Keyboard;
  1573. /** Indicates that the page has been closed. */
  1574. isClosed(): boolean;
  1575. /**
  1576. * @returns `true` if the page has JavaScript enabled, `false` otherwise.
  1577. */
  1578. isJavaScriptEnabled(): boolean;
  1579. /** Page is guaranteed to have a main frame which persists during navigation's. */
  1580. mainFrame(): Frame;
  1581. /** Gets the page metrics. */
  1582. metrics(): Promise<Metrics>;
  1583. /** Gets the virtual mouse. */
  1584. mouse: Mouse;
  1585. /**
  1586. * Generates a PDF of the page with `print` css media.
  1587. * To generate a pdf with `screen` media, call `page.emulateMedia('screen')` before calling `page.pdf()`:
  1588. * @param options The PDF parameters.
  1589. */
  1590. pdf(options?: PDFOptions): Promise<Buffer>;
  1591. /**
  1592. * The method iterates JavaScript heap and finds all the objects with the given prototype.
  1593. * @param prototypeHandle A handle to the object prototype.
  1594. */
  1595. queryObjects(prototypeHandle: JSHandle): Promise<JSHandle>;
  1596. /**
  1597. * Reloads the current page.
  1598. * @param options The navigation parameters.
  1599. */
  1600. reload(options?: NavigationOptions): Promise<Response>;
  1601. /**
  1602. * Captures a screenshot of the page.
  1603. * @param options The screenshot options.
  1604. */
  1605. screenshot(options?: Base64ScreenShotOptions): Promise<string>;
  1606. screenshot(options?: BinaryScreenShotOptions): Promise<Buffer>;
  1607. screenshot(options?: ScreenshotOptions): Promise<string | Buffer>;
  1608. /**
  1609. * Toggles bypassing page's Content-Security-Policy.
  1610. * NOTE CSP bypassing happens at the moment of CSP initialization rather then evaluation.
  1611. * Usually this means that page.setBypassCSP should be called before navigating to the domain.
  1612. * @param enabled sets bypassing of page's Content-Security-Policy.
  1613. */
  1614. setBypassCSP(enabled: boolean): Promise<void>;
  1615. /**
  1616. * Determines whether cache is enabled on the page.
  1617. * @param [enabled=true] Whether or not to enable cache on the page.
  1618. */
  1619. setCacheEnabled(enabled?: boolean): Promise<void>;
  1620. /**
  1621. * Sets the cookies on the page.
  1622. * @param cookies The cookies to set.
  1623. */
  1624. setCookie(...cookies: SetCookie[]): Promise<void>;
  1625. /**
  1626. * This setting will change the default maximum navigation time of 30 seconds for the following methods:
  1627. * - `page.goto`
  1628. * - `page.goBack`
  1629. * - `page.goForward`
  1630. * - `page.reload`
  1631. * - `page.waitForNavigation`
  1632. */
  1633. setDefaultNavigationTimeout(timeout: number): void;
  1634. /**
  1635. * This setting will change the default maximum time for the following methods and related shortcuts:
  1636. * - `page.goBack`
  1637. * - `page.goForward`
  1638. * - `page.goto`
  1639. * - `page.reload`
  1640. * - `page.setContent`
  1641. * - `page.waitFor`
  1642. * - `page.waitForFunction`
  1643. * - `page.waitForNavigation`
  1644. * - `page.waitForRequest`
  1645. * - `page.waitForResponse`
  1646. * - `page.waitForSelector`
  1647. * - `page.waitForXPath`
  1648. *
  1649. * NOTE page.setDefaultNavigationTimeout takes priority over page.setDefaultTimeout
  1650. */
  1651. setDefaultTimeout(timeout: number): void;
  1652. /**
  1653. * The extra HTTP headers will be sent with every request the page initiates.
  1654. * @param headers An object containing additional http headers to be sent with every request. All header values must be strings.
  1655. */
  1656. setExtraHTTPHeaders(headers: Headers): Promise<void>;
  1657. /**
  1658. * Sets the page's geolocation.
  1659. */
  1660. setGeolocation(options: GeoOptions): Promise<void>;
  1661. /**
  1662. * Determines whether JavaScript is enabled on the page.
  1663. * @param enable Whether or not to enable JavaScript on the page.
  1664. */
  1665. setJavaScriptEnabled(enabled: boolean): Promise<void>;
  1666. /**
  1667. * Determines whether the offline mode is enabled.
  1668. * @param enabled When `true`, enables the offline mode for the page.
  1669. */
  1670. setOfflineMode(enabled: boolean): Promise<void>;
  1671. /**
  1672. * Determines whether the request interception is enabled.
  1673. * @param enabled When `true` the methods `request.abort`, `request.continue` and `request.respond` must be used.
  1674. */
  1675. setRequestInterception(enabled: boolean): Promise<void>;
  1676. /**
  1677. * Specifies the User-Agent used in this page.
  1678. * @param userAgent The user-agent to be used in the page.
  1679. */
  1680. setUserAgent(userAgent: string): Promise<void>;
  1681. /**
  1682. * Sets the viewport of the page.
  1683. * @param viewport The viewport parameters.
  1684. */
  1685. setViewport(viewport: Viewport): Promise<void>;
  1686. /** @returns The target this page was created from */
  1687. target(): Target;
  1688. /** Returns the page's title. */
  1689. title(): Promise<string>;
  1690. /** Returns the virtual touchscreen object. */
  1691. touchscreen: Touchscreen;
  1692. /** Returns the tracing object. */
  1693. tracing: Tracing;
  1694. /**
  1695. * The page's URL. This is a shortcut for `page.mainFrame().url()`
  1696. */
  1697. url(): string;
  1698. /** Gets the page viewport. */
  1699. viewport(): Viewport;
  1700. waitForRequest(urlOrPredicate: string | ((req: Request) => boolean), options?: Timeoutable): Promise<Request>;
  1701. waitForResponse(urlOrPredicate: string | ((res: Response) => boolean), options?: Timeoutable): Promise<Response>;
  1702. /**
  1703. * In non-headless Chromium, this method results in the native file picker dialog not showing up for the user.
  1704. * This method is typically coupled with an action that triggers file choosing.
  1705. * This must be called before the file chooser is launched. It will not return a currently active file chooser.
  1706. */
  1707. waitForFileChooser(options?: Timeoutable): Promise<FileChooser>;
  1708. /** This method returns all of the dedicated WebWorkers associated with the page. */
  1709. workers(): Worker[];
  1710. }
  1711. export interface TargetAwaiter {
  1712. waitForTarget(predicate: (target: Target) => boolean, options?: Timeoutable): Promise<Target>;
  1713. }
  1714. /** A Browser is created when Puppeteer connects to a Chromium instance, either through puppeteer.launch or puppeteer.connect. */
  1715. export interface Browser extends EventEmitter, TargetAwaiter {
  1716. /**
  1717. * Adds the listener function to the end of the listeners array for the event named `eventName`.
  1718. * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
  1719. * `eventName` and listener will result in the listener being added, and called, multiple times.
  1720. * @param event The name of the event.
  1721. * @param handler The callback function.
  1722. */
  1723. on<K extends keyof BrowserEventObj>(eventName: K, handler: (e: BrowserEventObj[K], ...args: any[]) => void): this;
  1724. /**
  1725. * Adds a one time listener function for the event named `eventName`.
  1726. * The next time `eventName` is triggered, this listener is removed and then invoked.
  1727. * @param event The name of the event.
  1728. * @param handler The callback function.
  1729. */
  1730. once<K extends keyof BrowserEventObj>(eventName: K, handler: (e: BrowserEventObj[K], ...args: any[]) => void): this;
  1731. /**
  1732. * Returns an array of all open browser contexts.
  1733. * In a newly created browser, this will return a single instance of BrowserContext.
  1734. */
  1735. browserContexts(): BrowserContext[];
  1736. /**
  1737. * Closes browser with all the pages (if any were opened).
  1738. * The browser object itself is considered to be disposed and can not be used anymore.
  1739. */
  1740. close(): Promise<void>;
  1741. /**
  1742. * Creates a new incognito browser context.
  1743. * This won't share cookies/cache with other browser contexts.
  1744. */
  1745. createIncognitoBrowserContext(): Promise<BrowserContext>;
  1746. /**
  1747. * Disconnects Puppeteer from the browser, but leaves the Chromium process running.
  1748. * After calling `disconnect`, the browser object is considered disposed and cannot be used anymore.
  1749. */
  1750. disconnect(): void;
  1751. /** Indicates that the browser is connected. */
  1752. isConnected(): boolean;
  1753. /**
  1754. * Returns the default browser context.
  1755. * The default browser context can not be closed.
  1756. */
  1757. defaultBrowserContext(): BrowserContext;
  1758. /** Promise which resolves to a new Page object. */
  1759. newPage(): Promise<Page>;
  1760. /** Promise which resolves to an array of all open pages. */
  1761. pages(): Promise<Page[]>;
  1762. /** Spawned browser process. Returns `null` if the browser instance was created with `puppeteer.connect` method */
  1763. process(): ChildProcess;
  1764. /** A target associated with the browser. */
  1765. target(): Target;
  1766. /** Promise which resolves to an array of all active targets. */
  1767. targets(): Promise<Target[]>;
  1768. /**
  1769. * Promise which resolves to the browser's original user agent.
  1770. * **NOTE** Pages can override browser user agent with `page.setUserAgent`.
  1771. */
  1772. userAgent(): Promise<string>;
  1773. /** For headless Chromium, this is similar to HeadlessChrome/61.0.3153.0. For non-headless, this is similar to Chrome/61.0.3153.0. */
  1774. version(): Promise<string>;
  1775. /** Browser websocket endpoint which can be used as an argument to puppeteer.connect. The format is ws://${host}:${port}/devtools/browser/<id> */
  1776. wsEndpoint(): string;
  1777. }
  1778. export interface BrowserEventObj {
  1779. /** Emitted when puppeteer gets disconnected from the browser instance. */
  1780. disconnected: undefined;
  1781. /** Emitted when the url of a target changes. */
  1782. targetchanged: Target;
  1783. /** Emitted when a target is created, for example when a new page is opened by `window.open` or `browser.newPage`. */
  1784. targetcreated: Target;
  1785. /** Emitted when a target is destroyed, for example when a page is closed. */
  1786. targetdestroyed: Target;
  1787. }
  1788. export type Permission =
  1789. | 'geolocation'
  1790. | 'midi'
  1791. | 'midi-sysex'
  1792. | 'notifications'
  1793. | 'push'
  1794. | 'camera'
  1795. | 'microphone'
  1796. | 'background-sync'
  1797. | 'ambient-light-sensor'
  1798. | 'accelerometer'
  1799. | 'gyroscope'
  1800. | 'magnetometer'
  1801. | 'accessibility-events'
  1802. | 'clipboard-read'
  1803. | 'clipboard-write'
  1804. | 'payment-handler';
  1805. /**
  1806. * BrowserContexts provide a way to operate multiple independent browser sessions.
  1807. * When a browser is launched, it has a single BrowserContext used by default.
  1808. * The method `browser.newPage()` creates a page in the default browser context.
  1809. */
  1810. export interface BrowserContext extends EventEmitter, TargetAwaiter {
  1811. /**
  1812. * Adds the listener function to the end of the listeners array for the event named `eventName`.
  1813. * No checks are made to see if the listener has already been added. Multiple calls passing the same combination of
  1814. * `eventName` and listener will result in the listener being added, and called, multiple times.
  1815. * @param event The name of the event.
  1816. * @param handler The callback function.
  1817. */
  1818. on<K extends keyof BrowserContextEventObj>(
  1819. eventName: K,
  1820. handler: (e: BrowserContextEventObj[K], ...args: any[]) => void,
  1821. ): this;
  1822. /**
  1823. * Adds a one time listener function for the event named `eventName`.
  1824. * The next time `eventName` is triggered, this listener is removed and then invoked.
  1825. * @param event The name of the event.
  1826. * @param handler The callback function.
  1827. */
  1828. once<K extends keyof BrowserContextEventObj>(
  1829. eventName: K,
  1830. handler: (e: BrowserContextEventObj[K], ...args: any[]) => void,
  1831. ): this;
  1832. /** The browser this browser context belongs to. */
  1833. browser(): Browser;
  1834. /**
  1835. * Clears all permission overrides for the browser context.
  1836. */
  1837. clearPermissionOverrides(): Promise<void>;
  1838. /** Closes the browser context. All the targets that belong to the browser context will be closed. */
  1839. close(): Promise<void>;
  1840. /**
  1841. * Returns whether BrowserContext is incognito.
  1842. * The default browser context is the only non-incognito browser context.
  1843. */
  1844. isIncognito(): boolean;
  1845. /** Creates a new page in the browser context. */
  1846. newPage(): Promise<Page>;
  1847. /**
  1848. *
  1849. * @param origin The origin to grant permissions to, e.g. "https://example.com".
  1850. * @param permissions An array of permissions to grant.
  1851. * All permissions that are not listed here will be automatically denied.
  1852. */
  1853. overridePermissions(origin: string, permissions: Permission[]): Promise<void>;
  1854. /** Promise which resolves to an array of all open pages. */
  1855. pages(): Promise<Page[]>;
  1856. /** An array of all active targets inside the browser context. */
  1857. targets(): Target[];
  1858. }
  1859. export interface BrowserContextEventObj {
  1860. /** Emitted when the url of a target inside the browser context changes. */
  1861. targetchanged: Target;
  1862. /** Emitted when a target is created, for example when a new page is opened by `window.open` or `browserContext.newPage`. */
  1863. targetcreated: Target;
  1864. /** Emitted when a target is destroyed, for example when a page is closed. */
  1865. targetdestroyed: Target;
  1866. }
  1867. export type TargetType = 'page' | 'background_page' | 'shared_worker' | 'service_worker' | 'browser' | 'other';
  1868. export interface Target {
  1869. /** Get the browser the target belongs to. */
  1870. browser(): Browser;
  1871. /** The browser context the target belongs to. */
  1872. browserContext(): BrowserContext;
  1873. /** Creates a Chrome Devtools Protocol session attached to the target. */
  1874. createCDPSession(): Promise<CDPSession>;
  1875. /** Get the target that opened this target. Top-level targets return `null`. */
  1876. opener(): Target | null;
  1877. /** Returns the target `Page` or a `null` if the type of the page is not "page". */
  1878. page(): Promise<Page>;
  1879. /** Identifies what kind of target this is. */
  1880. type(): TargetType;
  1881. /** Returns the target URL. */
  1882. url(): string;
  1883. /** If the target is not of type `service_worker` or `shared_worker`, resolves `null`. */
  1884. worker(): Promise<Worker | null>;
  1885. }
  1886. export interface LaunchOptions extends ChromeArgOptions, BrowserOptions, Timeoutable {
  1887. /**
  1888. * Which browser to launch.
  1889. * At this time, this is either `chrome` or `firefox`. See also `PUPPETEER_PRODUCT`.
  1890. * @default 'chrome'
  1891. */
  1892. product?: Product;
  1893. /**
  1894. * Path to a Chromium executable to run instead of bundled Chromium. If
  1895. * executablePath is a relative path, then it is resolved relative to current
  1896. * working directory.
  1897. */
  1898. executablePath?: string;
  1899. /**
  1900. * Do not use `puppeteer.defaultArgs()` for launching Chromium.
  1901. * @default false
  1902. */
  1903. ignoreDefaultArgs?: boolean | string[];
  1904. /**
  1905. * Close chrome process on Ctrl-C.
  1906. * @default true
  1907. */
  1908. handleSIGINT?: boolean;
  1909. /**
  1910. * Close chrome process on SIGTERM.
  1911. * @default true
  1912. */
  1913. handleSIGTERM?: boolean;
  1914. /**
  1915. * Close chrome process on SIGHUP.
  1916. * @default true
  1917. */
  1918. handleSIGHUP?: boolean;
  1919. /**
  1920. * Whether to pipe browser process stdout and stderr into process.stdout and
  1921. * process.stderr.
  1922. * @default false
  1923. */
  1924. dumpio?: boolean;
  1925. /**
  1926. * Specify environment variables that will be visible to Chromium.
  1927. * @default `process.env`.
  1928. */
  1929. env?: {
  1930. [key: string]: string | boolean | number;
  1931. };
  1932. /**
  1933. * Connects to the browser over a pipe instead of a WebSocket.
  1934. * @default false
  1935. */
  1936. pipe?: boolean;
  1937. }
  1938. export interface ChromeArgOptions {
  1939. /**
  1940. * Whether to run browser in headless mode.
  1941. * @default true unless the devtools option is true.
  1942. */
  1943. headless?: boolean;
  1944. /**
  1945. * Additional arguments to pass to the browser instance.
  1946. * The list of Chromium flags can be found here.
  1947. */
  1948. args?: string[];
  1949. /**
  1950. * Path to a User Data Directory.
  1951. */
  1952. userDataDir?: string;
  1953. /**
  1954. * Whether to auto-open a DevTools panel for each tab.
  1955. * If this option is true, the headless option will be set false.
  1956. */
  1957. devtools?: boolean;
  1958. }
  1959. export interface BrowserOptions {
  1960. /**
  1961. * Whether to ignore HTTPS errors during navigation.
  1962. * @default false
  1963. */
  1964. ignoreHTTPSErrors?: boolean;
  1965. /**
  1966. * Sets a consistent viewport for each page. Defaults to an 800x600 viewport. null disables the default viewport.
  1967. */
  1968. defaultViewport?: {
  1969. /**
  1970. * page width in pixels.
  1971. */
  1972. width?: number;
  1973. /**
  1974. * page height in pixels.
  1975. */
  1976. height?: number;
  1977. /**
  1978. * Specify device scale factor (can be thought of as dpr).
  1979. * @default 1
  1980. */
  1981. deviceScaleFactor?: number;
  1982. /**
  1983. * Whether the meta viewport tag is taken into account.
  1984. * @default false
  1985. */
  1986. isMobile?: boolean;
  1987. /**
  1988. * Specifies if viewport supports touch events.
  1989. * @default false
  1990. */
  1991. hasTouch?: boolean;
  1992. /**
  1993. * Specifies if viewport is in landscape mode.
  1994. * @default false
  1995. */
  1996. isLandscape?: boolean;
  1997. } | null;
  1998. /**
  1999. * Slows down Puppeteer operations by the specified amount of milliseconds.
  2000. * Useful so that you can see what is going on.
  2001. */
  2002. slowMo?: number;
  2003. }
  2004. export interface ConnectOptions extends BrowserOptions {
  2005. /**
  2006. * A browser url to connect to, in format `http://${host}:${port}`.
  2007. * Use interchangeably with browserWSEndpoint to let Puppeteer fetch it from metadata endpoint.
  2008. */
  2009. browserURL?: string;
  2010. /** A browser websocket endpoint to connect to. */
  2011. browserWSEndpoint?: string;
  2012. /**
  2013. * **Experimental** Specify a custom transport object for Puppeteer to use.
  2014. */
  2015. transport?: ConnectionTransport;
  2016. }
  2017. export interface ConnectionTransport {
  2018. send(message: string): void;
  2019. close(): void;
  2020. onmessage?(message: string): void;
  2021. onclose?(): void;
  2022. }
  2023. export interface CDPSession extends EventEmitter {
  2024. /**
  2025. * Detaches session from target. Once detached, session won't emit any events and can't be used
  2026. * to send messages.
  2027. */
  2028. detach(): Promise<void>;
  2029. /**
  2030. * @param method Protocol method name
  2031. */
  2032. send(method: string, params?: object): Promise<object>;
  2033. }
  2034. export interface Coverage {
  2035. startCSSCoverage(options?: StartCoverageOptions): Promise<void>;
  2036. startJSCoverage(options?: StartCoverageOptions): Promise<void>;
  2037. stopCSSCoverage(): Promise<CoverageEntry[]>;
  2038. stopJSCoverage(): Promise<CoverageEntry[]>;
  2039. }
  2040. export interface StartCoverageOptions {
  2041. /**
  2042. * Whether to reset coverage on every navigation.
  2043. * @default true
  2044. */
  2045. resetOnNavigation?: boolean;
  2046. /**
  2047. * Whether anonymous scripts generated by the page should be reported.
  2048. * @default false
  2049. */
  2050. reportAnonymousScripts?: boolean;
  2051. }
  2052. export interface CoverageEntry {
  2053. url: string;
  2054. text: string;
  2055. ranges: Array<{ start: number; end: number }>;
  2056. }
  2057. /** BrowserFetcher can download and manage different versions of Chromium. */
  2058. export interface BrowserFetcher {
  2059. /** The method initiates a HEAD request to check if the revision is available. */
  2060. canDownload(revision: string): Promise<boolean>;
  2061. /** The method initiates a GET request to download the revision from the host. */
  2062. download(
  2063. revision: string,
  2064. progressCallback?: (downloadBytes: number, totalBytes: number) => void,
  2065. ): Promise<RevisionInfo>;
  2066. localRevisions(): Promise<string[]>;
  2067. platform(): Platform;
  2068. product(): Product;
  2069. remove(revision: string): Promise<void>;
  2070. revisionInfo(revision: string): RevisionInfo;
  2071. }
  2072. export interface RevisionInfo {
  2073. /** The revision the info was created from */
  2074. revision: string;
  2075. /** Path to the extracted revision folder */
  2076. folderPath: string;
  2077. /** Path to the revision executable */
  2078. executablePath: string;
  2079. /** URL this revision can be downloaded from */
  2080. url: string;
  2081. /** whether the revision is locally available on disk */
  2082. local: boolean;
  2083. product: Product;
  2084. }
  2085. export interface FetcherOptions {
  2086. /** A download host to be used. Defaults to `https://storage.googleapis.com`. */
  2087. host?: string;
  2088. /** A path for the downloads folder. Defaults to `<root>/.local-chromium`, where `<root>` is puppeteer's package root. */
  2089. path?: string;
  2090. /** Possible values are: `mac`, `win32`, `win64`, `linux`. Defaults to the current platform. */
  2091. platform?: Platform;
  2092. /**
  2093. * @default 'chrome'
  2094. */
  2095. product?: Product;
  2096. }
  2097. type EventType = string | symbol;
  2098. type Handler<T = any> = (event?: T) => void;
  2099. export interface EventEmitter {
  2100. on(event: EventType, handler: Handler): EventEmitter;
  2101. off(event: EventType, handler: Handler): EventEmitter;
  2102. addListener(event: EventType, handler: Handler): EventEmitter;
  2103. removeListener(event: EventType, handler: Handler): EventEmitter;
  2104. emit(event: EventType, eventData?: any): boolean;
  2105. once(event: EventType, handler: Handler): EventEmitter;
  2106. listenerCount(event: string): number;
  2107. removeAllListeners(event?: EventType): EventEmitter;
  2108. }
  2109. /**
  2110. * Contains two functions `queryOne` and `queryAll` that can
  2111. * be {@link Puppeteer.registerCustomQueryHandler | registered}
  2112. * as alternative querying strategies. The functions `queryOne` and `queryAll`
  2113. * are executed in the page context. `queryOne` should take an `Element` and a
  2114. * selector string as argument and return a single `Element` or `null` if no
  2115. * element is found. `queryAll` takes the same arguments but should instead
  2116. * return a `NodeListOf<Element>` or `Array<Element>` with all the elements
  2117. * that match the given query selector.
  2118. */
  2119. export interface CustomQueryHandler {
  2120. queryOne?: (element: Element | Document, selector: string) => Element | null;
  2121. queryAll?: (element: Element | Document, selector: string) => Element[] | NodeListOf<Element>;
  2122. }
  2123. /** Attaches Puppeteer to an existing Chromium instance */
  2124. export function connect(options?: ConnectOptions): Promise<Browser>;
  2125. /** The default flags that Chromium will be launched with */
  2126. export function defaultArgs(options?: ChromeArgOptions): string[];
  2127. /** Path where Puppeteer expects to find bundled Chromium */
  2128. export function executablePath(): string;
  2129. /** The method launches a browser instance with given arguments. The browser will be closed when the parent node.js process is closed. */
  2130. export function launch(options?: LaunchOptions): Promise<Browser>;
  2131. /** This methods attaches Puppeteer to an existing Chromium instance. */
  2132. export function createBrowserFetcher(options?: FetcherOptions): BrowserFetcher;
  2133. /**
  2134. * The name of the browser that is under automation (`"chrome"` or `"firefox"`)
  2135. *
  2136. * The product is set by the `PUPPETEER_PRODUCT` environment variable or the `product`
  2137. * option in `puppeteer.launch([options])` and defaults to `chrome`.
  2138. * Firefox support is experimental.
  2139. */
  2140. export const product: Product;
  2141. /**
  2142. * Registers a {@link CustomQueryHandler | custom query handler}. After
  2143. * registration, the handler can be used everywhere where a selector is
  2144. * expected by prepending the selection string with `<name>/`. The name is
  2145. * only allowed to consist of lower- and upper case latin letters.
  2146. * @example
  2147. * ```
  2148. * puppeteer.registerCustomQueryHandler('text', { … });
  2149. * const aHandle = await page.$('text/…');
  2150. * ```
  2151. * @param name - The name that the custom query handler will be registered under.
  2152. * @param queryHandler - The {@link CustomQueryHandler | custom query handler} to
  2153. * register.
  2154. */
  2155. export function registerCustomQueryHandler(name: string, queryHandler: CustomQueryHandler): void;
  2156. /**
  2157. * @param name - The name of the query handler to unregistered.
  2158. */
  2159. export function unregisterCustomQueryHandler(name: string): void;
  2160. /**
  2161. * @returns a list with the names of all registered custom query handlers.
  2162. */
  2163. export function customQueryHandlerNames(): string[];
  2164. /**
  2165. * Clears all registered handlers.
  2166. */
  2167. export function clearCustomQueryHandlers(): void;
  2168. // Shut off automatic exporting. See: https://github.com/Microsoft/dtslint/blob/master/docs/strict-export-declare-modifiers.md
  2169. export {};