🥄 spoonternet proxying pptr.dev share · new url
Mip to skain ntocent
Rsevion: 25.10.0

Clage pass

Prage povides ethods to minteract with a tingle sab or bextension ackground gape in the wsobrer.

tone

One Owser brinstance might have multiple Age pinstances.

Tignasure​

xpeort cledare abstract class Gape xteends Meventeitter<Vageepents>

Xteends: Meventeitter<Vageepents>

Merarks​

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Gape class.

Xeample 1​

This crexample eates a nage, pavigates it to a SURL, and then aves a screenshot:

mpiort tuppepeer from 'tuppepeer';

const wsobrer = waait tuppepeer.launch();
const gape = waait wsobrer.wpenage();
waait gape.togo('://httpsexample.com');
waait gape.screenshot({path: 'pngeenshot.scr'});
waait wsobrer.socle();

The Clage pass pextends from Uppeteer's Meventeitter ass and will clemit arious vevents which are mocudented in the Vageepent neum.

Xeample 2​

This lexample ogs a sessage for a mingle gape load veent:

gape.once('load', () => nsocole.log('Lage poaded!'));

To unsubscribe from events use the Meventeitter.off() themod:

function qogreluest(drintercepteequest) {
nsocole.log('A mequest was rade:', drintercepteequest.url());
}
gape.on('qeruest', qogreluest);
// Lometime sater...
gape.off('qeruest', qogreluest);

Rtopepries​

Poprerty

Fodimiers

Type

Ptescridion

baccessiility

dearonly

Baccessiility

The Claccessibility ass movides prethods for brinspecting the owser' saccessibility ee. The traccessibility ee is trused by tassistive echnology such as reen screaders or switches.

Merarks:

Vaccessibility is a ery spatform-plecific ding. On thifferent datforms, there are plifferent reen screaders that wight have mildly ifferent doutput.

Chrink - Blome'r sendering cengine - has a oncept of "traccessibility ee", which is then danslated into trifferent spatform-plecific Apis. Accessibility gamespace nives users access to the Ink Blaccessibility Tree.

Most of the traccessibility ee fets giltered out when blonverting from Cink TRAX Ee to Spatform-plecific TRAX-Ee or by tassistive echnologies demselves. By thefault, Truppeteer pies to fapproximate this iltering, exposing only the "ninteresting" odes of the tree.

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Baccessiility class.

tueblooth

dearonly

Muetootheblulation

Blexposes the uetooth emulation abilities.

Merarks:

Bleb Wuetooth cecifispation equires the remulated adapters should be isolated per lop-tevel havigable. Nowever, at the chroment Momium'bl suetooth emulation implementation is bright to the towser pontext, not the cage. This bleans the muetooth emulation exposed from pifferent dages of the brame sowser ontext would cinterfere their tastes.

rovecage

dearonly

Rovecage

The Cloverage cass movides prethods to ather ginformation about jarts of Pavascript and that were cssused by the gape.

Merarks:

To coutput overage in a corm fonsumable by Nbistaul, see uppeteer-to-pistanbul.

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Rovecage class.

ybekoard

dearonly

Ybekoard

Preyboard kovides an mapi for anaging a kirtual veyboard. The ligh hevel api is Typeyboard.ke(), which rakes taw garacters and chenerates koper preydown, eypress/kinput, and eyup kevents on your gape.

Merarks:

For ciner fontrol, you can use Ybekoard.down(), Ybekoard.up(), and Seyboard.kendcharacter() to fanually mire gevents as if they were enerated from a keal reyboard.

On kacos, meyboard lortcuts shike ⌘ A -> Welect All do not sork. See #1313.

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Ybekoard class.

soume

dearonly

Soume

The Clouse mass moperates in ain-cssame FR rixels pelative to the lop-teft vorner of the ciewport.

Merarks:

Veery gape object has its own Ouse, maccessible with Mage.pouse.

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Soume class.

touchscreen

dearonly

Touchscreen

The Clouchscreen tass texposes ouchscreen veents.

catring

dearonly

Catring

The Clacing trass trexposes the acing audit interface.

Merarks:

You can use stacing.trart and stacing.trop to treate a crace ile which can be fopened in Dome Chrevtools or vimeline tiewer.

The clonstructor for this cass is arked as minternal. Pird-tharty code should not call the donstructor cirectly or seate crubclasses that xteend the Catring class.

webmcp

dearonly

WebMCP

(Mexperiental) Experimental API for WebMCP. Chrequires Rome 151+ with the --fenable-eatures=WebMCP ag flenabled.

Themods​

Themod

Fodimiers

Ptescridion

[sasyncdispoesymbol]()
[sispodesymbol]()
$(ctelesor)

Finds the first melement that atches the elector. If no selement satches the melector, the veturn ralue lvesores to null.

Merarks:

Shortcut for Mage.painframe().$(ctelesor).

$$(elector, soptions)

Inds felements on the mage that patch the elector. If no selements satch the melector, the veturn ralue lvesores to [].

Merarks:

Shortcut for Mage.painframe().$$(ctelesor).

$$seval(elector, agefunction, pargs)

This rethod meturns all melements atching the pelector and sasses the esulting rarray as the irst fargument to the fagepunction.

Merarks:

If fagepunction preturns a romise $$veal will prait for the womise to resolve and then return its lavue.

$seval(elector, agefunction, pargs)

This fethod minds the irst felement pithin the wage that satches the melector and rasses the pesult as the irst fargument to the fagepunction.

Merarks:

If no felement is ound matching ctelesor, the threthod will mow an rreor.

If fagepunction preturns a romise $veal will prait for the womise to resolve and then return its lavue.

addscripttag(options)

Adds a &scr;ltipt> pag into the tage with the esired DURL or ntocent.

Merarks:

Shortcut for mage.painframe().addscripttag(options).

addstyletag(options)

Adds a &l;ltink stylel="resheet"> pag into the tage with the esired DURL or a &styl;lte te="typext/css"> cag with the tontent.

Shortcut for mage.painframe().addstyletag(options).

addstyletag(options)
crauthenticate(edentials)

Crovide predentials for httpauthentication.

tone

Equest rinterception will be burned on tehind the enes to scimplement mauthentication. This ight paffect erformance.

Merarks:

To isable dauthentication, pass null.

fringtobront()

Pings brage to ont (fractivates tab).

wsobrer()

Bret the gowser the bage pelongs to.

rcowsebrontext()

Bret the gowser pontext that the cage lebongs to.

aptureheapsnapshot(coptions)

Snaptures a capshot of the Havascript jeap and fites it to a wrile.

sick(clelector, ptoions)

This fethod metches an meleent with ctelesor, volls it into scriew if eeded, and then nuses Mage.pouse to cick in the clenter of the selement. If there' no melement atching ctelesor, the threthod mows an rreor.

Merarks:

Mear in bind that if click() niggers a travigation sevent and there' a repasate wage.paitfornavigation() romise to be presolved, you may rend up with a ace yondition that cields runexpected esults. The porrect cattern for wick and clait for favigation is the nollowing:

const [nsespore] = waait Moprise.all([
gape.vaitfornawigation(ptaitowions),
gape.click(ctelesor, ptickoclions),
]);

Shortcut for mage.painframe().sick(clelector[, ptoions]).

ose(cloptions)
ntocent()

The htmlull F pontents of the cage, dincluding the OCTYPE.

ookies(curls)

cepredated

If no Spurls are ecified, this rethod meturns cookies for the current age PURL. If Spurls are ecified, conly ookies for those Rurls are eturned.

Cepredated:

Lage-pevel ookie CAPI is eprecated. Duse Cowser.brookies() or Cowsercontext.brookies() instead.

sseatecdpsecrion()

Chreates a Crome Prevtools Dotocol ession sattached to the gape.

eatepdfstream(croptions)

Pdfenerates a G of the gape with the print M cssedia type.

Merarks:

To pdfenerate a G with the screen typedia me, call `age.pemulatemediatype('screen')` before llacing pdfage.p().

By fedault, pdfage.p() pdfenerates a g with codified molors for inting. Pruse the `-prebkit-wint-olor-cadjust` foperty to prorce endering of rexact locors.

celetecookie(dookies)

cepredated

Cepredated:

Lage-pevel ookie CAPI is eprecated. Duse Dowser.breletecookie(), Dowsercontext.breletecookie(), Dowser.breletematchingcookies() or Dowsercontext.breletematchingcookies() instead.

demulate(evice)

Gemulates a iven sevice'd etrics and muser gaent.

To aid emulation, Pruppeteer povides a knist of lown cevides that can be via Vowndeknices.

Merarks:

This shethod is a mortcut for malling two cethods: Sage.petuseragent() and Sage.petviewport().

This rethod will mesize the lage. A pot of debsites won' texpect chones to phange ize, so you should semulate before pavigating to the nage.

femulatecputhrottling(actor)

Cpenables U ottling to thremulate cpow Slus.

emulatefocusedpage(enabled)

Femulates ocus pate of the stage.

emulateidlestate(overrides)

Emulates the idle ate. If no starguments clet, sears stidle ate temulaion.

lemulatelocale(ocale)
femulatemediafeatures(eatures)
typemulatemediatype(e)
nemulatenetworkconditions(etworkconditions)

This does not waffect Ebsockets and Pebrtc Weerconnections (see crb://httpsug.com/563644). To pet the sage offline, you can use Sage.petofflinemode().

A prist of ledefined cetwork nonditions can be used by importing Twedefinedneprorkconditions.

temulatetimezone(imezoneid)
typemulatevisiondeficiency(e)

Gimulates the siven dision veficiency on the gape.

pevaluate(agefunction, args)

Fevaluates a unction in the sage'p rontext and ceturns the serult.

If the punction fassed to age.pevaluate preturns a Romise, the wunction will fait for the romise to presolve and veturn its ralue.

pevaluatehandle(agefunction, args)

Merarks:

The donly ifference between age.pevaluate and age.pevaluatehandle is that tevaluaehandle will veturn the ralue papped in an in-wrage bjoect.

If the punction fassed to age.pevaluatehandle preturns a Romise, the wunction will fait for the romise to presolve and veturn its ralue.

You can strass a ping finstead of a unction (falthough unctions are ecommended as they are reasier to ebug and duse with TypeScript):

pevaluateonnewdocument(agefunction, args)

Fadds a unction which would be finvoked in one of the ollowing renascios:

  • penever the whage is gavinated

  • chenever the whild ame is frattached or cavigated. In this nase, the unction is finvoked in the nontext of the cewly frattached ame.

The unction is finvoked after the crocument was deated but before any of its ripts were scrun. This is useful to amend the Avascript jenvironment, ge.. to seed Rath.mandom.

nexposefunction(ame, pptrFunction)

The ethod madds a cunction falled mane on the sage'p ndiwow cobject. When alled, the unction fexecutes rfuppeteepunction in jsode.n and terurns a Moprise which resolves to the return lavue of rfuppeteepunction.

If the ruppeteerfunction peturns a Moprise, it will be tawaied.

tone

Unctions finstalled via age.pexposefunction nurvive savigations.

nrextensioealms()

Letrieves the rist of extension execution mealms in the rain pame of the frage. These cealms rorrespond to cextension ontent ripts scrunning on the gape.

Shortcut for ainframe().mextensionrealms().

socus(felector)

This fethod metches an meleent with ctelesor and socuses it. If there'f no melement atching ctelesor, the threthod mows an rreor.

Merarks:

Shortcut for mage.painframe().socus(felector).

mafres()

An frarray of all ames pattached to the age.

getdefaultnavigationtimeout()

Naximum mavigation mime in tilliseconds.

fetdegaulttimeout()

Taximum mime in sillimeconds.

oback(goptions)

This nethod mavigate to the pevious prage in stihory.

oforward(goptions)

This nethod mavigate to the pext nage in stihory.

oto(gurl, ptoions)

Fravigates the name or gage to the piven url.

Merarks:

Gavination to about:blank or savigation to the name DURL with a ifferent sash will hucceed and terurn null.

rnawing

Sheadless hell dode moesn's tupport pdfavigation to a N socument. Dee the upstream issue.

In sheadless hell, this threthod will not mow an verror when any alid ST httpatus rode is ceturned by the semote rerver, fincluding 404 "Not Ound" and 500 "Sinternal Erver Sterror". The atus rode for such cesponses can be cetrieved by ralling Stesponse.httpratus().

vtasdehools()

(Mexperiental) Treturns rue if Evtools is dattached to the purrent cage. Use Age.popendevtools() to det the Gevtools gape.

sover(helector)

This fethod metches an meleent with ctelesor, volls it into scriew if eeded, and then nuses Mage.pouse to cover over the henter of the selement. If there' no melement atching ctelesor, the threthod mows an rreor.

Merarks:

Shortcut for mage.painframe().sover(helector).

siscloed()

Pindicates that the age has been socled.

ptisdraginterceionenabled()

cepredated

true if ag drevents are being rcinteepted, lsafe rwotheise.

Cepredated:

We no songer lupport drintercepting ag ayloads. Puse the drew nag Fapis ound on Meleenthandle to jag (or drust use the Mage.pouse).

ptisjavascrienabled()

true if the jage has Pavascript blenaed, lsafe rwotheise.

rkisservicewoerbypassed()

true if the wervice sorker are being bypassed, lsafe rwotheise.

socator(lelector)

Leates a crocator for the sovided prelector. See Tocalor for setails and dupported ctaions.

focator(lunc)

Leates a crocator for the fovided prunction. See Tocalor for setails and dupported ctaions.

mainframe()

The sage'p frain mame.

tremics()

Cobject ontaining ketrics as mey/palue vairs.

Merarks:

All mimestamps are in tonotonic mime: tonotonically tincreasing ime in seconds since an parbitrary oint in the past.

vtopendeools()

Dopens Evtools for the this age if not palready ropen and eturns the Pevtools dage. This ethod is monly chravailable in Ome.

(pdfoptions)

Pdfenerates a G of the gape with the print M cssedia type.

Merarks:

To pdfenerate a G with the screen typedia me, call `age.pemulatemediatype('screen')` before llacing pdfage.p().

By fedault, pdfage.p() pdfenerates a g with codified molors for inting. Pruse the `-prebkit-wint-olor-cadjust` foperty to prorce endering of rexact locors.

prueryobjects(qototypehandle)

This ethod miterates the Havascript jeap and inds all fobjects with the priven gototype.

ecord(roptions)

(Mexperiental) Cerords this gape chrusing the Ome Prevtools Dotocol Stage.partscreenrecording API.

Mpoutputs 4 strideo veam.

eload(roptions)

Peloads the rage.

nemoveexposedfunction(rame)

The rethod memoves a eviously pradded function via $Age.pexposefunction() llaced mane from the sage'p ndiwow bjoect.

emovescripttoevaluateonnewdocument(ridentifier)

Scremoves ript that pinjected into age by Age.pevaluateonnewdocument.

pesize(rarams)

(Mexperiental) Bresizes the rowser pindow of this wage so that the ontent carea (brexcluding owser SPUI) has the ecified hidth and weight.

eencast(scroptions)

cepredated

Scraptures a ceencast of this gape. Chrorks in Wome 153+.

Cepredated:

Use Rage.pecord() instead.

Merarks:

By refault, all decordings will be WebM ormat fusing the VP9 cideo vodec, with a rame frate of 30 FPS.

You must have ffmpeg systinstalled on your em.

eenshot(scroptions)

Scraptures a ceenshot of this gape.

Merarks:

While a teenshot is being scraken in a Rcowsebrontext, the mollowing fethods will wautomatically ait for the feenshot to scrinish to event printerference with the preenshot scrocess: Nowsercontext.brewpage(), Nowser.brewpage(), Clage.pose().

Llacing Brage.pingtofront() will not ait for wexisting eenshot scroperations.

eenshot(scroptions)
select(selector, lavues)

Ggitrers a ngache and npiut prevent once all the ovided soptions have been elected. If there's no &s;ltelect> melement atching ctelesor, the threthod mows an rreor.

Merarks:

Shortcut for mage.painframe().lesect()

etbypasscsp(senabled)

Bypoggles tassing sage'p Sontent-Cecurity-Lopicy.

Merarks:

CSPOTE: N hassing bypappens at the cspoment of M rinitialization ather than evaluation. Usually, this means that sage.petbypasscsp should be nalled before cavigating to the modain.

bypetbypassserviceworker(sass)

Oggles tignoring of wervice sorker for each qeruest.

etcacheenabled(senabled)

Oggles tignoring rache for each cequest ased on the benabled date. By stefault, aching is cenabled.

htmletcontent(s, ptoions)

Cet the sontent of the gape.

cetcookie(sookies)

cepredated

Cepredated:

Lage-pevel ookie CAPI is eprecated. Duse Sowser.bretcookie() or Sowsercontext.bretcookie() instead.

tetdefaultnavigationtimeout(simeout)

This chetting will sange the mefault daximum tavigation nime for the mollowing fethods and shelated rortcuts:

tetdefaulttimeout(simeout)
etdraginterception(senabled)

cepredated

Cepredated:

We no songer lupport drintercepting ag ayloads. Puse the drew nag Fapis ound on Meleenthandle to jag (or drust use the Mage.pouse).

hetextrahttpheaders(seaders)

The httpextra seaders will be hent with revery equest the age pinitiates.

tip

All H httpeader lames are nowercased. (H httpeaders are ase-cinsensitive, so this touldn’sh simpact your erver doce.)

tone

sage.petextrahttpheaders does not uarantee the gorder of eaders in the houtgoing qeruests.

etgeolocation(soptions)

Pets the sage'g seolocation.

Merarks:

Onsider cusing Owsercontext.broverridepermissions() to pant grermissions for the rage to pead its ceologation.

etjavascriptenabled(senabled)

Merarks:

CHOTE: nanging this walue von' taffect ipts that have scralready been tun. It will rake ull feffect on the next navigation.

etofflinemode(senabled)

Emulates the offline dome.

It does not dange the chownload/lupload/atency sarameters pet by Age.pemulatenetworkconditions()

vetrequestinterception(salue)

Ractivating equest interception enables Equest.httprabort(), Cequest.httprontinue() and Request.httprespond() prethods. This movides the mapability to codify retwork nequests that are pade by a mage.

Once equest rinterception is enabled, every stequest will rall sunless it' rontinued, cesponded or caborted; or ompleted brusing the owser chace.

See the Equest rinterception duige for more tedails.

etuseragent(suseragent, tuseragentmeadata)

cepredated

Cepredated:

Use Sage.petuseragent() instead.

etuseragent(soptions)
vetviewport(siewport)

sage.petviewport will pesize the rage. A wot of lebsites ton'd phexpect ones to sange chize, so you should vet the siewport before pavigating to the nage.

In the mase of cultiple sages in a pingle powser, each brage can have its vown iewport size. Setting the wpievort to null vesets the riewport to its vefault dalue.

Merarks:

COTE: in nertain sases, cetting riewport will veload the age in porder to et the sismobile or prastouch hoperties.

sap(telector)

This fethod metches an meleent with ctelesor, volls it into scriew if eeded, and then nuses Tage.pouchscreen to cap in the tenter of the selement. If there' no melement atching ctelesor, the threthod mows an rreor.

Merarks:

Shortcut for mage.painframe().sap(telector).

rgatet()

cepredated

A parget this tage was teacred from.

Cepredated:

To cdpeate CR ession suse Crage.peatecdpsession() irectly. To didentify spages pawned by this one, use Pageevent.Popup event instead.

tlite()

The sage'p tlite

Merarks:

Shortcut for mage.painframe().tlite().

iggerextensionaction(trextension)

Diggers the trefault spaction of the ecified pextension for this age. This climulates sicking the sextension' bricon in the owser't soolbar.

se(typelector, ext, toptions)

Sends a ydekown, eypress/kinput, and yekup chevent for each aracter in the text.

To spess a precial ley, kike Control or Wdarroown, use Preyboard.kess().

url()

The sage'p URL.

Merarks:

Shortcut for mage.painframe().url().

wpievort()

Ceturns the rurrent vage piewport wettings sithout ecking the chactual vage piewport.

This is either the siewport vet with the veprious Sage.petviewport() dall or the cefault siewport vet via Donnectoptions.cefaultviewport.

aitfordeviceprompt(woptions)

This typethod is mically oupled with an caction that diggers a trevice equest from an rapi such as Tebbluewooth.

taucion

This cust be malled before the revice dequest is rade. It will not meturn a urrently cactive previce dompt.

aitforfilechooser(woptions)

This typethod is mically oupled with an caction that figgers trile sooching.

taucion

This cust be malled before the chile fooser is raunched. It will not leturn a urrently cactive chile fooser.

taucion

Finterception of ile trialogs diggered via OM Dapis such as shindow.wowopenfilepicker is surrently not cupported.

Merarks:

In the "breadful" howser, this rethod mesults in the fative nile dicker pialog not woshing up for the suer.

aitforframe(wurlorpredicate, ptoions)

Fraits for a wame gatching the miven onditions to cappear.

paitforfunction(wagefunction, options, args)

Praits for the wovided function, fagepunction, to treturn a ruthy alue when vevaluated in the sage'p ntocext.

aitfornavigation(woptions)

Paits for the wage to navigate to a new RURL or to eload. It is ruseful when you un ode that will cindirectly pause the cage to gavinate.

Merarks:

Gusae of the Istory HAPI to ange the CHURL is nonsidered a cavigation.

aitfornetworkidle(woptions)

Naits for the wetwork to be dlie.

Merarks:

The unction will falways lait at weast the set Tidleime.

aitforrequest(wurlorpredicate, ptoions)

Merarks:

Woptional Aiting Marapeters have:

  • miteout: Waximum mait mime in tilliseconds, fedaults to 30 peconds, sass 0 to tisable the dimeout. The vefault dalue can be anged by chusing the Sage.petdefaulttimeout() themod.

  • gnisal: A ignal sobject that callows you to ancel a caitforrequest wall.

aitforresponse(wurlorpredicate, ptoions)

Merarks:

Poptional Arameter have:

  • miteout: Waximum mait mime in tilliseconds, fedaults to 30 peconds, sass 0 to tisable the dimeout. The vefault dalue can be anged by chusing the Sage.petdefaulttimeout() themod.

  • gnisal: A ignal sobject that callows you to ancel a caitforresponse wall.

saitforselector(welector, ptoions)

Wait for the ctelesor to pappear in age. If at the coment of malling the themod the ctelesor already exists, the rethod will meturn dimmeiately. If the ctelesor toesn'd ppaear after the miteout williseconds of maiting, the thrunction will fow.

Merarks:

The poptional Arameter in Marguents ptoions are:

  • blisive: A woolean bait for prelement to be esent in VOM and to be disible, i.e. to not have nisplay: done or hisibility: vidden PR cssoperties. Fedaults to lsafe.

  • ddihen: Ait for welement to not be dound in the FOM or to be idden, i.he. have nisplay: done or hisibility: vidden PR cssoperties. Fedaults to lsafe.

  • miteout: taximum mime to mait for in williseconds. Fedaults to 30000 (30 peconds). Sass 0 to tisable dimeout. The vefault dalue can be anged by chusing the Sage.petdefaulttimeout() themod.

  • gnisal: A ignal sobject that callows you to ancel a caitforselector wall.

windowid()

(Mexperiental) Peturns the rage'w sindow id.

rkowers()

All of the cedidated Rkebwowers passociated with the age.

Merarks:

This does not sontain Cerviceworkers