1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310 |
- var mapperTab = (function () {
- 'use strict';
- var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
- function getAugmentedNamespace(n) {
- if (n.__esModule) return n;
- var f = n.default;
- if (typeof f == "function") {
- var a = function a () {
- if (this instanceof a) {
- return Reflect.construct(f, arguments, this.constructor);
- }
- return f.apply(this, arguments);
- };
- a.prototype = f.prototype;
- } else a = {};
- Object.defineProperty(a, '__esModule', {value: true});
- Object.keys(n).forEach(function (k) {
- var d = Object.getOwnPropertyDescriptor(n, k);
- Object.defineProperty(a, k, d.get ? d : {
- enumerable: true,
- get: function () {
- return n[k];
- }
- });
- });
- return a;
- }
- var bidiTab = {};
- var BidiMapper = {};
- var BidiServer$1 = {};
- var EventEmitter$1 = {};
- function mitt(n){return {all:n=n||new Map,on:function(t,e){var i=n.get(t);i?i.push(e):n.set(t,[e]);},off:function(t,e){var i=n.get(t);i&&(e?i.splice(i.indexOf(e)>>>0,1):n.set(t,[]));},emit:function(t,e){var i=n.get(t);i&&i.slice().map(function(n){n(e);}),(i=n.get("*"))&&i.slice().map(function(n){n(t,e);});}}}
- var mitt$1 = /*#__PURE__*/Object.freeze({
- __proto__: null,
- default: mitt
- });
- var require$$0 = /*@__PURE__*/getAugmentedNamespace(mitt$1);
- var __importDefault$2 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(EventEmitter$1, "__esModule", { value: true });
- EventEmitter$1.EventEmitter = void 0;
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const mitt_1 = __importDefault$2(require$$0);
- class EventEmitter {
- #emitter = (0, mitt_1.default)();
- on(type, handler) {
- this.#emitter.on(type, handler);
- return this;
- }
- /**
- * Like `on` but the listener will only be fired once and then it will be removed.
- * @param event The event you'd like to listen to
- * @param handler The handler function to run when the event occurs
- * @return `this` to enable chaining method calls.
- */
- once(event, handler) {
- const onceHandler = (eventData) => {
- handler(eventData);
- this.off(event, onceHandler);
- };
- return this.on(event, onceHandler);
- }
- off(type, handler) {
- this.#emitter.off(type, handler);
- return this;
- }
- /**
- * Emits an event and call any associated listeners.
- *
- * @param event The event to emit.
- * @param eventData Any data to emit with the event.
- * @return `true` if there are any listeners, `false` otherwise.
- */
- emit(event, eventData) {
- this.#emitter.emit(event, eventData);
- }
- /**
- * Removes all listeners. If given an event argument, it will remove only
- * listeners for that event.
- * @param event - the event to remove listeners for.
- * @returns `this` to enable you to chain method calls.
- */
- removeAllListeners(event) {
- if (event) {
- this.#emitter.all.delete(event);
- }
- else {
- this.#emitter.all.clear();
- }
- return this;
- }
- }
- EventEmitter$1.EventEmitter = EventEmitter;
- var log$1 = {};
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(log$1, "__esModule", { value: true });
- log$1.LogType = void 0;
- var LogType;
- (function (LogType) {
- // keep-sorted start
- LogType["bidi"] = "bidi";
- LogType["cdp"] = "cdp";
- LogType["debug"] = "debug";
- LogType["debugError"] = "debug:error";
- LogType["debugInfo"] = "debug:info";
- // keep-sorted end
- })(LogType || (log$1.LogType = LogType = {}));
- var ProcessingQueue$1 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(ProcessingQueue$1, "__esModule", { value: true });
- ProcessingQueue$1.ProcessingQueue = void 0;
- const log_js_1$d = log$1;
- class ProcessingQueue {
- static LOGGER_PREFIX = `${log_js_1$d.LogType.debug}:queue`;
- #logger;
- #processor;
- #queue = [];
- // Flag to keep only 1 active processor.
- #isProcessing = false;
- constructor(processor, logger) {
- this.#processor = processor;
- this.#logger = logger;
- }
- add(entry, name) {
- this.#queue.push([entry, name]);
- // No need in waiting. Just initialize processor if needed.
- void this.#processIfNeeded();
- }
- async #processIfNeeded() {
- if (this.#isProcessing) {
- return;
- }
- this.#isProcessing = true;
- while (this.#queue.length > 0) {
- const arrayEntry = this.#queue.shift();
- if (!arrayEntry) {
- continue;
- }
- const [entryPromise, name] = arrayEntry;
- this.#logger?.(ProcessingQueue.LOGGER_PREFIX, 'Processing event:', name);
- await entryPromise
- .then((entry) => {
- if (entry.kind === 'error') {
- this.#logger?.(log_js_1$d.LogType.debugError, 'Event threw before sending:', entry.error.message, entry.error.stack);
- return;
- }
- return this.#processor(entry.value);
- })
- .catch((error) => {
- this.#logger?.(log_js_1$d.LogType.debugError, 'Event was not processed:', error?.message);
- });
- }
- this.#isProcessing = false;
- }
- }
- ProcessingQueue$1.ProcessingQueue = ProcessingQueue;
- var CommandProcessor$1 = {};
- var protocol = {};
- var cdp = {};
- Object.defineProperty(cdp, "__esModule", { value: true });
- var chromiumBidi = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(chromiumBidi, "__esModule", { value: true });
- chromiumBidi.EVENT_NAMES = chromiumBidi.Network = chromiumBidi.BrowsingContext = chromiumBidi.Log = chromiumBidi.Script = chromiumBidi.BiDiModule = void 0;
- // keep-sorted end
- var BiDiModule;
- (function (BiDiModule) {
- // keep-sorted start
- BiDiModule["Browser"] = "browser";
- BiDiModule["BrowsingContext"] = "browsingContext";
- BiDiModule["Cdp"] = "cdp";
- BiDiModule["Input"] = "input";
- BiDiModule["Log"] = "log";
- BiDiModule["Network"] = "network";
- BiDiModule["Script"] = "script";
- BiDiModule["Session"] = "session";
- // keep-sorted end
- })(BiDiModule || (chromiumBidi.BiDiModule = BiDiModule = {}));
- var Script$1;
- (function (Script) {
- (function (EventNames) {
- // keep-sorted start
- EventNames["Message"] = "script.message";
- EventNames["RealmCreated"] = "script.realmCreated";
- EventNames["RealmDestroyed"] = "script.realmDestroyed";
- // keep-sorted end
- })(Script.EventNames || (Script.EventNames = {}));
- })(Script$1 || (chromiumBidi.Script = Script$1 = {}));
- var Log;
- (function (Log) {
- (function (EventNames) {
- EventNames["LogEntryAdded"] = "log.entryAdded";
- })(Log.EventNames || (Log.EventNames = {}));
- })(Log || (chromiumBidi.Log = Log = {}));
- var BrowsingContext$1;
- (function (BrowsingContext) {
- (function (EventNames) {
- // keep-sorted start
- EventNames["ContextCreated"] = "browsingContext.contextCreated";
- EventNames["ContextDestroyed"] = "browsingContext.contextDestroyed";
- EventNames["DomContentLoaded"] = "browsingContext.domContentLoaded";
- EventNames["DownloadWillBegin"] = "browsingContext.downloadWillBegin";
- EventNames["FragmentNavigated"] = "browsingContext.fragmentNavigated";
- EventNames["Load"] = "browsingContext.load";
- EventNames["NavigationAborted"] = "browsingContext.navigationAborted";
- EventNames["NavigationFailed"] = "browsingContext.navigationFailed";
- EventNames["NavigationStarted"] = "browsingContext.navigationStarted";
- EventNames["UserPromptClosed"] = "browsingContext.userPromptClosed";
- EventNames["UserPromptOpened"] = "browsingContext.userPromptOpened";
- // keep-sorted end
- })(BrowsingContext.EventNames || (BrowsingContext.EventNames = {}));
- })(BrowsingContext$1 || (chromiumBidi.BrowsingContext = BrowsingContext$1 = {}));
- var Network$1;
- (function (Network) {
- (function (EventNames) {
- // keep-sorted start
- EventNames["AuthRequired"] = "network.authRequired";
- EventNames["BeforeRequestSent"] = "network.beforeRequestSent";
- EventNames["FetchError"] = "network.fetchError";
- EventNames["ResponseCompleted"] = "network.responseCompleted";
- EventNames["ResponseStarted"] = "network.responseStarted";
- // keep-sorted end
- })(Network.EventNames || (Network.EventNames = {}));
- })(Network$1 || (chromiumBidi.Network = Network$1 = {}));
- chromiumBidi.EVENT_NAMES = new Set([
- // keep-sorted start
- ...Object.values(BiDiModule),
- ...Object.values(BrowsingContext$1.EventNames),
- ...Object.values(Log.EventNames),
- ...Object.values(Network$1.EventNames),
- ...Object.values(Script$1.EventNames),
- // keep-sorted end
- ]);
- var webdriverBidi$1 = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(webdriverBidi$1, "__esModule", { value: true });
- var ErrorResponse = {};
- Object.defineProperty(ErrorResponse, "__esModule", { value: true });
- ErrorResponse.UnderspecifiedStoragePartitionException = ErrorResponse.UnableToSetFileInputException = ErrorResponse.UnableToSetCookieException = ErrorResponse.NoSuchStoragePartitionException = ErrorResponse.UnsupportedOperationException = ErrorResponse.UnableToCloseBrowserException = ErrorResponse.UnableToCaptureScreenException = ErrorResponse.UnknownErrorException = ErrorResponse.UnknownCommandException = ErrorResponse.SessionNotCreatedException = ErrorResponse.NoSuchUserContextException = ErrorResponse.NoSuchScriptException = ErrorResponse.NoSuchRequestException = ErrorResponse.NoSuchNodeException = ErrorResponse.NoSuchInterceptException = ErrorResponse.NoSuchHistoryEntryException = ErrorResponse.NoSuchHandleException = ErrorResponse.NoSuchFrameException = ErrorResponse.NoSuchElementException = ErrorResponse.NoSuchAlertException = ErrorResponse.MoveTargetOutOfBoundsException = ErrorResponse.InvalidSessionIdException = ErrorResponse.InvalidSelectorException = ErrorResponse.InvalidArgumentException = ErrorResponse.Exception = void 0;
- class Exception {
- error;
- message;
- stacktrace;
- constructor(error, message, stacktrace) {
- this.error = error;
- this.message = message;
- this.stacktrace = stacktrace;
- }
- toErrorResponse(commandId) {
- return {
- type: 'error',
- id: commandId,
- error: this.error,
- message: this.message,
- stacktrace: this.stacktrace,
- };
- }
- }
- ErrorResponse.Exception = Exception;
- class InvalidArgumentException extends Exception {
- constructor(message, stacktrace) {
- super("invalid argument" /* ErrorCode.InvalidArgument */, message, stacktrace);
- }
- }
- ErrorResponse.InvalidArgumentException = InvalidArgumentException;
- class InvalidSelectorException extends Exception {
- constructor(message, stacktrace) {
- super("invalid selector" /* ErrorCode.InvalidSelector */, message, stacktrace);
- }
- }
- ErrorResponse.InvalidSelectorException = InvalidSelectorException;
- class InvalidSessionIdException extends Exception {
- constructor(message, stacktrace) {
- super("invalid session id" /* ErrorCode.InvalidSessionId */, message, stacktrace);
- }
- }
- ErrorResponse.InvalidSessionIdException = InvalidSessionIdException;
- class MoveTargetOutOfBoundsException extends Exception {
- constructor(message, stacktrace) {
- super("move target out of bounds" /* ErrorCode.MoveTargetOutOfBounds */, message, stacktrace);
- }
- }
- ErrorResponse.MoveTargetOutOfBoundsException = MoveTargetOutOfBoundsException;
- class NoSuchAlertException extends Exception {
- constructor(message, stacktrace) {
- super("no such alert" /* ErrorCode.NoSuchAlert */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchAlertException = NoSuchAlertException;
- class NoSuchElementException extends Exception {
- constructor(message, stacktrace) {
- super("no such element" /* ErrorCode.NoSuchElement */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchElementException = NoSuchElementException;
- class NoSuchFrameException extends Exception {
- constructor(message, stacktrace) {
- super("no such frame" /* ErrorCode.NoSuchFrame */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchFrameException = NoSuchFrameException;
- class NoSuchHandleException extends Exception {
- constructor(message, stacktrace) {
- super("no such handle" /* ErrorCode.NoSuchHandle */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchHandleException = NoSuchHandleException;
- class NoSuchHistoryEntryException extends Exception {
- constructor(message, stacktrace) {
- super("no such history entry" /* ErrorCode.NoSuchHistoryEntry */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchHistoryEntryException = NoSuchHistoryEntryException;
- class NoSuchInterceptException extends Exception {
- constructor(message, stacktrace) {
- super("no such intercept" /* ErrorCode.NoSuchIntercept */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchInterceptException = NoSuchInterceptException;
- class NoSuchNodeException extends Exception {
- constructor(message, stacktrace) {
- super("no such node" /* ErrorCode.NoSuchNode */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchNodeException = NoSuchNodeException;
- class NoSuchRequestException extends Exception {
- constructor(message, stacktrace) {
- super("no such request" /* ErrorCode.NoSuchRequest */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchRequestException = NoSuchRequestException;
- class NoSuchScriptException extends Exception {
- constructor(message, stacktrace) {
- super("no such script" /* ErrorCode.NoSuchScript */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchScriptException = NoSuchScriptException;
- class NoSuchUserContextException extends Exception {
- constructor(message, stacktrace) {
- super("no such user context" /* ErrorCode.NoSuchUserContext */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchUserContextException = NoSuchUserContextException;
- class SessionNotCreatedException extends Exception {
- constructor(message, stacktrace) {
- super("session not created" /* ErrorCode.SessionNotCreated */, message, stacktrace);
- }
- }
- ErrorResponse.SessionNotCreatedException = SessionNotCreatedException;
- class UnknownCommandException extends Exception {
- constructor(message, stacktrace) {
- super("unknown command" /* ErrorCode.UnknownCommand */, message, stacktrace);
- }
- }
- ErrorResponse.UnknownCommandException = UnknownCommandException;
- class UnknownErrorException extends Exception {
- constructor(message, stacktrace = new Error().stack) {
- super("unknown error" /* ErrorCode.UnknownError */, message, stacktrace);
- }
- }
- ErrorResponse.UnknownErrorException = UnknownErrorException;
- class UnableToCaptureScreenException extends Exception {
- constructor(message, stacktrace) {
- super("unable to capture screen" /* ErrorCode.UnableToCaptureScreen */, message, stacktrace);
- }
- }
- ErrorResponse.UnableToCaptureScreenException = UnableToCaptureScreenException;
- class UnableToCloseBrowserException extends Exception {
- constructor(message, stacktrace) {
- super("unable to close browser" /* ErrorCode.UnableToCloseBrowser */, message, stacktrace);
- }
- }
- ErrorResponse.UnableToCloseBrowserException = UnableToCloseBrowserException;
- class UnsupportedOperationException extends Exception {
- constructor(message, stacktrace) {
- super("unsupported operation" /* ErrorCode.UnsupportedOperation */, message, stacktrace);
- }
- }
- ErrorResponse.UnsupportedOperationException = UnsupportedOperationException;
- class NoSuchStoragePartitionException extends Exception {
- constructor(message, stacktrace) {
- super("no such storage partition" /* ErrorCode.NoSuchStoragePartition */, message, stacktrace);
- }
- }
- ErrorResponse.NoSuchStoragePartitionException = NoSuchStoragePartitionException;
- class UnableToSetCookieException extends Exception {
- constructor(message, stacktrace) {
- super("unable to set cookie" /* ErrorCode.UnableToSetCookie */, message, stacktrace);
- }
- }
- ErrorResponse.UnableToSetCookieException = UnableToSetCookieException;
- class UnableToSetFileInputException extends Exception {
- constructor(message, stacktrace) {
- super("unable to set file input" /* ErrorCode.UnableToSetFileInput */, message, stacktrace);
- }
- }
- ErrorResponse.UnableToSetFileInputException = UnableToSetFileInputException;
- class UnderspecifiedStoragePartitionException extends Exception {
- constructor(message, stacktrace) {
- super("underspecified storage partition" /* ErrorCode.UnderspecifiedStoragePartition */, message, stacktrace);
- }
- }
- ErrorResponse.UnderspecifiedStoragePartitionException = UnderspecifiedStoragePartitionException;
- var webdriverBidiPermissions$1 = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(webdriverBidiPermissions$1, "__esModule", { value: true });
- (function (exports) {
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- var desc = Object.getOwnPropertyDescriptor(m, k);
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
- desc = { enumerable: true, get: function() { return m[k]; } };
- }
- Object.defineProperty(o, k2, desc);
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.ChromiumBidi = exports.Cdp = void 0;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- exports.Cdp = __importStar(cdp);
- exports.ChromiumBidi = __importStar(chromiumBidi);
- __exportStar(webdriverBidi$1, exports);
- __exportStar(ErrorResponse, exports);
- __exportStar(webdriverBidiPermissions$1, exports);
-
- } (protocol));
- var BidiNoOpParser$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(BidiNoOpParser$1, "__esModule", { value: true });
- BidiNoOpParser$1.BidiNoOpParser = void 0;
- class BidiNoOpParser {
- // Browser domain
- // keep-sorted start block=yes
- parseRemoveUserContextParams(params) {
- return params;
- }
- // keep-sorted end
- // Browsing Context domain
- // keep-sorted start block=yes
- parseActivateParams(params) {
- return params;
- }
- parseCaptureScreenshotParams(params) {
- return params;
- }
- parseCloseParams(params) {
- return params;
- }
- parseCreateParams(params) {
- return params;
- }
- parseGetTreeParams(params) {
- return params;
- }
- parseHandleUserPromptParams(params) {
- return params;
- }
- parseLocateNodesParams(params) {
- return params;
- }
- parseNavigateParams(params) {
- return params;
- }
- parsePrintParams(params) {
- return params;
- }
- parseReloadParams(params) {
- return params;
- }
- parseSetViewportParams(params) {
- return params;
- }
- parseTraverseHistoryParams(params) {
- return params;
- }
- // keep-sorted end
- // CDP domain
- // keep-sorted start block=yes
- parseGetSessionParams(params) {
- return params;
- }
- parseResolveRealmParams(params) {
- return params;
- }
- parseSendCommandParams(params) {
- return params;
- }
- // keep-sorted end
- // Script domain
- // keep-sorted start block=yes
- parseAddPreloadScriptParams(params) {
- return params;
- }
- parseCallFunctionParams(params) {
- return params;
- }
- parseDisownParams(params) {
- return params;
- }
- parseEvaluateParams(params) {
- return params;
- }
- parseGetRealmsParams(params) {
- return params;
- }
- parseRemovePreloadScriptParams(params) {
- return params;
- }
- // keep-sorted end
- // Input domain
- // keep-sorted start block=yes
- parsePerformActionsParams(params) {
- return params;
- }
- parseReleaseActionsParams(params) {
- return params;
- }
- parseSetFilesParams(params) {
- return params;
- }
- // keep-sorted end
- // Network domain
- // keep-sorted start block=yes
- parseAddInterceptParams(params) {
- return params;
- }
- parseContinueRequestParams(params) {
- return params;
- }
- parseContinueResponseParams(params) {
- return params;
- }
- parseContinueWithAuthParams(params) {
- return params;
- }
- parseFailRequestParams(params) {
- return params;
- }
- parseProvideResponseParams(params) {
- return params;
- }
- parseRemoveInterceptParams(params) {
- return params;
- }
- // keep-sorted end
- // Permissions domain
- // keep-sorted start block=yes
- parseSetPermissionsParams(params) {
- return params;
- }
- // keep-sorted end
- // Session domain
- // keep-sorted start block=yes
- parseSubscribeParams(params) {
- return params;
- }
- // keep-sorted end
- // Storage domain
- // keep-sorted start block=yes
- parseDeleteCookiesParams(params) {
- return params;
- }
- parseGetCookiesParams(params) {
- return params;
- }
- parseSetCookieParams(params) {
- return params;
- }
- }
- BidiNoOpParser$1.BidiNoOpParser = BidiNoOpParser;
- var BrowserProcessor$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(BrowserProcessor$1, "__esModule", { value: true });
- BrowserProcessor$1.BrowserProcessor = void 0;
- const protocol_js_1$n = protocol;
- class BrowserProcessor {
- #browserCdpClient;
- constructor(browserCdpClient) {
- this.#browserCdpClient = browserCdpClient;
- }
- close() {
- // Ensure that it is put at the end of the event loop.
- // This way we send back the response before closing the tab.
- setTimeout(() => this.#browserCdpClient.sendCommand('Browser.close'), 0);
- return {};
- }
- async createUserContext(params) {
- const request = {
- proxyServer: params['goog:proxyServer'] ?? undefined,
- };
- const proxyBypassList = params['goog:proxyBypassList'] ?? undefined;
- if (proxyBypassList) {
- request.proxyBypassList = proxyBypassList.join(',');
- }
- const context = await this.#browserCdpClient.sendCommand('Target.createBrowserContext', request);
- return {
- userContext: context.browserContextId,
- };
- }
- async removeUserContext(params) {
- const userContext = params.userContext;
- if (userContext === 'default') {
- throw new protocol_js_1$n.InvalidArgumentException('`default` user context cannot be removed');
- }
- try {
- await this.#browserCdpClient.sendCommand('Target.disposeBrowserContext', {
- browserContextId: userContext,
- });
- }
- catch (err) {
- // https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/protocol/target_handler.cc;l=1424;drc=c686e8f4fd379312469fe018f5c390e9c8f20d0d
- if (err.message.startsWith('Failed to find context with id')) {
- throw new protocol_js_1$n.NoSuchUserContextException(err.message);
- }
- throw err;
- }
- return {};
- }
- async getUserContexts() {
- const result = await this.#browserCdpClient.sendCommand('Target.getBrowserContexts');
- return {
- userContexts: [
- {
- userContext: 'default',
- },
- ...result.browserContextIds.map((id) => {
- return {
- userContext: id,
- };
- }),
- ],
- };
- }
- }
- BrowserProcessor$1.BrowserProcessor = BrowserProcessor;
- var CdpProcessor$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(CdpProcessor$1, "__esModule", { value: true });
- CdpProcessor$1.CdpProcessor = void 0;
- const protocol_js_1$m = protocol;
- class CdpProcessor {
- #browsingContextStorage;
- #realmStorage;
- #cdpConnection;
- #browserCdpClient;
- constructor(browsingContextStorage, realmStorage, cdpConnection, browserCdpClient) {
- this.#browsingContextStorage = browsingContextStorage;
- this.#realmStorage = realmStorage;
- this.#cdpConnection = cdpConnection;
- this.#browserCdpClient = browserCdpClient;
- }
- getSession(params) {
- const context = params.context;
- const sessionId = this.#browsingContextStorage.getContext(context).cdpTarget.cdpSessionId;
- if (sessionId === undefined) {
- return {};
- }
- return { session: sessionId };
- }
- resolveRealm(params) {
- const context = params.realm;
- const realm = this.#realmStorage.getRealm({ realmId: context });
- if (realm === undefined) {
- throw new protocol_js_1$m.UnknownErrorException(`Could not find realm ${params.realm}`);
- }
- return { executionContextId: realm.executionContextId };
- }
- async sendCommand(params) {
- const client = params.session
- ? this.#cdpConnection.getCdpClient(params.session)
- : this.#browserCdpClient;
- const result = await client.sendCommand(params.method, params.params);
- return {
- result,
- session: params.session,
- };
- }
- }
- CdpProcessor$1.CdpProcessor = CdpProcessor;
- var BrowsingContextProcessor$1 = {};
- Object.defineProperty(BrowsingContextProcessor$1, "__esModule", { value: true });
- BrowsingContextProcessor$1.BrowsingContextProcessor = void 0;
- const protocol_js_1$l = protocol;
- class BrowsingContextProcessor {
- #browserCdpClient;
- #browsingContextStorage;
- constructor(browserCdpClient, browsingContextStorage) {
- this.#browserCdpClient = browserCdpClient;
- this.#browsingContextStorage = browsingContextStorage;
- }
- getTree(params) {
- const resultContexts = params.root === undefined
- ? this.#browsingContextStorage.getTopLevelContexts()
- : [this.#browsingContextStorage.getContext(params.root)];
- return {
- contexts: resultContexts.map((c) => c.serializeToBidiValue(params.maxDepth ?? Number.MAX_VALUE)),
- };
- }
- async create(params) {
- let referenceContext;
- let userContext = 'default';
- if (params.referenceContext !== undefined) {
- referenceContext = this.#browsingContextStorage.getContext(params.referenceContext);
- if (!referenceContext.isTopLevelContext()) {
- throw new protocol_js_1$l.InvalidArgumentException(`referenceContext should be a top-level context`);
- }
- userContext = referenceContext.userContext;
- }
- if (params.userContext !== undefined) {
- userContext = params.userContext;
- }
- let newWindow = false;
- switch (params.type) {
- case "tab" /* BrowsingContext.CreateType.Tab */:
- newWindow = false;
- break;
- case "window" /* BrowsingContext.CreateType.Window */:
- newWindow = true;
- break;
- }
- if (userContext !== 'default') {
- const existingContexts = this.#browsingContextStorage
- .getAllContexts()
- .filter((context) => context.userContext === userContext);
- if (!existingContexts.length) {
- // If there are no contexts in the given user context, we need to set
- // newWindow to true as newWindow=false will be rejected.
- newWindow = true;
- }
- }
- let result;
- try {
- result = await this.#browserCdpClient.sendCommand('Target.createTarget', {
- url: 'about:blank',
- newWindow,
- browserContextId: userContext === 'default' ? undefined : userContext,
- });
- }
- catch (err) {
- if (
- // See https://source.chromium.org/chromium/chromium/src/+/main:chrome/browser/devtools/protocol/target_handler.cc;l=90;drc=e80392ac11e48a691f4309964cab83a3a59e01c8
- err.message.startsWith('Failed to find browser context with id') ||
- // See https://source.chromium.org/chromium/chromium/src/+/main:headless/lib/browser/protocol/target_handler.cc;l=49;drc=e80392ac11e48a691f4309964cab83a3a59e01c8
- err.message === 'browserContextId') {
- throw new protocol_js_1$l.NoSuchUserContextException(`The context ${userContext} was not found`);
- }
- throw err;
- }
- // Wait for the new tab to be loaded to avoid race conditions in the
- // `browsingContext` events, when the `browsingContext.domContentLoaded` and
- // `browsingContext.load` events from the initial `about:blank` navigation
- // are emitted after the next navigation is started.
- // Details: https://github.com/web-platform-tests/wpt/issues/35846
- const contextId = result.targetId;
- const context = this.#browsingContextStorage.getContext(contextId);
- await context.lifecycleLoaded();
- return { context: context.id };
- }
- navigate(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- return context.navigate(params.url, params.wait ?? "none" /* BrowsingContext.ReadinessState.None */);
- }
- reload(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- return context.reload(params.ignoreCache ?? false, params.wait ?? "none" /* BrowsingContext.ReadinessState.None */);
- }
- async activate(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- if (!context.isTopLevelContext()) {
- throw new protocol_js_1$l.InvalidArgumentException('Activation is only supported on the top-level context');
- }
- await context.activate();
- return {};
- }
- async captureScreenshot(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- return await context.captureScreenshot(params);
- }
- async print(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- return await context.print(params);
- }
- async setViewport(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- if (!context.isTopLevelContext()) {
- throw new protocol_js_1$l.InvalidArgumentException('Emulating viewport is only supported on the top-level context');
- }
- await context.setViewport(params.viewport, params.devicePixelRatio);
- return {};
- }
- async traverseHistory(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- if (!context) {
- throw new protocol_js_1$l.InvalidArgumentException(`No browsing context with id ${params.context}`);
- }
- await context.traverseHistory(params.delta);
- return {};
- }
- async handleUserPrompt(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- try {
- await context.handleUserPrompt(params);
- }
- catch (error) {
- // Heuristically determine the error
- // https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/protocol/page_handler.cc;l=1085?q=%22No%20dialog%20is%20showing%22&ss=chromium
- if (error.message?.includes('No dialog is showing')) {
- throw new protocol_js_1$l.NoSuchAlertException('No dialog is showing');
- }
- throw error;
- }
- return {};
- }
- async close(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- if (!context.isTopLevelContext()) {
- throw new protocol_js_1$l.InvalidArgumentException(`Non top-level browsing context ${context.id} cannot be closed.`);
- }
- try {
- const detachedFromTargetPromise = new Promise((resolve) => {
- const onContextDestroyed = (event) => {
- if (event.targetId === params.context) {
- this.#browserCdpClient.off('Target.detachedFromTarget', onContextDestroyed);
- resolve();
- }
- };
- this.#browserCdpClient.on('Target.detachedFromTarget', onContextDestroyed);
- });
- if (params.promptUnload) {
- await context.close();
- }
- else {
- await this.#browserCdpClient.sendCommand('Target.closeTarget', {
- targetId: params.context,
- });
- }
- // Sometimes CDP command finishes before `detachedFromTarget` event,
- // sometimes after. Wait for the CDP command to be finished, and then wait
- // for `detachedFromTarget` if it hasn't emitted.
- await detachedFromTargetPromise;
- }
- catch (error) {
- // Swallow error that arise from the page being destroyed
- // Example is navigating to faulty SSL certificate
- if (!(error.code === -32000 /* CdpErrorConstants.GENERIC_ERROR */ &&
- error.message === 'Not attached to an active page')) {
- throw error;
- }
- }
- return {};
- }
- async locateNodes(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- return await context.locateNodes(params);
- }
- }
- BrowsingContextProcessor$1.BrowsingContextProcessor = BrowsingContextProcessor;
- var InputProcessor$1 = {};
- var assert$1 = {};
- Object.defineProperty(assert$1, "__esModule", { value: true });
- assert$1.assert = void 0;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- function assert(predicate, message) {
- if (!predicate) {
- throw new Error(message ?? 'Internal assertion failed.');
- }
- }
- assert$1.assert = assert;
- var ActionDispatcher$1 = {};
- var InputSource = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(InputSource, "__esModule", { value: true });
- InputSource.WheelSource = InputSource.PointerSource = InputSource.KeySource = InputSource.NoneSource = void 0;
- class NoneSource {
- type = "none" /* SourceType.None */;
- }
- InputSource.NoneSource = NoneSource;
- class KeySource {
- type = "key" /* SourceType.Key */;
- pressed = new Set();
- // This is a bitfield that matches the modifiers parameter of
- // https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchKeyEvent
- #modifiers = 0;
- get modifiers() {
- return this.#modifiers;
- }
- get alt() {
- return (this.#modifiers & 1) === 1;
- }
- set alt(value) {
- this.#setModifier(value, 1);
- }
- get ctrl() {
- return (this.#modifiers & 2) === 2;
- }
- set ctrl(value) {
- this.#setModifier(value, 2);
- }
- get meta() {
- return (this.#modifiers & 4) === 4;
- }
- set meta(value) {
- this.#setModifier(value, 4);
- }
- get shift() {
- return (this.#modifiers & 8) === 8;
- }
- set shift(value) {
- this.#setModifier(value, 8);
- }
- #setModifier(value, bit) {
- if (value) {
- this.#modifiers |= bit;
- }
- else {
- this.#modifiers &= ~bit;
- }
- }
- }
- InputSource.KeySource = KeySource;
- class PointerSource {
- type = "pointer" /* SourceType.Pointer */;
- subtype;
- pointerId;
- pressed = new Set();
- x = 0;
- y = 0;
- constructor(id, subtype) {
- this.pointerId = id;
- this.subtype = subtype;
- }
- // This is a bitfield that matches the buttons parameter of
- // https://chromedevtools.github.io/devtools-protocol/tot/Input/#method-dispatchMouseEvent
- get buttons() {
- let buttons = 0;
- for (const button of this.pressed) {
- switch (button) {
- case 0:
- buttons |= 1;
- break;
- case 1:
- buttons |= 4;
- break;
- case 2:
- buttons |= 2;
- break;
- case 3:
- buttons |= 8;
- break;
- case 4:
- buttons |= 16;
- break;
- }
- }
- return buttons;
- }
- // --- Platform-specific code starts here ---
- // Input.dispatchMouseEvent doesn't know the concept of double click, so we
- // need to create the logic, similar to how it's done for OSes:
- // https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:ui/events/event.cc;l=479
- static ClickContext = class ClickContext {
- static #DOUBLE_CLICK_TIME_MS = 500;
- static #MAX_DOUBLE_CLICK_RADIUS = 2;
- count = 0;
- #x;
- #y;
- #time;
- constructor(x, y, time) {
- this.#x = x;
- this.#y = y;
- this.#time = time;
- }
- compare(context) {
- return (
- // The click needs to be within a certain amount of ms.
- context.#time - this.#time > ClickContext.#DOUBLE_CLICK_TIME_MS ||
- // The click needs to be within a certain square radius.
- Math.abs(context.#x - this.#x) >
- ClickContext.#MAX_DOUBLE_CLICK_RADIUS ||
- Math.abs(context.#y - this.#y) > ClickContext.#MAX_DOUBLE_CLICK_RADIUS);
- }
- };
- #clickContexts = new Map();
- setClickCount(button, context) {
- let storedContext = this.#clickContexts.get(button);
- if (!storedContext || storedContext.compare(context)) {
- storedContext = context;
- }
- ++storedContext.count;
- this.#clickContexts.set(button, storedContext);
- return storedContext.count;
- }
- getClickCount(button) {
- return this.#clickContexts.get(button)?.count ?? 0;
- }
- }
- InputSource.PointerSource = PointerSource;
- class WheelSource {
- type = "wheel" /* SourceType.Wheel */;
- }
- InputSource.WheelSource = WheelSource;
- var keyUtils = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(keyUtils, "__esModule", { value: true });
- keyUtils.getKeyLocation = keyUtils.getKeyCode = keyUtils.getNormalizedKey = void 0;
- function getNormalizedKey(value) {
- switch (value) {
- case '\uE000':
- return 'Unidentified';
- case '\uE001':
- return 'Cancel';
- case '\uE002':
- return 'Help';
- case '\uE003':
- return 'Backspace';
- case '\uE004':
- return 'Tab';
- case '\uE005':
- return 'Clear';
- case '\uE006':
- return 'Return';
- case '\uE007':
- return 'Enter';
- case '\uE008':
- return 'Shift';
- case '\uE009':
- return 'Control';
- case '\uE00A':
- return 'Alt';
- case '\uE00B':
- return 'Pause';
- case '\uE00C':
- return 'Escape';
- case '\uE00D':
- return ' ';
- case '\uE00E':
- return 'PageUp';
- case '\uE00F':
- return 'PageDown';
- case '\uE010':
- return 'End';
- case '\uE011':
- return 'Home';
- case '\uE012':
- return 'ArrowLeft';
- case '\uE013':
- return 'ArrowUp';
- case '\uE014':
- return 'ArrowRight';
- case '\uE015':
- return 'ArrowDown';
- case '\uE016':
- return 'Insert';
- case '\uE017':
- return 'Delete';
- case '\uE018':
- return ';';
- case '\uE019':
- return '=';
- case '\uE01A':
- return '0';
- case '\uE01B':
- return '1';
- case '\uE01C':
- return '2';
- case '\uE01D':
- return '3';
- case '\uE01E':
- return '4';
- case '\uE01F':
- return '5';
- case '\uE020':
- return '6';
- case '\uE021':
- return '7';
- case '\uE022':
- return '8';
- case '\uE023':
- return '9';
- case '\uE024':
- return '*';
- case '\uE025':
- return '+';
- case '\uE026':
- return ',';
- case '\uE027':
- return '-';
- case '\uE028':
- return '.';
- case '\uE029':
- return '/';
- case '\uE031':
- return 'F1';
- case '\uE032':
- return 'F2';
- case '\uE033':
- return 'F3';
- case '\uE034':
- return 'F4';
- case '\uE035':
- return 'F5';
- case '\uE036':
- return 'F6';
- case '\uE037':
- return 'F7';
- case '\uE038':
- return 'F8';
- case '\uE039':
- return 'F9';
- case '\uE03A':
- return 'F10';
- case '\uE03B':
- return 'F11';
- case '\uE03C':
- return 'F12';
- case '\uE03D':
- return 'Meta';
- case '\uE040':
- return 'ZenkakuHankaku';
- case '\uE050':
- return 'Shift';
- case '\uE051':
- return 'Control';
- case '\uE052':
- return 'Alt';
- case '\uE053':
- return 'Meta';
- case '\uE054':
- return 'PageUp';
- case '\uE055':
- return 'PageDown';
- case '\uE056':
- return 'End';
- case '\uE057':
- return 'Home';
- case '\uE058':
- return 'ArrowLeft';
- case '\uE059':
- return 'ArrowUp';
- case '\uE05A':
- return 'ArrowRight';
- case '\uE05B':
- return 'ArrowDown';
- case '\uE05C':
- return 'Insert';
- case '\uE05D':
- return 'Delete';
- default:
- return value;
- }
- }
- keyUtils.getNormalizedKey = getNormalizedKey;
- function getKeyCode(key) {
- switch (key) {
- case '`':
- case '~':
- return 'Backquote';
- case '\\':
- case '|':
- return 'Backslash';
- case '\uE003':
- return 'Backspace';
- case '[':
- case '{':
- return 'BracketLeft';
- case ']':
- case '}':
- return 'BracketRight';
- case ',':
- case '<':
- return 'Comma';
- case '0':
- case ')':
- return 'Digit0';
- case '1':
- case '!':
- return 'Digit1';
- case '2':
- case '@':
- return 'Digit2';
- case '3':
- case '#':
- return 'Digit3';
- case '4':
- case '$':
- return 'Digit4';
- case '5':
- case '%':
- return 'Digit5';
- case '6':
- case '^':
- return 'Digit6';
- case '7':
- case '&':
- return 'Digit7';
- case '8':
- case '*':
- return 'Digit8';
- case '9':
- case '(':
- return 'Digit9';
- case '=':
- case '+':
- return 'Equal';
- case 'a':
- case 'A':
- return 'KeyA';
- case 'b':
- case 'B':
- return 'KeyB';
- case 'c':
- case 'C':
- return 'KeyC';
- case 'd':
- case 'D':
- return 'KeyD';
- case 'e':
- case 'E':
- return 'KeyE';
- case 'f':
- case 'F':
- return 'KeyF';
- case 'g':
- case 'G':
- return 'KeyG';
- case 'h':
- case 'H':
- return 'KeyH';
- case 'i':
- case 'I':
- return 'KeyI';
- case 'j':
- case 'J':
- return 'KeyJ';
- case 'k':
- case 'K':
- return 'KeyK';
- case 'l':
- case 'L':
- return 'KeyL';
- case 'm':
- case 'M':
- return 'KeyM';
- case 'n':
- case 'N':
- return 'KeyN';
- case 'o':
- case 'O':
- return 'KeyO';
- case 'p':
- case 'P':
- return 'KeyP';
- case 'q':
- case 'Q':
- return 'KeyQ';
- case 'r':
- case 'R':
- return 'KeyR';
- case 's':
- case 'S':
- return 'KeyS';
- case 't':
- case 'T':
- return 'KeyT';
- case 'u':
- case 'U':
- return 'KeyU';
- case 'v':
- case 'V':
- return 'KeyV';
- case 'w':
- case 'W':
- return 'KeyW';
- case 'x':
- case 'X':
- return 'KeyX';
- case 'y':
- case 'Y':
- return 'KeyY';
- case 'z':
- case 'Z':
- return 'KeyZ';
- case '-':
- case '_':
- return 'Minus';
- case '.':
- return 'Period';
- case "'":
- case '"':
- return 'Quote';
- case ';':
- case ':':
- return 'Semicolon';
- case '/':
- case '?':
- return 'Slash';
- case '\uE00A':
- return 'AltLeft';
- case '\uE052':
- return 'AltRight';
- case '\uE009':
- return 'ControlLeft';
- case '\uE051':
- return 'ControlRight';
- case '\uE006':
- return 'Enter';
- case '\uE03D':
- return 'MetaLeft';
- case '\uE053':
- return 'MetaRight';
- case '\uE008':
- return 'ShiftLeft';
- case '\uE050':
- return 'ShiftRight';
- case ' ':
- case '\uE00D':
- return 'Space';
- case '\uE004':
- return 'Tab';
- case '\uE017':
- return 'Delete';
- case '\uE010':
- return 'End';
- case '\uE002':
- return 'Help';
- case '\uE011':
- return 'Home';
- case '\uE016':
- return 'Insert';
- case '\uE00F':
- return 'PageDown';
- case '\uE00E':
- return 'PageUp';
- case '\uE015':
- return 'ArrowDown';
- case '\uE012':
- return 'ArrowLeft';
- case '\uE014':
- return 'ArrowRight';
- case '\uE013':
- return 'ArrowUp';
- case '\uE00C':
- return 'Escape';
- case '\uE031':
- return 'F1';
- case '\uE032':
- return 'F2';
- case '\uE033':
- return 'F3';
- case '\uE034':
- return 'F4';
- case '\uE035':
- return 'F5';
- case '\uE036':
- return 'F6';
- case '\uE037':
- return 'F7';
- case '\uE038':
- return 'F8';
- case '\uE039':
- return 'F9';
- case '\uE03A':
- return 'F10';
- case '\uE03B':
- return 'F11';
- case '\uE03C':
- return 'F12';
- case '\uE01A':
- case '\uE05C':
- return 'Numpad0';
- case '\uE01B':
- case '\uE056':
- return 'Numpad1';
- case '\uE01C':
- case '\uE05B':
- return 'Numpad2';
- case '\uE01D':
- case '\uE055':
- return 'Numpad3';
- case '\uE01E':
- case '\uE058':
- return 'Numpad4';
- case '\uE01F':
- return 'Numpad5';
- case '\uE020':
- case '\uE05A':
- return 'Numpad6';
- case '\uE021':
- case '\uE057':
- return 'Numpad7';
- case '\uE022':
- case '\uE059':
- return 'Numpad8';
- case '\uE023':
- case '\uE054':
- return 'Numpad9';
- case '\uE025':
- return 'NumpadAdd';
- case '\uE026':
- return 'NumpadComma';
- case '\uE028':
- case '\uE05D':
- return 'NumpadDecimal';
- case '\uE029':
- return 'NumpadDivide';
- case '\uE007':
- return 'NumpadEnter';
- case '\uE024':
- return 'NumpadMultiply';
- case '\uE027':
- return 'NumpadSubtract';
- default:
- return;
- }
- }
- keyUtils.getKeyCode = getKeyCode;
- function getKeyLocation(key) {
- switch (key) {
- case '\uE007':
- case '\uE008':
- case '\uE009':
- case '\uE00A':
- case '\uE03D':
- return 1;
- case '\uE01A':
- case '\uE01B':
- case '\uE01C':
- case '\uE01D':
- case '\uE01E':
- case '\uE01F':
- case '\uE020':
- case '\uE021':
- case '\uE022':
- case '\uE023':
- case '\uE024':
- case '\uE025':
- case '\uE026':
- case '\uE027':
- case '\uE028':
- case '\uE029':
- case '\uE054':
- case '\uE055':
- case '\uE056':
- case '\uE057':
- case '\uE058':
- case '\uE059':
- case '\uE05A':
- case '\uE05B':
- case '\uE05C':
- case '\uE05D':
- return 3;
- case '\uE050':
- case '\uE051':
- case '\uE052':
- case '\uE053':
- return 2;
- default:
- return 0;
- }
- }
- keyUtils.getKeyLocation = getKeyLocation;
- var USKeyboardLayout = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(USKeyboardLayout, "__esModule", { value: true });
- USKeyboardLayout.KeyToKeyCode = void 0;
- // TODO: Remove this once https://crrev.com/c/4548290 is stably in Chromium.
- // `Input.dispatchKeyboardEvent` will automatically handle these conversions.
- USKeyboardLayout.KeyToKeyCode = {
- '0': 48,
- '1': 49,
- '2': 50,
- '3': 51,
- '4': 52,
- '5': 53,
- '6': 54,
- '7': 55,
- '8': 56,
- '9': 57,
- Abort: 3,
- Help: 6,
- Backspace: 8,
- Tab: 9,
- Numpad5: 12,
- NumpadEnter: 13,
- Enter: 13,
- '\\r': 13,
- '\\n': 13,
- ShiftLeft: 16,
- ShiftRight: 16,
- ControlLeft: 17,
- ControlRight: 17,
- AltLeft: 18,
- AltRight: 18,
- Pause: 19,
- CapsLock: 20,
- Escape: 27,
- Convert: 28,
- NonConvert: 29,
- Space: 32,
- Numpad9: 33,
- PageUp: 33,
- Numpad3: 34,
- PageDown: 34,
- End: 35,
- Numpad1: 35,
- Home: 36,
- Numpad7: 36,
- ArrowLeft: 37,
- Numpad4: 37,
- Numpad8: 38,
- ArrowUp: 38,
- ArrowRight: 39,
- Numpad6: 39,
- Numpad2: 40,
- ArrowDown: 40,
- Select: 41,
- Open: 43,
- PrintScreen: 44,
- Insert: 45,
- Numpad0: 45,
- Delete: 46,
- NumpadDecimal: 46,
- Digit0: 48,
- Digit1: 49,
- Digit2: 50,
- Digit3: 51,
- Digit4: 52,
- Digit5: 53,
- Digit6: 54,
- Digit7: 55,
- Digit8: 56,
- Digit9: 57,
- KeyA: 65,
- KeyB: 66,
- KeyC: 67,
- KeyD: 68,
- KeyE: 69,
- KeyF: 70,
- KeyG: 71,
- KeyH: 72,
- KeyI: 73,
- KeyJ: 74,
- KeyK: 75,
- KeyL: 76,
- KeyM: 77,
- KeyN: 78,
- KeyO: 79,
- KeyP: 80,
- KeyQ: 81,
- KeyR: 82,
- KeyS: 83,
- KeyT: 84,
- KeyU: 85,
- KeyV: 86,
- KeyW: 87,
- KeyX: 88,
- KeyY: 89,
- KeyZ: 90,
- MetaLeft: 91,
- MetaRight: 92,
- ContextMenu: 93,
- NumpadMultiply: 106,
- NumpadAdd: 107,
- NumpadSubtract: 109,
- NumpadDivide: 111,
- F1: 112,
- F2: 113,
- F3: 114,
- F4: 115,
- F5: 116,
- F6: 117,
- F7: 118,
- F8: 119,
- F9: 120,
- F10: 121,
- F11: 122,
- F12: 123,
- F13: 124,
- F14: 125,
- F15: 126,
- F16: 127,
- F17: 128,
- F18: 129,
- F19: 130,
- F20: 131,
- F21: 132,
- F22: 133,
- F23: 134,
- F24: 135,
- NumLock: 144,
- ScrollLock: 145,
- AudioVolumeMute: 173,
- AudioVolumeDown: 174,
- AudioVolumeUp: 175,
- MediaTrackNext: 176,
- MediaTrackPrevious: 177,
- MediaStop: 178,
- MediaPlayPause: 179,
- Semicolon: 186,
- Equal: 187,
- NumpadEqual: 187,
- Comma: 188,
- Minus: 189,
- Period: 190,
- Slash: 191,
- Backquote: 192,
- BracketLeft: 219,
- Backslash: 220,
- BracketRight: 221,
- Quote: 222,
- AltGraph: 225,
- Props: 247,
- Cancel: 3,
- Clear: 12,
- Shift: 16,
- Control: 17,
- Alt: 18,
- Accept: 30,
- ModeChange: 31,
- ' ': 32,
- Print: 42,
- Execute: 43,
- '\\u0000': 46,
- a: 65,
- b: 66,
- c: 67,
- d: 68,
- e: 69,
- f: 70,
- g: 71,
- h: 72,
- i: 73,
- j: 74,
- k: 75,
- l: 76,
- m: 77,
- n: 78,
- o: 79,
- p: 80,
- q: 81,
- r: 82,
- s: 83,
- t: 84,
- u: 85,
- v: 86,
- w: 87,
- x: 88,
- y: 89,
- z: 90,
- Meta: 91,
- '*': 106,
- '+': 107,
- '-': 109,
- '/': 111,
- ';': 186,
- '=': 187,
- ',': 188,
- '.': 190,
- '`': 192,
- '[': 219,
- '\\\\': 220,
- ']': 221,
- "'": 222,
- Attn: 246,
- CrSel: 247,
- ExSel: 248,
- EraseEof: 249,
- Play: 250,
- ZoomOut: 251,
- ')': 48,
- '!': 49,
- '@': 50,
- '#': 51,
- $: 52,
- '%': 53,
- '^': 54,
- '&': 55,
- '(': 57,
- A: 65,
- B: 66,
- C: 67,
- D: 68,
- E: 69,
- F: 70,
- G: 71,
- H: 72,
- I: 73,
- J: 74,
- K: 75,
- L: 76,
- M: 77,
- N: 78,
- O: 79,
- P: 80,
- Q: 81,
- R: 82,
- S: 83,
- T: 84,
- U: 85,
- V: 86,
- W: 87,
- X: 88,
- Y: 89,
- Z: 90,
- ':': 186,
- '<': 188,
- _: 189,
- '>': 190,
- '?': 191,
- '~': 192,
- '{': 219,
- '|': 220,
- '}': 221,
- '"': 222,
- Camera: 44,
- EndCall: 95,
- VolumeDown: 182,
- VolumeUp: 183,
- };
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(ActionDispatcher$1, "__esModule", { value: true });
- ActionDispatcher$1.ActionDispatcher = void 0;
- const protocol_js_1$k = protocol;
- const assert_js_1$6 = assert$1;
- const InputSource_js_1$1 = InputSource;
- const keyUtils_js_1 = keyUtils;
- const USKeyboardLayout_js_1 = USKeyboardLayout;
- /** https://w3c.github.io/webdriver/#dfn-center-point */
- const CALCULATE_IN_VIEW_CENTER_PT_DECL = ((i) => {
- const t = i.getClientRects()[0], e = Math.max(0, Math.min(t.x, t.x + t.width)), n = Math.min(window.innerWidth, Math.max(t.x, t.x + t.width)), h = Math.max(0, Math.min(t.y, t.y + t.height)), m = Math.min(window.innerHeight, Math.max(t.y, t.y + t.height));
- return [e + ((n - e) >> 1), h + ((m - h) >> 1)];
- }).toString();
- const IS_MAC_DECL = (() => {
- return navigator.platform.toLowerCase().includes('mac');
- }).toString();
- async function getElementCenter(context, element) {
- const sandbox = await context.getOrCreateSandbox(undefined);
- const result = await sandbox.callFunction(CALCULATE_IN_VIEW_CENTER_PT_DECL, false, { type: 'undefined' }, [element]);
- if (result.type === 'exception') {
- throw new protocol_js_1$k.NoSuchElementException(`Origin element ${element.sharedId} was not found`);
- }
- (0, assert_js_1$6.assert)(result.result.type === 'array');
- (0, assert_js_1$6.assert)(result.result.value?.[0]?.type === 'number');
- (0, assert_js_1$6.assert)(result.result.value?.[1]?.type === 'number');
- const { result: { value: [{ value: x }, { value: y }], }, } = result;
- return { x: x, y: y };
- }
- class ActionDispatcher {
- static isMacOS = async (context) => {
- const result = await (await context.getOrCreateSandbox(undefined)).callFunction(IS_MAC_DECL, false);
- (0, assert_js_1$6.assert)(result.type !== 'exception');
- (0, assert_js_1$6.assert)(result.result.type === 'boolean');
- return result.result.value;
- };
- #tickStart = 0;
- #tickDuration = 0;
- #inputState;
- #context;
- #isMacOS;
- constructor(inputState, context, isMacOS) {
- this.#inputState = inputState;
- this.#context = context;
- this.#isMacOS = isMacOS;
- }
- async dispatchActions(optionsByTick) {
- await this.#inputState.queue.run(async () => {
- for (const options of optionsByTick) {
- await this.dispatchTickActions(options);
- }
- });
- }
- async dispatchTickActions(options) {
- this.#tickStart = performance.now();
- this.#tickDuration = 0;
- for (const { action } of options) {
- if ('duration' in action && action.duration !== undefined) {
- this.#tickDuration = Math.max(this.#tickDuration, action.duration);
- }
- }
- const promises = [
- new Promise((resolve) => setTimeout(resolve, this.#tickDuration)),
- ];
- for (const option of options) {
- // In theory we have to wait for each action to happen, but CDP is serial,
- // so as an optimization, we queue all CDP commands at once and await all
- // of them.
- promises.push(this.#dispatchAction(option));
- }
- await Promise.all(promises);
- }
- async #dispatchAction({ id, action }) {
- const source = this.#inputState.get(id);
- const keyState = this.#inputState.getGlobalKeyState();
- switch (action.type) {
- case 'keyDown': {
- // SAFETY: The source is validated before.
- await this.#dispatchKeyDownAction(source, action);
- this.#inputState.cancelList.push({
- id,
- action: {
- ...action,
- type: 'keyUp',
- },
- });
- break;
- }
- case 'keyUp': {
- // SAFETY: The source is validated before.
- await this.#dispatchKeyUpAction(source, action);
- break;
- }
- case 'pause': {
- // TODO: Implement waiting on the input source.
- break;
- }
- case 'pointerDown': {
- // SAFETY: The source is validated before.
- await this.#dispatchPointerDownAction(source, keyState, action);
- this.#inputState.cancelList.push({
- id,
- action: {
- ...action,
- type: 'pointerUp',
- },
- });
- break;
- }
- case 'pointerMove': {
- // SAFETY: The source is validated before.
- await this.#dispatchPointerMoveAction(source, keyState, action);
- break;
- }
- case 'pointerUp': {
- // SAFETY: The source is validated before.
- await this.#dispatchPointerUpAction(source, keyState, action);
- break;
- }
- case 'scroll': {
- // SAFETY: The source is validated before.
- await this.#dispatchScrollAction(source, keyState, action);
- break;
- }
- }
- }
- #dispatchPointerDownAction(source, keyState, action) {
- const { button } = action;
- if (source.pressed.has(button)) {
- return;
- }
- source.pressed.add(button);
- const { x, y, subtype: pointerType } = source;
- const { width, height, pressure, twist, tangentialPressure } = action;
- const { tiltX, tiltY } = getTilt(action);
- // --- Platform-specific code begins here ---
- const { modifiers } = keyState;
- switch (pointerType) {
- case "mouse" /* Input.PointerType.Mouse */:
- case "pen" /* Input.PointerType.Pen */:
- // TODO: Implement width and height when available.
- return this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchMouseEvent', {
- type: 'mousePressed',
- x,
- y,
- modifiers,
- button: getCdpButton(button),
- buttons: source.buttons,
- clickCount: source.setClickCount(button, new InputSource_js_1$1.PointerSource.ClickContext(x, y, performance.now())),
- pointerType,
- tangentialPressure,
- tiltX,
- tiltY,
- twist,
- force: pressure,
- });
- case "touch" /* Input.PointerType.Touch */:
- return this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchTouchEvent', {
- type: 'touchStart',
- touchPoints: [
- {
- x,
- y,
- ...getRadii(width ?? 1, height ?? 1),
- tangentialPressure,
- tiltX,
- tiltY,
- twist,
- force: pressure,
- id: source.pointerId,
- },
- ],
- modifiers,
- });
- }
- // --- Platform-specific code ends here ---
- }
- #dispatchPointerUpAction(source, keyState, action) {
- const { button } = action;
- if (!source.pressed.has(button)) {
- return;
- }
- source.pressed.delete(button);
- const { x, y, subtype: pointerType } = source;
- // --- Platform-specific code begins here ---
- const { modifiers } = keyState;
- switch (pointerType) {
- case "mouse" /* Input.PointerType.Mouse */:
- case "pen" /* Input.PointerType.Pen */:
- // TODO: Implement width and height when available.
- return this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchMouseEvent', {
- type: 'mouseReleased',
- x,
- y,
- modifiers,
- button: getCdpButton(button),
- buttons: source.buttons,
- clickCount: source.getClickCount(button),
- pointerType,
- });
- case "touch" /* Input.PointerType.Touch */:
- return this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchTouchEvent', {
- type: 'touchEnd',
- touchPoints: [
- {
- x,
- y,
- id: source.pointerId,
- },
- ],
- modifiers,
- });
- }
- // --- Platform-specific code ends here ---
- }
- async #dispatchPointerMoveAction(source, keyState, action) {
- const { x: startX, y: startY, subtype: pointerType } = source;
- const { width, height, pressure, twist, tangentialPressure, x: offsetX, y: offsetY, origin = 'viewport', duration = this.#tickDuration, } = action;
- const { tiltX, tiltY } = getTilt(action);
- const { targetX, targetY } = await this.#getCoordinateFromOrigin(origin, offsetX, offsetY, startX, startY);
- if (targetX < 0 || targetY < 0) {
- throw new protocol_js_1$k.MoveTargetOutOfBoundsException(`Cannot move beyond viewport (x: ${targetX}, y: ${targetY})`);
- }
- let last;
- do {
- const ratio = duration > 0 ? (performance.now() - this.#tickStart) / duration : 1;
- last = ratio >= 1;
- let x;
- let y;
- if (last) {
- x = targetX;
- y = targetY;
- }
- else {
- x = Math.round(ratio * (targetX - startX) + startX);
- y = Math.round(ratio * (targetY - startY) + startY);
- }
- if (source.x !== x || source.y !== y) {
- // --- Platform-specific code begins here ---
- const { modifiers } = keyState;
- switch (pointerType) {
- case "mouse" /* Input.PointerType.Mouse */:
- // TODO: Implement width and height when available.
- await this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchMouseEvent', {
- type: 'mouseMoved',
- x,
- y,
- modifiers,
- clickCount: 0,
- button: getCdpButton(source.pressed.values().next().value ?? 5),
- buttons: source.buttons,
- pointerType,
- tangentialPressure,
- tiltX,
- tiltY,
- twist,
- force: pressure,
- });
- break;
- case "pen" /* Input.PointerType.Pen */:
- if (source.pressed.size !== 0) {
- // TODO: Implement width and height when available.
- await this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchMouseEvent', {
- type: 'mouseMoved',
- x,
- y,
- modifiers,
- clickCount: 0,
- button: getCdpButton(source.pressed.values().next().value ?? 5),
- buttons: source.buttons,
- pointerType,
- tangentialPressure,
- tiltX,
- tiltY,
- twist,
- force: pressure,
- });
- }
- break;
- case "touch" /* Input.PointerType.Touch */:
- if (source.pressed.size !== 0) {
- await this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchTouchEvent', {
- type: 'touchMove',
- touchPoints: [
- {
- x,
- y,
- ...getRadii(width ?? 1, height ?? 1),
- tangentialPressure,
- tiltX,
- tiltY,
- twist,
- force: pressure,
- id: source.pointerId,
- },
- ],
- modifiers,
- });
- }
- break;
- }
- // --- Platform-specific code ends here ---
- source.x = x;
- source.y = y;
- }
- } while (!last);
- }
- async #getCoordinateFromOrigin(origin, offsetX, offsetY, startX, startY) {
- let targetX;
- let targetY;
- switch (origin) {
- case 'viewport':
- targetX = offsetX;
- targetY = offsetY;
- break;
- case 'pointer':
- targetX = startX + offsetX;
- targetY = startY + offsetY;
- break;
- default: {
- const { x: posX, y: posY } = await getElementCenter(this.#context, origin.element);
- // SAFETY: These can never be special numbers.
- targetX = posX + offsetX;
- targetY = posY + offsetY;
- break;
- }
- }
- return { targetX, targetY };
- }
- async #dispatchScrollAction(_source, keyState, action) {
- const { deltaX: targetDeltaX, deltaY: targetDeltaY, x: offsetX, y: offsetY, origin = 'viewport', duration = this.#tickDuration, } = action;
- if (origin === 'pointer') {
- throw new protocol_js_1$k.InvalidArgumentException('"pointer" origin is invalid for scrolling.');
- }
- const { targetX, targetY } = await this.#getCoordinateFromOrigin(origin, offsetX, offsetY, 0, 0);
- if (targetX < 0 || targetY < 0) {
- throw new protocol_js_1$k.MoveTargetOutOfBoundsException(`Cannot move beyond viewport (x: ${targetX}, y: ${targetY})`);
- }
- let currentDeltaX = 0;
- let currentDeltaY = 0;
- let last;
- do {
- const ratio = duration > 0 ? (performance.now() - this.#tickStart) / duration : 1;
- last = ratio >= 1;
- let deltaX;
- let deltaY;
- if (last) {
- deltaX = targetDeltaX - currentDeltaX;
- deltaY = targetDeltaY - currentDeltaY;
- }
- else {
- deltaX = Math.round(ratio * targetDeltaX - currentDeltaX);
- deltaY = Math.round(ratio * targetDeltaY - currentDeltaY);
- }
- if (deltaX !== 0 || deltaY !== 0) {
- // --- Platform-specific code begins here ---
- const { modifiers } = keyState;
- await this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchMouseEvent', {
- type: 'mouseWheel',
- deltaX,
- deltaY,
- x: targetX,
- y: targetY,
- modifiers,
- });
- // --- Platform-specific code ends here ---
- currentDeltaX += deltaX;
- currentDeltaY += deltaY;
- }
- } while (!last);
- }
- async #dispatchKeyDownAction(source, action) {
- if ([...action.value].length > 1) {
- throw new protocol_js_1$k.InvalidArgumentException(`Invalid key value: ${action.value}`);
- }
- const rawKey = action.value;
- const key = (0, keyUtils_js_1.getNormalizedKey)(rawKey);
- const repeat = source.pressed.has(key);
- const code = (0, keyUtils_js_1.getKeyCode)(rawKey);
- const location = (0, keyUtils_js_1.getKeyLocation)(rawKey);
- switch (key) {
- case 'Alt':
- source.alt = true;
- break;
- case 'Shift':
- source.shift = true;
- break;
- case 'Control':
- source.ctrl = true;
- break;
- case 'Meta':
- source.meta = true;
- break;
- }
- source.pressed.add(key);
- const { modifiers } = source;
- // --- Platform-specific code begins here ---
- // The spread is a little hack so JS gives us an array of unicode characters
- // to measure.
- const unmodifiedText = getKeyEventUnmodifiedText(key, source);
- const text = getKeyEventText(code ?? '', source) ?? unmodifiedText;
- let command;
- // The following commands need to be declared because Chromium doesn't
- // handle them. See
- // https://source.chromium.org/chromium/chromium/src/+/refs/heads/main:third_party/blink/renderer/core/editing/editing_behavior.cc;l=169;drc=b8143cf1dfd24842890fcd831c4f5d909bef4fc4;bpv=0;bpt=1.
- if (this.#isMacOS && source.meta) {
- switch (code) {
- case 'KeyA':
- command = 'SelectAll';
- break;
- case 'KeyC':
- command = 'Copy';
- break;
- case 'KeyV':
- command = source.shift ? 'PasteAndMatchStyle' : 'Paste';
- break;
- case 'KeyX':
- command = 'Cut';
- break;
- case 'KeyZ':
- command = source.shift ? 'Redo' : 'Undo';
- break;
- // Intentionally empty.
- }
- }
- const promises = [
- this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchKeyEvent', {
- type: text ? 'keyDown' : 'rawKeyDown',
- windowsVirtualKeyCode: USKeyboardLayout_js_1.KeyToKeyCode[key],
- key,
- code,
- text,
- unmodifiedText,
- autoRepeat: repeat,
- isSystemKey: source.alt || undefined,
- location: location < 3 ? location : undefined,
- isKeypad: location === 3,
- modifiers,
- commands: command ? [command] : undefined,
- }),
- ];
- // Drag cancelling happens on escape.
- if (key === 'Escape') {
- if (!source.alt &&
- ((this.#isMacOS && !source.ctrl && !source.meta) || !this.#isMacOS)) {
- promises.push(this.#context.cdpTarget.cdpClient.sendCommand('Input.cancelDragging'));
- }
- }
- await Promise.all(promises);
- // --- Platform-specific code ends here ---
- }
- #dispatchKeyUpAction(source, action) {
- if ([...action.value].length > 1) {
- throw new protocol_js_1$k.InvalidArgumentException(`Invalid key value: ${action.value}`);
- }
- const rawKey = action.value;
- const key = (0, keyUtils_js_1.getNormalizedKey)(rawKey);
- if (!source.pressed.has(key)) {
- return;
- }
- const code = (0, keyUtils_js_1.getKeyCode)(rawKey);
- const location = (0, keyUtils_js_1.getKeyLocation)(rawKey);
- switch (key) {
- case 'Alt':
- source.alt = false;
- break;
- case 'Shift':
- source.shift = false;
- break;
- case 'Control':
- source.ctrl = false;
- break;
- case 'Meta':
- source.meta = false;
- break;
- }
- source.pressed.delete(key);
- const { modifiers } = source;
- // --- Platform-specific code begins here ---
- // The spread is a little hack so JS gives us an array of unicode characters
- // to measure.
- const unmodifiedText = getKeyEventUnmodifiedText(key, source);
- const text = getKeyEventText(code ?? '', source) ?? unmodifiedText;
- return this.#context.cdpTarget.cdpClient.sendCommand('Input.dispatchKeyEvent', {
- type: 'keyUp',
- windowsVirtualKeyCode: USKeyboardLayout_js_1.KeyToKeyCode[key],
- key,
- code,
- text,
- unmodifiedText,
- location: location < 3 ? location : undefined,
- isSystemKey: source.alt || undefined,
- isKeypad: location === 3,
- modifiers,
- });
- // --- Platform-specific code ends here ---
- }
- }
- ActionDispatcher$1.ActionDispatcher = ActionDispatcher;
- const getKeyEventUnmodifiedText = (key, source) => {
- if (key === 'Enter') {
- return '\r';
- }
- return [...key].length === 1
- ? source.shift
- ? key.toLocaleUpperCase('en-US')
- : key
- : undefined;
- };
- const getKeyEventText = (code, source) => {
- if (source.ctrl) {
- switch (code) {
- case 'Digit2':
- if (source.shift) {
- return '\x00';
- }
- break;
- case 'KeyA':
- return '\x01';
- case 'KeyB':
- return '\x02';
- case 'KeyC':
- return '\x03';
- case 'KeyD':
- return '\x04';
- case 'KeyE':
- return '\x05';
- case 'KeyF':
- return '\x06';
- case 'KeyG':
- return '\x07';
- case 'KeyH':
- return '\x08';
- case 'KeyI':
- return '\x09';
- case 'KeyJ':
- return '\x0A';
- case 'KeyK':
- return '\x0B';
- case 'KeyL':
- return '\x0C';
- case 'KeyM':
- return '\x0D';
- case 'KeyN':
- return '\x0E';
- case 'KeyO':
- return '\x0F';
- case 'KeyP':
- return '\x10';
- case 'KeyQ':
- return '\x11';
- case 'KeyR':
- return '\x12';
- case 'KeyS':
- return '\x13';
- case 'KeyT':
- return '\x14';
- case 'KeyU':
- return '\x15';
- case 'KeyV':
- return '\x16';
- case 'KeyW':
- return '\x17';
- case 'KeyX':
- return '\x18';
- case 'KeyY':
- return '\x19';
- case 'KeyZ':
- return '\x1A';
- case 'BracketLeft':
- return '\x1B';
- case 'Backslash':
- return '\x1C';
- case 'BracketRight':
- return '\x1D';
- case 'Digit6':
- if (source.shift) {
- return '\x1E';
- }
- break;
- case 'Minus':
- return '\x1F';
- }
- return '';
- }
- if (source.alt) {
- return '';
- }
- return;
- };
- function getCdpButton(button) {
- switch (button) {
- case 0:
- return 'left';
- case 1:
- return 'middle';
- case 2:
- return 'right';
- case 3:
- return 'back';
- case 4:
- return 'forward';
- default:
- return 'none';
- }
- }
- function getTilt(action) {
- // https://w3c.github.io/pointerevents/#converting-between-tiltx-tilty-and-altitudeangle-azimuthangle
- const altitudeAngle = action.altitudeAngle ?? 0;
- const azimuthAngle = action.azimuthAngle ?? 0;
- let tiltXRadians = 0;
- let tiltYRadians = 0;
- if (altitudeAngle === 0) {
- // the pen is in the X-Y plane
- if (azimuthAngle === 0 || azimuthAngle === 2 * Math.PI) {
- // pen is on positive X axis
- tiltXRadians = Math.PI / 2;
- }
- if (azimuthAngle === Math.PI / 2) {
- // pen is on positive Y axis
- tiltYRadians = Math.PI / 2;
- }
- if (azimuthAngle === Math.PI) {
- // pen is on negative X axis
- tiltXRadians = -Math.PI / 2;
- }
- if (azimuthAngle === (3 * Math.PI) / 2) {
- // pen is on negative Y axis
- tiltYRadians = -Math.PI / 2;
- }
- if (azimuthAngle > 0 && azimuthAngle < Math.PI / 2) {
- tiltXRadians = Math.PI / 2;
- tiltYRadians = Math.PI / 2;
- }
- if (azimuthAngle > Math.PI / 2 && azimuthAngle < Math.PI) {
- tiltXRadians = -Math.PI / 2;
- tiltYRadians = Math.PI / 2;
- }
- if (azimuthAngle > Math.PI && azimuthAngle < (3 * Math.PI) / 2) {
- tiltXRadians = -Math.PI / 2;
- tiltYRadians = -Math.PI / 2;
- }
- if (azimuthAngle > (3 * Math.PI) / 2 && azimuthAngle < 2 * Math.PI) {
- tiltXRadians = Math.PI / 2;
- tiltYRadians = -Math.PI / 2;
- }
- }
- if (altitudeAngle !== 0) {
- const tanAlt = Math.tan(altitudeAngle);
- tiltXRadians = Math.atan(Math.cos(azimuthAngle) / tanAlt);
- tiltYRadians = Math.atan(Math.sin(azimuthAngle) / tanAlt);
- }
- const factor = 180 / Math.PI;
- return {
- tiltX: Math.round(tiltXRadians * factor),
- tiltY: Math.round(tiltYRadians * factor),
- };
- }
- function getRadii(width, height) {
- return {
- radiusX: width ? width / 2 : 0.5,
- radiusY: height ? height / 2 : 0.5,
- };
- }
- var InputStateManager$1 = {};
- var InputState$1 = {};
- var Mutex$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- * Copyright 2022 The Chromium Authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(Mutex$1, "__esModule", { value: true });
- Mutex$1.Mutex = void 0;
- /**
- * Use Mutex class to coordinate local concurrent operations.
- * Once `acquire` promise resolves, you hold the lock and must
- * call `release` function returned by `acquire` to release the
- * lock. Failing to `release` the lock may lead to deadlocks.
- */
- class Mutex {
- #locked = false;
- #acquirers = [];
- // This is FIFO.
- acquire() {
- const state = { resolved: false };
- if (this.#locked) {
- return new Promise((resolve) => {
- this.#acquirers.push(() => resolve(this.#release.bind(this, state)));
- });
- }
- this.#locked = true;
- return Promise.resolve(this.#release.bind(this, state));
- }
- #release(state) {
- if (state.resolved) {
- throw new Error('Cannot release more than once.');
- }
- state.resolved = true;
- const resolve = this.#acquirers.shift();
- if (!resolve) {
- this.#locked = false;
- return;
- }
- resolve();
- }
- async run(action) {
- const release = await this.acquire();
- try {
- // Note we need to await here because we want the await to release AFTER
- // that await happens. Returning action() will trigger the release
- // immediately which is counter to what we want.
- const result = await action();
- return result;
- }
- finally {
- release();
- }
- }
- }
- Mutex$1.Mutex = Mutex;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(InputState$1, "__esModule", { value: true });
- InputState$1.InputState = void 0;
- const protocol_js_1$j = protocol;
- const Mutex_js_1 = Mutex$1;
- const InputSource_js_1 = InputSource;
- class InputState {
- cancelList = [];
- #sources = new Map();
- #mutex = new Mutex_js_1.Mutex();
- getOrCreate(id, type, subtype) {
- let source = this.#sources.get(id);
- if (!source) {
- switch (type) {
- case "none" /* SourceType.None */:
- source = new InputSource_js_1.NoneSource();
- break;
- case "key" /* SourceType.Key */:
- source = new InputSource_js_1.KeySource();
- break;
- case "pointer" /* SourceType.Pointer */: {
- let pointerId = subtype === "mouse" /* Input.PointerType.Mouse */ ? 0 : 2;
- const pointerIds = new Set();
- for (const [, source] of this.#sources) {
- if (source.type === "pointer" /* SourceType.Pointer */) {
- pointerIds.add(source.pointerId);
- }
- }
- while (pointerIds.has(pointerId)) {
- ++pointerId;
- }
- source = new InputSource_js_1.PointerSource(pointerId, subtype);
- break;
- }
- case "wheel" /* SourceType.Wheel */:
- source = new InputSource_js_1.WheelSource();
- break;
- default:
- throw new protocol_js_1$j.InvalidArgumentException(`Expected "${"none" /* SourceType.None */}", "${"key" /* SourceType.Key */}", "${"pointer" /* SourceType.Pointer */}", or "${"wheel" /* SourceType.Wheel */}". Found unknown source type ${type}.`);
- }
- this.#sources.set(id, source);
- return source;
- }
- if (source.type !== type) {
- throw new protocol_js_1$j.InvalidArgumentException(`Input source type of ${id} is ${source.type}, but received ${type}.`);
- }
- return source;
- }
- get(id) {
- const source = this.#sources.get(id);
- if (!source) {
- throw new protocol_js_1$j.UnknownErrorException(`Internal error.`);
- }
- return source;
- }
- getGlobalKeyState() {
- const state = new InputSource_js_1.KeySource();
- for (const [, source] of this.#sources) {
- if (source.type !== "key" /* SourceType.Key */) {
- continue;
- }
- for (const pressed of source.pressed) {
- state.pressed.add(pressed);
- }
- state.alt ||= source.alt;
- state.ctrl ||= source.ctrl;
- state.meta ||= source.meta;
- state.shift ||= source.shift;
- }
- return state;
- }
- get queue() {
- return this.#mutex;
- }
- }
- InputState$1.InputState = InputState;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(InputStateManager$1, "__esModule", { value: true });
- InputStateManager$1.InputStateManager = void 0;
- const assert_js_1$5 = assert$1;
- const InputState_js_1 = InputState$1;
- // We use a weak map here as specified here:
- // https://www.w3.org/TR/webdriver/#dfn-browsing-context-input-state-map
- class InputStateManager extends WeakMap {
- get(context) {
- (0, assert_js_1$5.assert)(context.isTopLevelContext());
- if (!this.has(context)) {
- this.set(context, new InputState_js_1.InputState());
- }
- return super.get(context);
- }
- }
- InputStateManager$1.InputStateManager = InputStateManager;
- Object.defineProperty(InputProcessor$1, "__esModule", { value: true });
- InputProcessor$1.InputProcessor = void 0;
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const protocol_js_1$i = protocol;
- const assert_js_1$4 = assert$1;
- const ActionDispatcher_js_1 = ActionDispatcher$1;
- const InputStateManager_js_1 = InputStateManager$1;
- class InputProcessor {
- #browsingContextStorage;
- #realmStorage;
- #inputStateManager = new InputStateManager_js_1.InputStateManager();
- constructor(browsingContextStorage, realmStorage) {
- this.#browsingContextStorage = browsingContextStorage;
- this.#realmStorage = realmStorage;
- }
- async performActions(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- const inputState = this.#inputStateManager.get(context.top);
- const actionsByTick = this.#getActionsByTick(params, inputState);
- const dispatcher = new ActionDispatcher_js_1.ActionDispatcher(inputState, context, await ActionDispatcher_js_1.ActionDispatcher.isMacOS(context).catch(() => false));
- await dispatcher.dispatchActions(actionsByTick);
- return {};
- }
- async releaseActions(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- const topContext = context.top;
- const inputState = this.#inputStateManager.get(topContext);
- const dispatcher = new ActionDispatcher_js_1.ActionDispatcher(inputState, context, await ActionDispatcher_js_1.ActionDispatcher.isMacOS(context).catch(() => false));
- await dispatcher.dispatchTickActions(inputState.cancelList.reverse());
- this.#inputStateManager.delete(topContext);
- return {};
- }
- async setFiles(params) {
- const context = this.#browsingContextStorage.getContext(params.context);
- const realm = await context.getOrCreateSandbox(undefined);
- let result;
- try {
- result = await realm.callFunction(String(function getFiles(fileListLength) {
- if (!(this instanceof HTMLInputElement)) {
- return 0 /* ErrorCode.Object */;
- }
- if (this.type !== 'file') {
- return 1 /* ErrorCode.Type */;
- }
- if (this.disabled) {
- return 2 /* ErrorCode.Disabled */;
- }
- if (fileListLength > 1 && !this.multiple) {
- return 3 /* ErrorCode.Multiple */;
- }
- return;
- }), false, params.element, [{ type: 'number', value: params.files.length }]);
- }
- catch {
- throw new protocol_js_1$i.NoSuchElementException(`Could not find element ${params.element.sharedId}`);
- }
- (0, assert_js_1$4.assert)(result.type === 'success');
- if (result.result.type === 'number') {
- switch (result.result.value) {
- case 0 /* ErrorCode.Object */: {
- throw new protocol_js_1$i.NoSuchElementException(`Could not find element ${params.element.sharedId}`);
- }
- case 1 /* ErrorCode.Type */: {
- throw new protocol_js_1$i.UnableToSetFileInputException(`Element ${params.element.sharedId} is not a file input`);
- }
- case 2 /* ErrorCode.Disabled */: {
- throw new protocol_js_1$i.UnableToSetFileInputException(`Input element ${params.element.sharedId} is disabled`);
- }
- case 3 /* ErrorCode.Multiple */: {
- throw new protocol_js_1$i.UnableToSetFileInputException(`Cannot set multiple files on a non-multiple input element`);
- }
- }
- }
- /**
- * The zero-length array is a special case, it seems that
- * DOM.setFileInputFiles does not actually update the files in that case, so
- * the solution is to eval the element value to a new FileList directly.
- */
- if (params.files.length === 0) {
- // XXX: These events should converted to trusted events. Perhaps do this
- // in `DOM.setFileInputFiles`?
- await realm.callFunction(String(function dispatchEvent() {
- if (this.files?.length === 0) {
- this.dispatchEvent(new Event('cancel', {
- bubbles: true,
- }));
- return;
- }
- this.files = new DataTransfer().files;
- // Dispatch events for this case because it should behave akin to a user action.
- this.dispatchEvent(new Event('input', { bubbles: true, composed: true }));
- this.dispatchEvent(new Event('change', { bubbles: true }));
- }), false, params.element);
- return {};
- }
- // Our goal here is to iterate over the input element files and get their
- // file paths.
- const paths = [];
- for (let i = 0; i < params.files.length; ++i) {
- const result = await realm.callFunction(String(function getFiles(index) {
- return this.files?.item(index);
- }), false, params.element, [{ type: 'number', value: 0 }], "root" /* Script.ResultOwnership.Root */);
- (0, assert_js_1$4.assert)(result.type === 'success');
- if (result.result.type !== 'object') {
- break;
- }
- const { handle } = result.result;
- (0, assert_js_1$4.assert)(handle !== undefined);
- const { path } = await realm.cdpClient.sendCommand('DOM.getFileInfo', {
- objectId: handle,
- });
- paths.push(path);
- // Cleanup the handle.
- void realm.disown(handle).catch(undefined);
- }
- paths.sort();
- // We create a new array so we preserve the order of the original files.
- const sortedFiles = [...params.files].sort();
- if (paths.length !== params.files.length ||
- sortedFiles.some((path, index) => {
- return paths[index] !== path;
- })) {
- const { objectId } = await realm.deserializeForCdp(params.element);
- // This cannot throw since this was just used in `callFunction` above.
- (0, assert_js_1$4.assert)(objectId !== undefined);
- await realm.cdpClient.sendCommand('DOM.setFileInputFiles', {
- files: params.files,
- objectId,
- });
- }
- else {
- // XXX: We should dispatch a trusted event.
- await realm.callFunction(String(function dispatchEvent() {
- this.dispatchEvent(new Event('cancel', {
- bubbles: true,
- }));
- }), false, params.element);
- }
- return {};
- }
- #getActionsByTick(params, inputState) {
- const actionsByTick = [];
- for (const action of params.actions) {
- switch (action.type) {
- case "pointer" /* SourceType.Pointer */: {
- action.parameters ??= { pointerType: "mouse" /* Input.PointerType.Mouse */ };
- action.parameters.pointerType ??= "mouse" /* Input.PointerType.Mouse */;
- const source = inputState.getOrCreate(action.id, "pointer" /* SourceType.Pointer */, action.parameters.pointerType);
- if (source.subtype !== action.parameters.pointerType) {
- throw new protocol_js_1$i.InvalidArgumentException(`Expected input source ${action.id} to be ${source.subtype}; got ${action.parameters.pointerType}.`);
- }
- break;
- }
- default:
- inputState.getOrCreate(action.id, action.type);
- }
- const actions = action.actions.map((item) => ({
- id: action.id,
- action: item,
- }));
- for (let i = 0; i < actions.length; i++) {
- if (actionsByTick.length === i) {
- actionsByTick.push([]);
- }
- actionsByTick[i].push(actions[i]);
- }
- }
- return actionsByTick;
- }
- }
- InputProcessor$1.InputProcessor = InputProcessor;
- var NetworkProcessor$1 = {};
- var NetworkUtils = {};
- var Base64 = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(Base64, "__esModule", { value: true });
- Base64.base64ToString = void 0;
- /**
- * Encodes a string to base64.
- *
- * Uses the native Web API if available, otherwise falls back to a NodeJS Buffer.
- * @param {string} base64Str
- * @return {string}
- */
- function base64ToString(base64Str) {
- // Available only if run in a browser context.
- if ('atob' in globalThis) {
- return globalThis.atob(base64Str);
- }
- // Available only if run in a NodeJS context.
- return Buffer.from(base64Str, 'base64').toString('ascii');
- }
- Base64.base64ToString = base64ToString;
- var UrlPattern = {};
- var M=Object.defineProperty;var Pe=Object.getOwnPropertyDescriptor;var Re=Object.getOwnPropertyNames;var Ee=Object.prototype.hasOwnProperty;var Oe=(e,t)=>{for(var r in t)M(e,r,{get:t[r],enumerable:!0});},ke=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let a of Re(t))!Ee.call(e,a)&&a!==r&&M(e,a,{get:()=>t[a],enumerable:!(n=Pe(t,a))||n.enumerable});return e};var Te=e=>ke(M({},"__esModule",{value:!0}),e);var Ne={};Oe(Ne,{URLPattern:()=>Y});var urlpattern=Te(Ne);var R=class{type=3;name="";prefix="";value="";suffix="";modifier=3;constructor(t,r,n,a,c,l){this.type=t,this.name=r,this.prefix=n,this.value=a,this.suffix=c,this.modifier=l;}hasCustomName(){return this.name!==""&&typeof this.name!="number"}},Ae=/[$_\p{ID_Start}]/u,ye=/[$_\u200C\u200D\p{ID_Continue}]/u,v=".*";function we(e,t){return (t?/^[\x00-\xFF]*$/:/^[\x00-\x7F]*$/).test(e)}function D(e,t=!1){let r=[],n=0;for(;n<e.length;){let a=e[n],c=function(l){if(!t)throw new TypeError(l);r.push({type:"INVALID_CHAR",index:n,value:e[n++]});};if(a==="*"){r.push({type:"ASTERISK",index:n,value:e[n++]});continue}if(a==="+"||a==="?"){r.push({type:"OTHER_MODIFIER",index:n,value:e[n++]});continue}if(a==="\\"){r.push({type:"ESCAPED_CHAR",index:n++,value:e[n++]});continue}if(a==="{"){r.push({type:"OPEN",index:n,value:e[n++]});continue}if(a==="}"){r.push({type:"CLOSE",index:n,value:e[n++]});continue}if(a===":"){let l="",s=n+1;for(;s<e.length;){let i=e.substr(s,1);if(s===n+1&&Ae.test(i)||s!==n+1&&ye.test(i)){l+=e[s++];continue}break}if(!l){c(`Missing parameter name at ${n}`);continue}r.push({type:"NAME",index:n,value:l}),n=s;continue}if(a==="("){let l=1,s="",i=n+1,o=!1;if(e[i]==="?"){c(`Pattern cannot start with "?" at ${i}`);continue}for(;i<e.length;){if(!we(e[i],!1)){c(`Invalid character '${e[i]}' at ${i}.`),o=!0;break}if(e[i]==="\\"){s+=e[i++]+e[i++];continue}if(e[i]===")"){if(l--,l===0){i++;break}}else if(e[i]==="("&&(l++,e[i+1]!=="?")){c(`Capturing groups are not allowed at ${i}`),o=!0;break}s+=e[i++];}if(o)continue;if(l){c(`Unbalanced pattern at ${n}`);continue}if(!s){c(`Missing pattern at ${n}`);continue}r.push({type:"REGEX",index:n,value:s}),n=i;continue}r.push({type:"CHAR",index:n,value:e[n++]});}return r.push({type:"END",index:n,value:""}),r}function F(e,t={}){let r=D(e);t.delimiter??="/#?",t.prefixes??="./";let n=`[^${S(t.delimiter)}]+?`,a=[],c=0,l=0,i=new Set,o=h=>{if(l<r.length&&r[l].type===h)return r[l++].value},f=()=>o("OTHER_MODIFIER")??o("ASTERISK"),d=h=>{let u=o(h);if(u!==void 0)return u;let{type:p,index:A}=r[l];throw new TypeError(`Unexpected ${p} at ${A}, expected ${h}`)},T=()=>{let h="",u;for(;u=o("CHAR")??o("ESCAPED_CHAR");)h+=u;return h},xe=h=>h,L=t.encodePart||xe,I="",U=h=>{I+=h;},$=()=>{I.length&&(a.push(new R(3,"","",L(I),"",3)),I="");},X=(h,u,p,A,Z)=>{let g=3;switch(Z){case"?":g=1;break;case"*":g=0;break;case"+":g=2;break}if(!u&&!p&&g===3){U(h);return}if($(),!u&&!p){if(!h)return;a.push(new R(3,"","",L(h),"",g));return}let m;p?p==="*"?m=v:m=p:m=n;let O=2;m===n?(O=1,m=""):m===v&&(O=0,m="");let P;if(u?P=u:p&&(P=c++),i.has(P))throw new TypeError(`Duplicate name '${P}'.`);i.add(P),a.push(new R(O,P,L(h),m,L(A),g));};for(;l<r.length;){let h=o("CHAR"),u=o("NAME"),p=o("REGEX");if(!u&&!p&&(p=o("ASTERISK")),u||p){let g=h??"";t.prefixes.indexOf(g)===-1&&(U(g),g=""),$();let m=f();X(g,u,p,"",m);continue}let A=h??o("ESCAPED_CHAR");if(A){U(A);continue}if(o("OPEN")){let g=T(),m=o("NAME"),O=o("REGEX");!m&&!O&&(O=o("ASTERISK"));let P=T();d("CLOSE");let be=f();X(g,m,O,P,be);continue}$(),d("END");}return a}function S(e){return e.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}function B(e){return e&&e.ignoreCase?"ui":"u"}function q(e,t,r){return W(F(e,r),t,r)}function k(e){switch(e){case 0:return "*";case 1:return "?";case 2:return "+";case 3:return ""}}function W(e,t,r={}){r.delimiter??="/#?",r.prefixes??="./",r.sensitive??=!1,r.strict??=!1,r.end??=!0,r.start??=!0,r.endsWith="";let n=r.start?"^":"";for(let s of e){if(s.type===3){s.modifier===3?n+=S(s.value):n+=`(?:${S(s.value)})${k(s.modifier)}`;continue}t&&t.push(s.name);let i=`[^${S(r.delimiter)}]+?`,o=s.value;if(s.type===1?o=i:s.type===0&&(o=v),!s.prefix.length&&!s.suffix.length){s.modifier===3||s.modifier===1?n+=`(${o})${k(s.modifier)}`:n+=`((?:${o})${k(s.modifier)})`;continue}if(s.modifier===3||s.modifier===1){n+=`(?:${S(s.prefix)}(${o})${S(s.suffix)})`,n+=k(s.modifier);continue}n+=`(?:${S(s.prefix)}`,n+=`((?:${o})(?:`,n+=S(s.suffix),n+=S(s.prefix),n+=`(?:${o}))*)${S(s.suffix)})`,s.modifier===0&&(n+="?");}let a=`[${S(r.endsWith)}]|$`,c=`[${S(r.delimiter)}]`;if(r.end)return r.strict||(n+=`${c}?`),r.endsWith.length?n+=`(?=${a})`:n+="$",new RegExp(n,B(r));r.strict||(n+=`(?:${c}(?=${a}))?`);let l=!1;if(e.length){let s=e[e.length-1];s.type===3&&s.modifier===3&&(l=r.delimiter.indexOf(s)>-1);}return l||(n+=`(?=${c}|${a})`),new RegExp(n,B(r))}var x={delimiter:"",prefixes:"",sensitive:!0,strict:!0},J={delimiter:".",prefixes:"",sensitive:!0,strict:!0},Q={delimiter:"/",prefixes:"/",sensitive:!0,strict:!0};function ee(e,t){return e.length?e[0]==="/"?!0:!t||e.length<2?!1:(e[0]=="\\"||e[0]=="{")&&e[1]=="/":!1}function te(e,t){return e.startsWith(t)?e.substring(t.length,e.length):e}function Ce(e,t){return e.endsWith(t)?e.substr(0,e.length-t.length):e}function _(e){return !e||e.length<2?!1:e[0]==="["||(e[0]==="\\"||e[0]==="{")&&e[1]==="["}var re=["ftp","file","http","https","ws","wss"];function N(e){if(!e)return !0;for(let t of re)if(e.test(t))return !0;return !1}function ne(e,t){if(e=te(e,"#"),t||e==="")return e;let r=new URL("https://example.com");return r.hash=e,r.hash?r.hash.substring(1,r.hash.length):""}function se(e,t){if(e=te(e,"?"),t||e==="")return e;let r=new URL("https://example.com");return r.search=e,r.search?r.search.substring(1,r.search.length):""}function ie(e,t){return t||e===""?e:_(e)?K(e):j(e)}function ae(e,t){if(t||e==="")return e;let r=new URL("https://example.com");return r.password=e,r.password}function oe(e,t){if(t||e==="")return e;let r=new URL("https://example.com");return r.username=e,r.username}function ce(e,t,r){if(r||e==="")return e;if(t&&!re.includes(t))return new URL(`${t}:${e}`).pathname;let n=e[0]=="/";return e=new URL(n?e:"/-"+e,"https://example.com").pathname,n||(e=e.substring(2,e.length)),e}function le(e,t,r){return z(t)===e&&(e=""),r||e===""?e:G(e)}function fe(e,t){return e=Ce(e,":"),t||e===""?e:y(e)}function z(e){switch(e){case"ws":case"http":return "80";case"wws":case"https":return "443";case"ftp":return "21";default:return ""}}function y(e){if(e==="")return e;if(/^[-+.A-Za-z0-9]*$/.test(e))return e.toLowerCase();throw new TypeError(`Invalid protocol '${e}'.`)}function he(e){if(e==="")return e;let t=new URL("https://example.com");return t.username=e,t.username}function ue(e){if(e==="")return e;let t=new URL("https://example.com");return t.password=e,t.password}function j(e){if(e==="")return e;if(/[\t\n\r #%/:<>?@[\]^\\|]/g.test(e))throw new TypeError(`Invalid hostname '${e}'`);let t=new URL("https://example.com");return t.hostname=e,t.hostname}function K(e){if(e==="")return e;if(/[^0-9a-fA-F[\]:]/g.test(e))throw new TypeError(`Invalid IPv6 hostname '${e}'`);return e.toLowerCase()}function G(e){if(e===""||/^[0-9]*$/.test(e)&&parseInt(e)<=65535)return e;throw new TypeError(`Invalid port '${e}'.`)}function de(e){if(e==="")return e;let t=new URL("https://example.com");return t.pathname=e[0]!=="/"?"/-"+e:e,e[0]!=="/"?t.pathname.substring(2,t.pathname.length):t.pathname}function pe(e){return e===""?e:new URL(`data:${e}`).pathname}function ge(e){if(e==="")return e;let t=new URL("https://example.com");return t.search=e,t.search.substring(1,t.search.length)}function me(e){if(e==="")return e;let t=new URL("https://example.com");return t.hash=e,t.hash.substring(1,t.hash.length)}var H=class{#i;#n=[];#t={};#e=0;#s=1;#l=0;#o=0;#d=0;#p=0;#g=!1;constructor(t){this.#i=t;}get result(){return this.#t}parse(){for(this.#n=D(this.#i,!0);this.#e<this.#n.length;this.#e+=this.#s){if(this.#s=1,this.#n[this.#e].type==="END"){if(this.#o===0){this.#b(),this.#f()?this.#r(9,1):this.#h()?this.#r(8,1):this.#r(7,0);continue}else if(this.#o===2){this.#u(5);continue}this.#r(10,0);break}if(this.#d>0)if(this.#A())this.#d-=1;else continue;if(this.#T()){this.#d+=1;continue}switch(this.#o){case 0:this.#P()&&this.#u(1);break;case 1:if(this.#P()){this.#C();let t=7,r=1;this.#E()?(t=2,r=3):this.#g&&(t=2),this.#r(t,r);}break;case 2:this.#S()?this.#u(3):(this.#x()||this.#h()||this.#f())&&this.#u(5);break;case 3:this.#O()?this.#r(4,1):this.#S()&&this.#r(5,1);break;case 4:this.#S()&&this.#r(5,1);break;case 5:this.#y()?this.#p+=1:this.#w()&&(this.#p-=1),this.#k()&&!this.#p?this.#r(6,1):this.#x()?this.#r(7,0):this.#h()?this.#r(8,1):this.#f()&&this.#r(9,1);break;case 6:this.#x()?this.#r(7,0):this.#h()?this.#r(8,1):this.#f()&&this.#r(9,1);break;case 7:this.#h()?this.#r(8,1):this.#f()&&this.#r(9,1);break;case 8:this.#f()&&this.#r(9,1);break;}}this.#t.hostname!==void 0&&this.#t.port===void 0&&(this.#t.port="");}#r(t,r){switch(this.#o){case 0:break;case 1:this.#t.protocol=this.#c();break;case 2:break;case 3:this.#t.username=this.#c();break;case 4:this.#t.password=this.#c();break;case 5:this.#t.hostname=this.#c();break;case 6:this.#t.port=this.#c();break;case 7:this.#t.pathname=this.#c();break;case 8:this.#t.search=this.#c();break;case 9:this.#t.hash=this.#c();break;}this.#o!==0&&t!==10&&([1,2,3,4].includes(this.#o)&&[6,7,8,9].includes(t)&&(this.#t.hostname??=""),[1,2,3,4,5,6].includes(this.#o)&&[8,9].includes(t)&&(this.#t.pathname??=this.#g?"/":""),[1,2,3,4,5,6,7].includes(this.#o)&&t===9&&(this.#t.search??="")),this.#R(t,r);}#R(t,r){this.#o=t,this.#l=this.#e+r,this.#e+=r,this.#s=0;}#b(){this.#e=this.#l,this.#s=0;}#u(t){this.#b(),this.#o=t;}#m(t){return t<0&&(t=this.#n.length-t),t<this.#n.length?this.#n[t]:this.#n[this.#n.length-1]}#a(t,r){let n=this.#m(t);return n.value===r&&(n.type==="CHAR"||n.type==="ESCAPED_CHAR"||n.type==="INVALID_CHAR")}#P(){return this.#a(this.#e,":")}#E(){return this.#a(this.#e+1,"/")&&this.#a(this.#e+2,"/")}#S(){return this.#a(this.#e,"@")}#O(){return this.#a(this.#e,":")}#k(){return this.#a(this.#e,":")}#x(){return this.#a(this.#e,"/")}#h(){if(this.#a(this.#e,"?"))return !0;if(this.#n[this.#e].value!=="?")return !1;let t=this.#m(this.#e-1);return t.type!=="NAME"&&t.type!=="REGEX"&&t.type!=="CLOSE"&&t.type!=="ASTERISK"}#f(){return this.#a(this.#e,"#")}#T(){return this.#n[this.#e].type=="OPEN"}#A(){return this.#n[this.#e].type=="CLOSE"}#y(){return this.#a(this.#e,"[")}#w(){return this.#a(this.#e,"]")}#c(){let t=this.#n[this.#e],r=this.#m(this.#l).index;return this.#i.substring(r,t.index)}#C(){let t={};Object.assign(t,x),t.encodePart=y;let r=q(this.#c(),void 0,t);this.#g=N(r);}};var V=["protocol","username","password","hostname","port","pathname","search","hash"],E="*";function Se(e,t){if(typeof e!="string")throw new TypeError("parameter 1 is not of type 'string'.");let r=new URL(e,t);return {protocol:r.protocol.substring(0,r.protocol.length-1),username:r.username,password:r.password,hostname:r.hostname,port:r.port,pathname:r.pathname,search:r.search!==""?r.search.substring(1,r.search.length):void 0,hash:r.hash!==""?r.hash.substring(1,r.hash.length):void 0}}function b(e,t){return t?C(e):e}function w(e,t,r){let n;if(typeof t.baseURL=="string")try{n=new URL(t.baseURL),t.protocol===void 0&&(e.protocol=b(n.protocol.substring(0,n.protocol.length-1),r)),!r&&t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&t.username===void 0&&(e.username=b(n.username,r)),!r&&t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&t.username===void 0&&t.password===void 0&&(e.password=b(n.password,r)),t.protocol===void 0&&t.hostname===void 0&&(e.hostname=b(n.hostname,r)),t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&(e.port=b(n.port,r)),t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&t.pathname===void 0&&(e.pathname=b(n.pathname,r)),t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&t.pathname===void 0&&t.search===void 0&&(e.search=b(n.search.substring(1,n.search.length),r)),t.protocol===void 0&&t.hostname===void 0&&t.port===void 0&&t.pathname===void 0&&t.search===void 0&&t.hash===void 0&&(e.hash=b(n.hash.substring(1,n.hash.length),r));}catch{throw new TypeError(`invalid baseURL '${t.baseURL}'.`)}if(typeof t.protocol=="string"&&(e.protocol=fe(t.protocol,r)),typeof t.username=="string"&&(e.username=oe(t.username,r)),typeof t.password=="string"&&(e.password=ae(t.password,r)),typeof t.hostname=="string"&&(e.hostname=ie(t.hostname,r)),typeof t.port=="string"&&(e.port=le(t.port,e.protocol,r)),typeof t.pathname=="string"){if(e.pathname=t.pathname,n&&!ee(e.pathname,r)){let a=n.pathname.lastIndexOf("/");a>=0&&(e.pathname=b(n.pathname.substring(0,a+1),r)+e.pathname);}e.pathname=ce(e.pathname,e.protocol,r);}return typeof t.search=="string"&&(e.search=se(t.search,r)),typeof t.hash=="string"&&(e.hash=ne(t.hash,r)),e}function C(e){return e.replace(/([+*?:{}()\\])/g,"\\$1")}function Le(e){return e.replace(/([.+*?^${}()[\]|/\\])/g,"\\$1")}function Ie(e,t){t.delimiter??="/#?",t.prefixes??="./",t.sensitive??=!1,t.strict??=!1,t.end??=!0,t.start??=!0,t.endsWith="";let r=".*",n=`[^${Le(t.delimiter)}]+?`,a=/[$_\u200C\u200D\p{ID_Continue}]/u,c="";for(let l=0;l<e.length;++l){let s=e[l];if(s.type===3){if(s.modifier===3){c+=C(s.value);continue}c+=`{${C(s.value)}}${k(s.modifier)}`;continue}let i=s.hasCustomName(),o=!!s.suffix.length||!!s.prefix.length&&(s.prefix.length!==1||!t.prefixes.includes(s.prefix)),f=l>0?e[l-1]:null,d=l<e.length-1?e[l+1]:null;if(!o&&i&&s.type===1&&s.modifier===3&&d&&!d.prefix.length&&!d.suffix.length)if(d.type===3){let T=d.value.length>0?d.value[0]:"";o=a.test(T);}else o=!d.hasCustomName();if(!o&&!s.prefix.length&&f&&f.type===3){let T=f.value[f.value.length-1];o=t.prefixes.includes(T);}o&&(c+="{"),c+=C(s.prefix),i&&(c+=`:${s.name}`),s.type===2?c+=`(${s.value})`:s.type===1?i||(c+=`(${n})`):s.type===0&&(!i&&(!f||f.type===3||f.modifier!==3||o||s.prefix!=="")?c+="*":c+=`(${r})`),s.type===1&&i&&s.suffix.length&&a.test(s.suffix[0])&&(c+="\\"),c+=C(s.suffix),o&&(c+="}"),s.modifier!==3&&(c+=k(s.modifier));}return c}var Y=class{#i;#n={};#t={};#e={};#s={};#l=!1;constructor(t={},r,n){try{let a;if(typeof r=="string"?a=r:n=r,typeof t=="string"){let i=new H(t);if(i.parse(),t=i.result,a===void 0&&typeof t.protocol!="string")throw new TypeError("A base URL must be provided for a relative constructor string.");t.baseURL=a;}else {if(!t||typeof t!="object")throw new TypeError("parameter 1 is not of type 'string' and cannot convert to dictionary.");if(a)throw new TypeError("parameter 1 is not of type 'string'.")}typeof n>"u"&&(n={ignoreCase:!1});let c={ignoreCase:n.ignoreCase===!0},l={pathname:E,protocol:E,username:E,password:E,hostname:E,port:E,search:E,hash:E};this.#i=w(l,t,!0),z(this.#i.protocol)===this.#i.port&&(this.#i.port="");let s;for(s of V){if(!(s in this.#i))continue;let i={},o=this.#i[s];switch(this.#t[s]=[],s){case"protocol":Object.assign(i,x),i.encodePart=y;break;case"username":Object.assign(i,x),i.encodePart=he;break;case"password":Object.assign(i,x),i.encodePart=ue;break;case"hostname":Object.assign(i,J),_(o)?i.encodePart=K:i.encodePart=j;break;case"port":Object.assign(i,x),i.encodePart=G;break;case"pathname":N(this.#n.protocol)?(Object.assign(i,Q,c),i.encodePart=de):(Object.assign(i,x,c),i.encodePart=pe);break;case"search":Object.assign(i,x,c),i.encodePart=ge;break;case"hash":Object.assign(i,x,c),i.encodePart=me;break}try{this.#s[s]=F(o,i),this.#n[s]=W(this.#s[s],this.#t[s],i),this.#e[s]=Ie(this.#s[s],i),this.#l=this.#l||this.#s[s].some(f=>f.type===2);}catch{throw new TypeError(`invalid ${s} pattern '${this.#i[s]}'.`)}}}catch(a){throw new TypeError(`Failed to construct 'URLPattern': ${a.message}`)}}test(t={},r){let n={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&r)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return !1;try{typeof t=="object"?n=w(n,t,!1):n=w(n,Se(t,r),!1);}catch{return !1}let a;for(a of V)if(!this.#n[a].exec(n[a]))return !1;return !0}exec(t={},r){let n={pathname:"",protocol:"",username:"",password:"",hostname:"",port:"",search:"",hash:""};if(typeof t!="string"&&r)throw new TypeError("parameter 1 is not of type 'string'.");if(typeof t>"u")return;try{typeof t=="object"?n=w(n,t,!1):n=w(n,Se(t,r),!1);}catch{return null}let a={};r?a.inputs=[t,r]:a.inputs=[t];let c;for(c of V){let l=this.#n[c].exec(n[c]);if(!l)return null;let s={};for(let[i,o]of this.#t[c].entries())if(typeof o=="string"||typeof o=="number"){let f=l[i+1];s[o]=f;}a[c]={input:n[c]??"",groups:s};}return a}static compareComponent(t,r,n){let a=(i,o)=>{for(let f of ["type","modifier","prefix","value","suffix"]){if(i[f]<o[f])return -1;if(i[f]===o[f])continue;return 1}return 0},c=new R(3,"","","","",3),l=new R(0,"","","","",3),s=(i,o)=>{let f=0;for(;f<Math.min(i.length,o.length);++f){let d=a(i[f],o[f]);if(d)return d}return i.length===o.length?0:a(i[f]??c,o[f]??c)};return !r.#e[t]&&!n.#e[t]?0:r.#e[t]&&!n.#e[t]?s(r.#s[t],[l]):!r.#e[t]&&n.#e[t]?s([l],n.#s[t]):s(r.#s[t],n.#s[t])}get protocol(){return this.#e.protocol}get username(){return this.#e.username}get password(){return this.#e.password}get hostname(){return this.#e.hostname}get port(){return this.#e.port}get pathname(){return this.#e.pathname}get search(){return this.#e.search}get hash(){return this.#e.hash}get hasRegExpGroups(){return this.#l}};
- const { URLPattern: URLPattern$2 } = urlpattern;
- var urlpatternPolyfill = { URLPattern: URLPattern$2 };
- if (!globalThis.URLPattern) {
- globalThis.URLPattern = URLPattern$2;
- }
- Object.defineProperty(UrlPattern, "__esModule", { value: true });
- UrlPattern.URLPattern = void 0;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const urlpattern_polyfill_1 = urlpatternPolyfill;
- // XXX: Switch to native URLPattern when available.
- // https://github.com/nodejs/node/issues/40844
- let URLPattern$1 = urlpattern_polyfill_1.URLPattern;
- UrlPattern.URLPattern = URLPattern$1;
- if ('URLPattern' in globalThis) {
- UrlPattern.URLPattern = URLPattern$1 = globalThis.URLPattern;
- }
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- Object.defineProperty(NetworkUtils, "__esModule", { value: true });
- NetworkUtils.matchUrlPattern = NetworkUtils.isSpecialScheme = NetworkUtils.sameSiteBiDiToCdp = NetworkUtils.bidiToCdpCookie = NetworkUtils.deserializeByteValue = NetworkUtils.cdpToBiDiCookie = NetworkUtils.cdpAuthChallengeResponseFromBidiAuthContinueWithAuthAction = NetworkUtils.cdpFetchHeadersFromBidiNetworkHeaders = NetworkUtils.bidiNetworkHeadersFromCdpFetchHeaders = NetworkUtils.cdpNetworkHeadersFromBidiNetworkHeaders = NetworkUtils.bidiNetworkHeadersFromCdpNetworkHeaders = NetworkUtils.computeHeadersSize = void 0;
- const ErrorResponse_js_1 = ErrorResponse;
- const Base64_js_1 = Base64;
- const UrlPattern_js_1 = UrlPattern;
- function computeHeadersSize(headers) {
- const requestHeaders = headers.reduce((acc, header) => {
- return `${acc}${header.name}: ${header.value.value}\r\n`;
- }, '');
- return new TextEncoder().encode(requestHeaders).length;
- }
- NetworkUtils.computeHeadersSize = computeHeadersSize;
- /** Converts from CDP Network domain headers to Bidi network headers. */
- function bidiNetworkHeadersFromCdpNetworkHeaders(headers) {
- if (!headers) {
- return [];
- }
- return Object.entries(headers).map(([name, value]) => ({
- name,
- value: {
- type: 'string',
- value,
- },
- }));
- }
- NetworkUtils.bidiNetworkHeadersFromCdpNetworkHeaders = bidiNetworkHeadersFromCdpNetworkHeaders;
- /** Converts from Bidi network headers to CDP Network domain headers. */
- function cdpNetworkHeadersFromBidiNetworkHeaders(headers) {
- if (headers === undefined) {
- return undefined;
- }
- return headers.reduce((result, header) => {
- // TODO: Distinguish between string and bytes?
- result[header.name] = header.value.value;
- return result;
- }, {});
- }
- NetworkUtils.cdpNetworkHeadersFromBidiNetworkHeaders = cdpNetworkHeadersFromBidiNetworkHeaders;
- /** Converts from CDP Fetch domain header entries to Bidi network headers. */
- function bidiNetworkHeadersFromCdpFetchHeaders(headers) {
- if (!headers) {
- return [];
- }
- return headers.map(({ name, value }) => ({
- name,
- value: {
- type: 'string',
- value,
- },
- }));
- }
- NetworkUtils.bidiNetworkHeadersFromCdpFetchHeaders = bidiNetworkHeadersFromCdpFetchHeaders;
- /** Converts from Bidi network headers to CDP Fetch domain header entries. */
- function cdpFetchHeadersFromBidiNetworkHeaders(headers) {
- if (headers === undefined) {
- return undefined;
- }
- return headers.map(({ name, value }) => ({
- name,
- value: value.value,
- }));
- }
- NetworkUtils.cdpFetchHeadersFromBidiNetworkHeaders = cdpFetchHeadersFromBidiNetworkHeaders;
- /** Converts from Bidi auth action to CDP auth challenge response. */
- function cdpAuthChallengeResponseFromBidiAuthContinueWithAuthAction(action) {
- switch (action) {
- case 'default':
- return 'Default';
- case 'cancel':
- return 'CancelAuth';
- case 'provideCredentials':
- return 'ProvideCredentials';
- }
- }
- NetworkUtils.cdpAuthChallengeResponseFromBidiAuthContinueWithAuthAction = cdpAuthChallengeResponseFromBidiAuthContinueWithAuthAction;
- /**
- * Converts from CDP Network domain cookie to BiDi network cookie.
- * * https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-Cookie
- * * https://w3c.github.io/webdriver-bidi/#type-network-Cookie
- */
- function cdpToBiDiCookie(cookie) {
- const result = {
- name: cookie.name,
- value: { type: 'string', value: cookie.value },
- domain: cookie.domain,
- path: cookie.path,
- size: cookie.size,
- httpOnly: cookie.httpOnly,
- secure: cookie.secure,
- sameSite: cookie.sameSite === undefined
- ? "none" /* Network.SameSite.None */
- : sameSiteCdpToBiDi(cookie.sameSite),
- ...(cookie.expires >= 0 ? { expiry: cookie.expires } : undefined),
- };
- // Extending with CDP-specific properties with `goog:` prefix.
- result[`goog:session`] = cookie.session;
- result[`goog:priority`] = cookie.priority;
- result[`goog:sameParty`] = cookie.sameParty;
- result[`goog:sourceScheme`] = cookie.sourceScheme;
- result[`goog:sourcePort`] = cookie.sourcePort;
- if (cookie.partitionKey !== undefined) {
- result[`goog:partitionKey`] = cookie.partitionKey;
- }
- if (cookie.partitionKeyOpaque !== undefined) {
- result[`goog:partitionKeyOpaque`] = cookie.partitionKeyOpaque;
- }
- return result;
- }
- NetworkUtils.cdpToBiDiCookie = cdpToBiDiCookie;
- /**
- * Decodes a byte value to a string.
- * @param {Network.BytesValue} value
- * @return {string}
- */
- function deserializeByteValue(value) {
- if (value.type === 'base64') {
- return (0, Base64_js_1.base64ToString)(value.value);
- }
- return value.value;
- }
- NetworkUtils.deserializeByteValue = deserializeByteValue;
- /**
- * Converts from BiDi set network cookie params to CDP Network domain cookie.
- * * https://w3c.github.io/webdriver-bidi/#type-network-Cookie
- * * https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-CookieParam
- */
- function bidiToCdpCookie(params, partitionKey) {
- const deserializedValue = deserializeByteValue(params.cookie.value);
- const result = {
- name: params.cookie.name,
- value: deserializedValue,
- domain: params.cookie.domain,
- path: params.cookie.path ?? '/',
- secure: params.cookie.secure ?? false,
- httpOnly: params.cookie.httpOnly ?? false,
- // CDP's `partitionKey` is the BiDi's `partition.sourceOrigin`.
- ...(partitionKey.sourceOrigin !== undefined && {
- partitionKey: partitionKey.sourceOrigin,
- }),
- ...(params.cookie.expiry !== undefined && {
- expires: params.cookie.expiry,
- }),
- ...(params.cookie.sameSite !== undefined && {
- sameSite: sameSiteBiDiToCdp(params.cookie.sameSite),
- }),
- };
- // Extending with CDP-specific properties with `goog:` prefix.
- if (params.cookie[`goog:url`] !== undefined) {
- result.url = params.cookie[`goog:url`];
- }
- if (params.cookie[`goog:priority`] !== undefined) {
- result.priority = params.cookie[`goog:priority`];
- }
- if (params.cookie[`goog:sameParty`] !== undefined) {
- result.sameParty = params.cookie[`goog:sameParty`];
- }
- if (params.cookie[`goog:sourceScheme`] !== undefined) {
- result.sourceScheme = params.cookie[`goog:sourceScheme`];
- }
- if (params.cookie[`goog:sourcePort`] !== undefined) {
- result.sourcePort = params.cookie[`goog:sourcePort`];
- }
- return result;
- }
- NetworkUtils.bidiToCdpCookie = bidiToCdpCookie;
- function sameSiteCdpToBiDi(sameSite) {
- switch (sameSite) {
- case 'Strict':
- return "strict" /* Network.SameSite.Strict */;
- case 'None':
- return "none" /* Network.SameSite.None */;
- case 'Lax':
- return "lax" /* Network.SameSite.Lax */;
- default:
- // Defaults to `Lax`:
- // https://web.dev/articles/samesite-cookies-explained#samesitelax_by_default
- return "lax" /* Network.SameSite.Lax */;
- }
- }
- function sameSiteBiDiToCdp(sameSite) {
- switch (sameSite) {
- case "strict" /* Network.SameSite.Strict */:
- return 'Strict';
- case "lax" /* Network.SameSite.Lax */:
- return 'Lax';
- case "none" /* Network.SameSite.None */:
- return 'None';
- }
- throw new ErrorResponse_js_1.InvalidArgumentException(`Unknown 'sameSite' value ${sameSite}`);
- }
- NetworkUtils.sameSiteBiDiToCdp = sameSiteBiDiToCdp;
- /**
- * Returns true if the given protocol is special.
- * Special protocols are those that have a default port.
- *
- * Example inputs: 'http', 'http:'
- *
- * @see https://url.spec.whatwg.org/#special-scheme
- */
- function isSpecialScheme(protocol) {
- return ['ftp', 'file', 'http', 'https', 'ws', 'wss'].includes(protocol.replace(/:$/, ''));
- }
- NetworkUtils.isSpecialScheme = isSpecialScheme;
- /** Matches the given URLPattern against the given URL. */
- function matchUrlPattern(urlPattern, url) {
- switch (urlPattern.type) {
- case 'string': {
- const pattern = new UrlPattern_js_1.URLPattern(urlPattern.pattern);
- return new UrlPattern_js_1.URLPattern({
- protocol: pattern.protocol,
- hostname: pattern.hostname,
- port: pattern.port,
- pathname: pattern.pathname,
- search: pattern.search,
- }).test(url);
- }
- case 'pattern':
- return new UrlPattern_js_1.URLPattern(urlPattern).test(url);
- }
- }
- NetworkUtils.matchUrlPattern = matchUrlPattern;
- Object.defineProperty(NetworkProcessor$1, "__esModule", { value: true });
- NetworkProcessor$1.NetworkProcessor = void 0;
- const protocol_js_1$h = protocol;
- const NetworkUtils_js_1$3 = NetworkUtils;
- /** Dispatches Network domain commands. */
- class NetworkProcessor {
- #browsingContextStorage;
- #networkStorage;
- constructor(browsingContextStorage, networkStorage) {
- this.#browsingContextStorage = browsingContextStorage;
- this.#networkStorage = networkStorage;
- }
- async addIntercept(params) {
- this.#browsingContextStorage.verifyTopLevelContextsList(params.contexts);
- const urlPatterns = params.urlPatterns ?? [];
- const parsedUrlPatterns = NetworkProcessor.parseUrlPatterns(urlPatterns);
- const intercept = this.#networkStorage.addIntercept({
- urlPatterns: parsedUrlPatterns,
- phases: params.phases,
- contexts: params.contexts,
- });
- await Promise.all(this.#browsingContextStorage.getAllContexts().map((context) => {
- return context.cdpTarget.toggleFetchIfNeeded();
- }));
- return {
- intercept,
- };
- }
- async continueRequest(params) {
- const { url, method, headers: commandHeaders, body, request: networkId, } = params;
- if (params.url !== undefined) {
- NetworkProcessor.parseUrlString(params.url);
- }
- const request = this.#getBlockedRequestOrFail(networkId, [
- "beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */,
- ]);
- const headers = (0, NetworkUtils_js_1$3.cdpFetchHeadersFromBidiNetworkHeaders)(commandHeaders);
- // TODO: Set / expand.
- // ; Step 9. cookies
- await request.continueRequest({
- url,
- method,
- headers,
- postData: getCdpBodyFromBiDiBytesValue(body),
- });
- return {};
- }
- async continueResponse(params) {
- const { request: networkId, statusCode, reasonPhrase, headers } = params;
- const responseHeaders = (0, NetworkUtils_js_1$3.cdpFetchHeadersFromBidiNetworkHeaders)(headers);
- const request = this.#getBlockedRequestOrFail(networkId, [
- "authRequired" /* Network.InterceptPhase.AuthRequired */,
- "responseStarted" /* Network.InterceptPhase.ResponseStarted */,
- ]);
- if (request.interceptPhase === "authRequired" /* Network.InterceptPhase.AuthRequired */) {
- if (params.credentials) {
- await Promise.all([
- request.waitNextPhase,
- request.continueWithAuth({
- response: 'ProvideCredentials',
- username: params.credentials.username,
- password: params.credentials.password,
- }),
- ]);
- }
- else {
- // We need to use `ProvideCredentials`
- // As `Default` may cancel the request
- await request.continueWithAuth({
- response: 'ProvideCredentials',
- });
- return {};
- }
- }
- if (request.interceptPhase === "responseStarted" /* Network.InterceptPhase.ResponseStarted */) {
- // TODO: Set / expand.
- // ; Step 10. cookies
- await request.continueResponse({
- responseCode: statusCode,
- responsePhrase: reasonPhrase,
- responseHeaders,
- });
- }
- return {};
- }
- async continueWithAuth(params) {
- const networkId = params.request;
- const request = this.#getBlockedRequestOrFail(networkId, [
- "authRequired" /* Network.InterceptPhase.AuthRequired */,
- ]);
- let username;
- let password;
- if (params.action === 'provideCredentials') {
- const { credentials } = params;
- username = credentials.username;
- password = credentials.password;
- }
- const response = (0, NetworkUtils_js_1$3.cdpAuthChallengeResponseFromBidiAuthContinueWithAuthAction)(params.action);
- await request.continueWithAuth({
- response,
- username,
- password,
- });
- return {};
- }
- async failRequest({ request: networkId, }) {
- const request = this.#getRequestOrFail(networkId);
- if (request.interceptPhase === "authRequired" /* Network.InterceptPhase.AuthRequired */) {
- throw new protocol_js_1$h.InvalidArgumentException(`Request '${networkId}' in 'authRequired' phase cannot be failed`);
- }
- if (!request.interceptPhase) {
- throw new protocol_js_1$h.NoSuchRequestException(`No blocked request found for network id '${networkId}'`);
- }
- await request.failRequest('Failed');
- return {};
- }
- async provideResponse(params) {
- const { statusCode, reasonPhrase: responsePhrase, headers, body, request: networkId, } = params;
- // TODO: Step 6
- // https://w3c.github.io/webdriver-bidi/#command-network-continueResponse
- const responseHeaders = (0, NetworkUtils_js_1$3.cdpFetchHeadersFromBidiNetworkHeaders)(headers);
- // TODO: Set / expand.
- // ; Step 10. cookies
- // ; Step 11. credentials
- const request = this.#getBlockedRequestOrFail(networkId, [
- "beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */,
- "responseStarted" /* Network.InterceptPhase.ResponseStarted */,
- "authRequired" /* Network.InterceptPhase.AuthRequired */,
- ]);
- // We need to pass through if the request is already in
- // AuthRequired phase
- if (request.interceptPhase === "authRequired" /* Network.InterceptPhase.AuthRequired */) {
- // We need to use `ProvideCredentials`
- // As `Default` may cancel the request
- await request.continueWithAuth({
- response: 'ProvideCredentials',
- });
- return {};
- }
- // If we con't modify the response
- // Just continue the request
- if (!body && !headers) {
- await request.continueRequest();
- return {};
- }
- const responseCode = statusCode ?? request.statusCode ?? 200;
- await request.provideResponse({
- responseCode,
- responsePhrase,
- responseHeaders,
- body: getCdpBodyFromBiDiBytesValue(body),
- });
- return {};
- }
- async removeIntercept(params) {
- this.#networkStorage.removeIntercept(params.intercept);
- await Promise.all(this.#browsingContextStorage.getAllContexts().map((context) => {
- return context.cdpTarget.toggleFetchIfNeeded();
- }));
- return {};
- }
- #getRequestOrFail(id) {
- const request = this.#networkStorage.getRequestById(id);
- if (!request) {
- throw new protocol_js_1$h.NoSuchRequestException(`Network request with ID '${id}' doesn't exist`);
- }
- return request;
- }
- #getBlockedRequestOrFail(id, phases) {
- const request = this.#getRequestOrFail(id);
- if (!request.interceptPhase) {
- throw new protocol_js_1$h.NoSuchRequestException(`No blocked request found for network id '${id}'`);
- }
- if (request.interceptPhase && !phases.includes(request.interceptPhase)) {
- throw new protocol_js_1$h.InvalidArgumentException(`Blocked request for network id '${id}' is in '${request.interceptPhase}' phase`);
- }
- return request;
- }
- /**
- * Attempts to parse the given url.
- * Throws an InvalidArgumentException if the url is invalid.
- */
- static parseUrlString(url) {
- try {
- return new URL(url);
- }
- catch (error) {
- throw new protocol_js_1$h.InvalidArgumentException(`Invalid URL '${url}': ${error}`);
- }
- }
- static parseUrlPatterns(urlPatterns) {
- return urlPatterns.map((urlPattern) => {
- switch (urlPattern.type) {
- case 'string': {
- NetworkProcessor.parseUrlString(urlPattern.pattern);
- return urlPattern;
- }
- case 'pattern':
- // No params signifies intercept all
- if (urlPattern.protocol === undefined &&
- urlPattern.hostname === undefined &&
- urlPattern.port === undefined &&
- urlPattern.pathname === undefined &&
- urlPattern.search === undefined) {
- return urlPattern;
- }
- if (urlPattern.protocol) {
- urlPattern.protocol = unescapeURLPattern(urlPattern.protocol);
- if (!urlPattern.protocol.match(/^[a-zA-Z+-.]+$/)) {
- throw new protocol_js_1$h.InvalidArgumentException('Forbidden characters');
- }
- }
- if (urlPattern.hostname) {
- urlPattern.hostname = unescapeURLPattern(urlPattern.hostname);
- }
- if (urlPattern.port) {
- urlPattern.port = unescapeURLPattern(urlPattern.port);
- }
- if (urlPattern.pathname) {
- urlPattern.pathname = unescapeURLPattern(urlPattern.pathname);
- if (urlPattern.pathname[0] !== '/') {
- urlPattern.pathname = `/${urlPattern.pathname}`;
- }
- if (urlPattern.pathname.includes('#') ||
- urlPattern.pathname.includes('?')) {
- throw new protocol_js_1$h.InvalidArgumentException('Forbidden characters');
- }
- }
- else if (urlPattern.pathname === '') {
- urlPattern.pathname = '/';
- }
- if (urlPattern.search) {
- urlPattern.search = unescapeURLPattern(urlPattern.search);
- if (urlPattern.search[0] !== '?') {
- urlPattern.search = `?${urlPattern.search}`;
- }
- if (urlPattern.search.includes('#')) {
- throw new protocol_js_1$h.InvalidArgumentException('Forbidden characters');
- }
- }
- if (urlPattern.protocol === '') {
- throw new protocol_js_1$h.InvalidArgumentException(`URL pattern must specify a protocol`);
- }
- if (urlPattern.hostname === '') {
- throw new protocol_js_1$h.InvalidArgumentException(`URL pattern must specify a hostname`);
- }
- if ((urlPattern.hostname?.length ?? 0) > 0) {
- if (urlPattern.protocol?.match(/^file/i)) {
- throw new protocol_js_1$h.InvalidArgumentException(`URL pattern protocol cannot be 'file'`);
- }
- if (urlPattern.hostname?.includes(':')) {
- throw new protocol_js_1$h.InvalidArgumentException(`URL pattern hostname must not contain a colon`);
- }
- }
- if (urlPattern.port === '') {
- throw new protocol_js_1$h.InvalidArgumentException(`URL pattern must specify a port`);
- }
- try {
- new URLPattern(urlPattern);
- }
- catch (error) {
- throw new protocol_js_1$h.InvalidArgumentException(`${error}`);
- }
- return urlPattern;
- }
- });
- }
- }
- NetworkProcessor$1.NetworkProcessor = NetworkProcessor;
- /**
- * See https://w3c.github.io/webdriver-bidi/#unescape-url-pattern
- */
- function unescapeURLPattern(pattern) {
- const forbidden = new Set(['(', ')', '*', '{', '}']);
- let result = '';
- let isEscaped = false;
- for (const c of pattern) {
- if (!isEscaped) {
- if (forbidden.has(c)) {
- throw new protocol_js_1$h.InvalidArgumentException('Forbidden characters');
- }
- if (c === '\\') {
- isEscaped = true;
- continue;
- }
- }
- result += c;
- isEscaped = false;
- }
- return result;
- }
- function getCdpBodyFromBiDiBytesValue(body) {
- let parsedBody;
- if (body?.type === 'string') {
- parsedBody = btoa(body.value);
- }
- else if (body?.type === 'base64') {
- parsedBody = body.value;
- }
- return parsedBody;
- }
- var PermissionsProcessor$1 = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(PermissionsProcessor$1, "__esModule", { value: true });
- PermissionsProcessor$1.PermissionsProcessor = void 0;
- const protocol_js_1$g = protocol;
- class PermissionsProcessor {
- #browserCdpClient;
- constructor(browserCdpClient) {
- this.#browserCdpClient = browserCdpClient;
- }
- async setPermissions(params) {
- try {
- const userContextId = params['goog:userContext'] ||
- params.userContext;
- await this.#browserCdpClient.sendCommand('Browser.setPermission', {
- origin: params.origin,
- browserContextId: userContextId && userContextId !== 'default'
- ? userContextId
- : undefined,
- permission: {
- name: params.descriptor.name,
- },
- setting: params.state,
- });
- }
- catch (err) {
- if (err.message ===
- `Permission can't be granted to opaque origins.`) {
- // Return success if the origin is not valid (does not match any
- // existing origins).
- return {};
- }
- throw new protocol_js_1$g.InvalidArgumentException(err.message);
- }
- return {};
- }
- }
- PermissionsProcessor$1.PermissionsProcessor = PermissionsProcessor;
- var ScriptProcessor$1 = {};
- var PreloadScript$1 = {};
- var uuid = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(uuid, "__esModule", { value: true });
- uuid.uuidv4 = void 0;
- /**
- * Generates a random v4 UUID, as specified in RFC4122.
- *
- * Uses the native Web Crypto API if available, otherwise falls back to a
- * polyfill.
- *
- * Example: '9b1deb4d-3b7d-4bad-9bdd-2b0d7b3dcb6d'
- */
- function uuidv4() {
- // Available only in secure contexts
- // https://developer.mozilla.org/en-US/docs/Web/API/Web_Crypto_API
- if ('crypto' in globalThis && 'randomUUID' in globalThis.crypto) {
- // Node with
- // https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#crypto_1 or
- // secure browser context.
- return globalThis.crypto.randomUUID();
- }
- const randomValues = new Uint8Array(16);
- if ('crypto' in globalThis && 'getRandomValues' in globalThis.crypto) {
- // Node with
- // https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#crypto_1 or
- // browser.
- globalThis.crypto.getRandomValues(randomValues);
- }
- else {
- // Node without
- // https://nodejs.org/dist/latest-v20.x/docs/api/globals.html#crypto_1.
- // eslint-disable-next-line @typescript-eslint/no-var-requires
- require('crypto').webcrypto.getRandomValues(randomValues);
- }
- // Set version (4) and variant (RFC4122) bits.
- randomValues[6] = (randomValues[6] & 0x0f) | 0x40;
- randomValues[8] = (randomValues[8] & 0x3f) | 0x80;
- const bytesToHex = (bytes) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), '');
- return [
- bytesToHex(randomValues.subarray(0, 4)),
- bytesToHex(randomValues.subarray(4, 6)),
- bytesToHex(randomValues.subarray(6, 8)),
- bytesToHex(randomValues.subarray(8, 10)),
- bytesToHex(randomValues.subarray(10, 16)),
- ].join('-');
- }
- uuid.uuidv4 = uuidv4;
- var ChannelProxy$1 = {};
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- Object.defineProperty(ChannelProxy$1, "__esModule", { value: true });
- ChannelProxy$1.ChannelProxy = void 0;
- const protocol_js_1$f = protocol;
- const log_js_1$c = log$1;
- const uuid_js_1$3 = uuid;
- /**
- * Used to send messages from realm to BiDi user.
- */
- class ChannelProxy {
- #properties;
- #id = (0, uuid_js_1$3.uuidv4)();
- #logger;
- constructor(channel, logger) {
- this.#properties = channel;
- this.#logger = logger;
- }
- /**
- * Creates a channel proxy in the given realm, initialises listener and
- * returns a handle to `sendMessage` delegate.
- */
- async init(realm, eventManager) {
- const channelHandle = await ChannelProxy.#createAndGetHandleInRealm(realm);
- const sendMessageHandle = await ChannelProxy.#createSendMessageHandle(realm, channelHandle);
- void this.#startListener(realm, channelHandle, eventManager);
- return sendMessageHandle;
- }
- /** Gets a ChannelProxy from window and returns its handle. */
- async startListenerFromWindow(realm, eventManager) {
- try {
- const channelHandle = await this.#getHandleFromWindow(realm);
- void this.#startListener(realm, channelHandle, eventManager);
- }
- catch (error) {
- this.#logger?.(log_js_1$c.LogType.debugError, error);
- }
- }
- /**
- * Evaluation string which creates a ChannelProxy object on the client side.
- */
- static #createChannelProxyEvalStr() {
- const functionStr = String(() => {
- const queue = [];
- let queueNonEmptyResolver = null;
- return {
- /**
- * Gets a promise, which is resolved as soon as a message occurs
- * in the queue.
- */
- async getMessage() {
- const onMessage = queue.length > 0
- ? Promise.resolve()
- : new Promise((resolve) => {
- queueNonEmptyResolver = resolve;
- });
- await onMessage;
- return queue.shift();
- },
- /**
- * Adds a message to the queue.
- * Resolves the pending promise if needed.
- */
- sendMessage(message) {
- queue.push(message);
- if (queueNonEmptyResolver !== null) {
- queueNonEmptyResolver();
- queueNonEmptyResolver = null;
- }
- },
- };
- });
- return `(${functionStr})()`;
- }
- /** Creates a ChannelProxy in the given realm. */
- static async #createAndGetHandleInRealm(realm) {
- const createChannelHandleResult = await realm.cdpClient.sendCommand('Runtime.evaluate', {
- expression: this.#createChannelProxyEvalStr(),
- contextId: realm.executionContextId,
- serializationOptions: {
- serialization: "idOnly" /* Protocol.Runtime.SerializationOptionsSerialization.IdOnly */,
- },
- });
- if (createChannelHandleResult.exceptionDetails ||
- createChannelHandleResult.result.objectId === undefined) {
- throw new Error(`Cannot create channel`);
- }
- return createChannelHandleResult.result.objectId;
- }
- /** Gets a handle to `sendMessage` delegate from the ChannelProxy handle. */
- static async #createSendMessageHandle(realm, channelHandle) {
- const sendMessageArgResult = await realm.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((channelHandle) => {
- return channelHandle.sendMessage;
- }),
- arguments: [{ objectId: channelHandle }],
- executionContextId: realm.executionContextId,
- serializationOptions: {
- serialization: "idOnly" /* Protocol.Runtime.SerializationOptionsSerialization.IdOnly */,
- },
- });
- // TODO: check for exceptionDetails.
- return sendMessageArgResult.result.objectId;
- }
- /** Starts listening for the channel events of the provided ChannelProxy. */
- async #startListener(realm, channelHandle, eventManager) {
- // noinspection InfiniteLoopJS
- for (;;) {
- try {
- const message = await realm.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String(async (channelHandle) => await channelHandle.getMessage()),
- arguments: [
- {
- objectId: channelHandle,
- },
- ],
- awaitPromise: true,
- executionContextId: realm.executionContextId,
- serializationOptions: {
- serialization: "deep" /* Protocol.Runtime.SerializationOptionsSerialization.Deep */,
- maxDepth: this.#properties.serializationOptions?.maxObjectDepth ??
- undefined,
- },
- });
- if (message.exceptionDetails) {
- throw message.exceptionDetails;
- }
- for (const browsingContext of realm.associatedBrowsingContexts) {
- eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$f.ChromiumBidi.Script.EventNames.Message,
- params: {
- channel: this.#properties.channel,
- data: realm.cdpToBidiValue(message, this.#properties.ownership ?? "none" /* Script.ResultOwnership.None */),
- source: realm.source,
- },
- }, browsingContext.id);
- }
- }
- catch (error) {
- // If an error is thrown, then the channel is permanently broken, so we
- // exit the loop.
- this.#logger?.(log_js_1$c.LogType.debugError, error);
- break;
- }
- }
- }
- /**
- * Returns a handle of ChannelProxy from window's property which was set there
- * by `getEvalInWindowStr`. If window property is not set yet, sets a promise
- * resolver to the window property, so that `getEvalInWindowStr` can resolve
- * the promise later on with the channel.
- * This is needed because `getEvalInWindowStr` can be called before or
- * after this method.
- */
- async #getHandleFromWindow(realm) {
- const channelHandleResult = await realm.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((id) => {
- const w = window;
- if (w[id] === undefined) {
- // The channelProxy is not created yet. Create a promise, put the
- // resolver to window property and return the promise.
- // `getEvalInWindowStr` will resolve the promise later.
- return new Promise((resolve) => (w[id] = resolve));
- }
- // The channelProxy is already created by `getEvalInWindowStr` and
- // is set into window property. Return it.
- const channelProxy = w[id];
- delete w[id];
- return channelProxy;
- }),
- arguments: [{ value: this.#id }],
- executionContextId: realm.executionContextId,
- awaitPromise: true,
- serializationOptions: {
- serialization: "idOnly" /* Protocol.Runtime.SerializationOptionsSerialization.IdOnly */,
- },
- });
- if (channelHandleResult.exceptionDetails !== undefined ||
- channelHandleResult.result.objectId === undefined) {
- throw new Error(`ChannelHandle not found in window["${this.#id}"]`);
- }
- return channelHandleResult.result.objectId;
- }
- /**
- * String to be evaluated to create a ProxyChannel and put it to window.
- * Returns the delegate `sendMessage`. Used to provide an argument for preload
- * script. Does the following:
- * 1. Creates a ChannelProxy.
- * 2. Puts the ChannelProxy to window['${this.#id}'] or resolves the promise
- * by calling delegate stored in window['${this.#id}'].
- * This is needed because `#getHandleFromWindow` can be called before or
- * after this method.
- * 3. Returns the delegate `sendMessage` of the created ChannelProxy.
- */
- getEvalInWindowStr() {
- const delegate = String((id, channelProxy) => {
- const w = window;
- if (w[id] === undefined) {
- // `#getHandleFromWindow` is not initialized yet, and will get the
- // channelProxy later.
- w[id] = channelProxy;
- }
- else {
- // `#getHandleFromWindow` is already set a delegate to window property
- // and is waiting for it to be called with the channelProxy.
- w[id](channelProxy);
- delete w[id];
- }
- return channelProxy.sendMessage;
- });
- const channelProxyEval = ChannelProxy.#createChannelProxyEvalStr();
- return `(${delegate})('${this.#id}',${channelProxyEval})`;
- }
- }
- ChannelProxy$1.ChannelProxy = ChannelProxy;
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- Object.defineProperty(PreloadScript$1, "__esModule", { value: true });
- PreloadScript$1.PreloadScript = void 0;
- const uuid_js_1$2 = uuid;
- const ChannelProxy_js_1$1 = ChannelProxy$1;
- /**
- * BiDi IDs are generated by the server and are unique within contexts.
- *
- * CDP preload script IDs are generated by the client and are unique
- * within sessions.
- *
- * The mapping between BiDi and CDP preload script IDs is 1:many.
- * BiDi IDs are needed by the mapper to keep track of potential multiple CDP IDs
- * in the client.
- */
- class PreloadScript {
- /** BiDi ID, an automatically generated UUID. */
- #id = (0, uuid_js_1$2.uuidv4)();
- /** CDP preload scripts. */
- #cdpPreloadScripts = [];
- /** The script itself, in a format expected by the spec i.e. a function. */
- #functionDeclaration;
- /** Targets, in which the preload script is initialized. */
- #targetIds = new Set();
- /** Channels to be added as arguments to functionDeclaration. */
- #channels;
- /** The script sandbox / world name. */
- #sandbox;
- /** The browsing contexts to execute the preload scripts in, if any. */
- #contexts;
- get id() {
- return this.#id;
- }
- get targetIds() {
- return this.#targetIds;
- }
- constructor(params, logger) {
- this.#channels =
- params.arguments?.map((a) => new ChannelProxy_js_1$1.ChannelProxy(a.value, logger)) ?? [];
- this.#functionDeclaration = params.functionDeclaration;
- this.#sandbox = params.sandbox;
- this.#contexts = params.contexts;
- }
- /** Channels of the preload script. */
- get channels() {
- return this.#channels;
- }
- /** Contexts of the preload script, if any */
- get contexts() {
- return this.#contexts;
- }
- /**
- * String to be evaluated. Wraps user-provided function so that the following
- * steps are run:
- * 1. Create channels.
- * 2. Store the created channels in window.
- * 3. Call the user-provided function with channels as arguments.
- */
- #getEvaluateString() {
- const channelsArgStr = `[${this.channels
- .map((c) => c.getEvalInWindowStr())
- .join(', ')}]`;
- return `(()=>{(${this.#functionDeclaration})(...${channelsArgStr})})()`;
- }
- /**
- * Adds the script to the given CDP targets by calling the
- * `Page.addScriptToEvaluateOnNewDocument` command.
- */
- async initInTargets(cdpTargets, runImmediately) {
- await Promise.all(Array.from(cdpTargets).map((cdpTarget) => this.initInTarget(cdpTarget, runImmediately)));
- }
- /**
- * Adds the script to the given CDP target by calling the
- * `Page.addScriptToEvaluateOnNewDocument` command.
- */
- async initInTarget(cdpTarget, runImmediately) {
- const addCdpPreloadScriptResult = await cdpTarget.cdpClient.sendCommand('Page.addScriptToEvaluateOnNewDocument', {
- source: this.#getEvaluateString(),
- worldName: this.#sandbox,
- runImmediately,
- });
- this.#cdpPreloadScripts.push({
- target: cdpTarget,
- preloadScriptId: addCdpPreloadScriptResult.identifier,
- });
- this.#targetIds.add(cdpTarget.id);
- }
- /**
- * Removes this script from all CDP targets.
- */
- async remove() {
- await Promise.all([
- this.#cdpPreloadScripts.map(async (cdpPreloadScript) => {
- const cdpTarget = cdpPreloadScript.target;
- const cdpPreloadScriptId = cdpPreloadScript.preloadScriptId;
- return await cdpTarget.cdpClient.sendCommand('Page.removeScriptToEvaluateOnNewDocument', {
- identifier: cdpPreloadScriptId,
- });
- }),
- ]);
- }
- /** Removes the provided cdp target from the list of cdp preload scripts. */
- dispose(cdpTargetId) {
- this.#cdpPreloadScripts = this.#cdpPreloadScripts.filter((cdpPreloadScript) => cdpPreloadScript.target?.id !== cdpTargetId);
- this.#targetIds.delete(cdpTargetId);
- }
- }
- PreloadScript$1.PreloadScript = PreloadScript;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(ScriptProcessor$1, "__esModule", { value: true });
- ScriptProcessor$1.ScriptProcessor = void 0;
- const protocol_js_1$e = protocol;
- const PreloadScript_js_1 = PreloadScript$1;
- class ScriptProcessor {
- #browsingContextStorage;
- #realmStorage;
- #preloadScriptStorage;
- #logger;
- constructor(browsingContextStorage, realmStorage, preloadScriptStorage, logger) {
- this.#browsingContextStorage = browsingContextStorage;
- this.#realmStorage = realmStorage;
- this.#preloadScriptStorage = preloadScriptStorage;
- this.#logger = logger;
- }
- async addPreloadScript(params) {
- const contexts = this.#browsingContextStorage.verifyTopLevelContextsList(params.contexts);
- const preloadScript = new PreloadScript_js_1.PreloadScript(params, this.#logger);
- this.#preloadScriptStorage.add(preloadScript);
- const cdpTargets = contexts.size === 0
- ? new Set(this.#browsingContextStorage
- .getTopLevelContexts()
- .map((context) => context.cdpTarget))
- : new Set([...contexts.values()].map((context) => context.cdpTarget));
- await preloadScript.initInTargets(cdpTargets, false);
- return {
- script: preloadScript.id,
- };
- }
- async removePreloadScript(params) {
- const { script: id } = params;
- const scripts = this.#preloadScriptStorage.find({ id });
- if (scripts.length === 0) {
- throw new protocol_js_1$e.NoSuchScriptException(`No preload script with id '${id}'`);
- }
- await Promise.all(scripts.map((script) => script.remove()));
- this.#preloadScriptStorage.remove({ id });
- return {};
- }
- async callFunction(params) {
- const realm = await this.#getRealm(params.target);
- return await realm.callFunction(params.functionDeclaration, params.awaitPromise, params.this, params.arguments, params.resultOwnership, params.serializationOptions, params.userActivation);
- }
- async evaluate(params) {
- const realm = await this.#getRealm(params.target);
- return await realm.evaluate(params.expression, params.awaitPromise, params.resultOwnership, params.serializationOptions, params.userActivation);
- }
- async disown(params) {
- const realm = await this.#getRealm(params.target);
- await Promise.all(params.handles.map(async (handle) => await realm.disown(handle)));
- return {};
- }
- getRealms(params) {
- if (params.context !== undefined) {
- // Make sure the context is known.
- this.#browsingContextStorage.getContext(params.context);
- }
- const realms = this.#realmStorage
- .findRealms({
- browsingContextId: params.context,
- type: params.type,
- })
- .map((realm) => realm.realmInfo);
- return { realms };
- }
- async #getRealm(target) {
- if ('context' in target) {
- const context = this.#browsingContextStorage.getContext(target.context);
- return await context.getOrCreateSandbox(target.sandbox);
- }
- return this.#realmStorage.getRealm({
- realmId: target.realm,
- });
- }
- }
- ScriptProcessor$1.ScriptProcessor = ScriptProcessor;
- var SessionProcessor$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(SessionProcessor$1, "__esModule", { value: true });
- SessionProcessor$1.SessionProcessor = void 0;
- class SessionProcessor {
- #eventManager;
- #browserCdpClient;
- constructor(eventManager, browserCdpClient) {
- this.#eventManager = eventManager;
- this.#browserCdpClient = browserCdpClient;
- }
- status() {
- return { ready: false, message: 'already connected' };
- }
- async create(_params) {
- // Since mapper exists, there is a session already.
- // Still the mapper can handle capabilities for us.
- // Currently, only Puppeteer calls here but, eventually, every client
- // should delegrate capability processing here.
- const version = await this.#browserCdpClient.sendCommand('Browser.getVersion');
- return {
- sessionId: 'unknown',
- capabilities: {
- acceptInsecureCerts: false,
- browserName: version.product,
- browserVersion: version.revision,
- platformName: '',
- setWindowRect: false,
- webSocketUrl: '',
- userAgent: version.userAgent,
- },
- };
- }
- async subscribe(params, channel = null) {
- await this.#eventManager.subscribe(params.events, params.contexts ?? [null], channel);
- return {};
- }
- async unsubscribe(params, channel = null) {
- await this.#eventManager.unsubscribe(params.events, params.contexts ?? [null], channel);
- return {};
- }
- }
- SessionProcessor$1.SessionProcessor = SessionProcessor;
- var StorageProcessor$1 = {};
- Object.defineProperty(StorageProcessor$1, "__esModule", { value: true });
- StorageProcessor$1.StorageProcessor = void 0;
- const protocol_js_1$d = protocol;
- const assert_js_1$3 = assert$1;
- const log_js_1$b = log$1;
- const NetworkProcessor_js_1$1 = NetworkProcessor$1;
- const NetworkUtils_js_1$2 = NetworkUtils;
- /**
- * Responsible for handling the `storage` domain.
- */
- class StorageProcessor {
- #browserCdpClient;
- #browsingContextStorage;
- #logger;
- constructor(browserCdpClient, browsingContextStorage, logger) {
- this.#browsingContextStorage = browsingContextStorage;
- this.#browserCdpClient = browserCdpClient;
- this.#logger = logger;
- }
- async deleteCookies(params) {
- const partitionKey = this.#expandStoragePartitionSpec(params.partition);
- let cdpResponse;
- try {
- cdpResponse = await this.#browserCdpClient.sendCommand('Storage.getCookies', {
- browserContextId: this.#getCdpBrowserContextId(partitionKey),
- });
- }
- catch (err) {
- if (this.#isNoSuchUserContextError(err)) {
- // If the user context is not found, special error is thrown.
- throw new protocol_js_1$d.NoSuchUserContextException(err.message);
- }
- throw err;
- }
- const cdpCookiesToDelete = cdpResponse.cookies
- .filter(
- // CDP's partition key is the source origin. If the request specifies the
- // `sourceOrigin` partition key, only cookies with the requested source origin
- // are returned.
- (c) => partitionKey.sourceOrigin === undefined ||
- c.partitionKey === partitionKey.sourceOrigin)
- .filter((cdpCookie) => {
- const bidiCookie = (0, NetworkUtils_js_1$2.cdpToBiDiCookie)(cdpCookie);
- return this.#matchCookie(bidiCookie, params.filter);
- })
- .map((cookie) => ({
- ...cookie,
- // Set expiry to pass date to delete the cookie.
- expires: 1,
- }));
- await this.#browserCdpClient.sendCommand('Storage.setCookies', {
- cookies: cdpCookiesToDelete,
- browserContextId: this.#getCdpBrowserContextId(partitionKey),
- });
- return {
- partitionKey,
- };
- }
- async getCookies(params) {
- const partitionKey = this.#expandStoragePartitionSpec(params.partition);
- let cdpResponse;
- try {
- cdpResponse = await this.#browserCdpClient.sendCommand('Storage.getCookies', {
- browserContextId: this.#getCdpBrowserContextId(partitionKey),
- });
- }
- catch (err) {
- if (this.#isNoSuchUserContextError(err)) {
- // If the user context is not found, special error is thrown.
- throw new protocol_js_1$d.NoSuchUserContextException(err.message);
- }
- throw err;
- }
- const filteredBiDiCookies = cdpResponse.cookies
- .filter(
- // CDP's partition key is the source origin. If the request specifies the
- // `sourceOrigin` partition key, only cookies with the requested source origin
- // are returned.
- (c) => partitionKey.sourceOrigin === undefined ||
- c.partitionKey === partitionKey.sourceOrigin)
- .map((c) => (0, NetworkUtils_js_1$2.cdpToBiDiCookie)(c))
- .filter((c) => this.#matchCookie(c, params.filter));
- return {
- cookies: filteredBiDiCookies,
- partitionKey,
- };
- }
- async setCookie(params) {
- const partitionKey = this.#expandStoragePartitionSpec(params.partition);
- const cdpCookie = (0, NetworkUtils_js_1$2.bidiToCdpCookie)(params, partitionKey);
- try {
- await this.#browserCdpClient.sendCommand('Storage.setCookies', {
- cookies: [cdpCookie],
- browserContextId: this.#getCdpBrowserContextId(partitionKey),
- });
- }
- catch (err) {
- if (this.#isNoSuchUserContextError(err)) {
- // If the user context is not found, special error is thrown.
- throw new protocol_js_1$d.NoSuchUserContextException(err.message);
- }
- this.#logger?.(log_js_1$b.LogType.debugError, err);
- throw new protocol_js_1$d.UnableToSetCookieException(err.toString());
- }
- return {
- partitionKey,
- };
- }
- #isNoSuchUserContextError(err) {
- // Heuristic to detect if the user context is not found.
- // See https://source.chromium.org/chromium/chromium/src/+/main:content/browser/devtools/protocol/browser_handler.cc;drc=a56154dd81e4679712422ac6eed2c9581cb51ab0;l=314
- return err.message?.startsWith('Failed to find browser context for id');
- }
- #getCdpBrowserContextId(partitionKey) {
- return partitionKey.userContext === 'default'
- ? undefined
- : partitionKey.userContext;
- }
- #expandStoragePartitionSpecByBrowsingContext(descriptor) {
- const browsingContextId = descriptor.context;
- const browsingContext = this.#browsingContextStorage.getContext(browsingContextId);
- // https://w3c.github.io/webdriver-bidi/#associated-storage-partition.
- // Each browsing context also has an associated storage partition, which is the
- // storage partition it uses to persist data. In Chromium it's a `BrowserContext`
- // which maps to BiDi `UserContext`.
- return {
- userContext: browsingContext.userContext,
- };
- }
- #expandStoragePartitionSpecByStorageKey(descriptor) {
- const unsupportedPartitionKeys = new Map();
- let sourceOrigin = descriptor.sourceOrigin;
- if (sourceOrigin !== undefined) {
- const url = NetworkProcessor_js_1$1.NetworkProcessor.parseUrlString(sourceOrigin);
- if (url.origin === 'null') {
- // Origin `null` is a special case for local pages.
- sourceOrigin = url.origin;
- }
- else {
- // Port is not supported in CDP Cookie's `partitionKey`, so it should be stripped
- // from the requested source origin.
- sourceOrigin = `${url.protocol}//${url.hostname}`;
- }
- }
- for (const [key, value] of Object.entries(descriptor)) {
- if (key !== undefined &&
- value !== undefined &&
- !['type', 'sourceOrigin', 'userContext'].includes(key)) {
- unsupportedPartitionKeys.set(key, value);
- }
- }
- if (unsupportedPartitionKeys.size > 0) {
- this.#logger?.(log_js_1$b.LogType.debugInfo, `Unsupported partition keys: ${JSON.stringify(Object.fromEntries(unsupportedPartitionKeys))}`);
- }
- // Set `userContext` to `default` if not provided, as it's required in Chromium.
- const userContext = descriptor.userContext ?? 'default';
- return {
- userContext,
- ...(sourceOrigin === undefined ? {} : { sourceOrigin }),
- };
- }
- #expandStoragePartitionSpec(partitionSpec) {
- if (partitionSpec === undefined) {
- // `userContext` is required in Chromium.
- return { userContext: 'default' };
- }
- if (partitionSpec.type === 'context') {
- return this.#expandStoragePartitionSpecByBrowsingContext(partitionSpec);
- }
- (0, assert_js_1$3.assert)(partitionSpec.type === 'storageKey', 'Unknown partition type');
- // Partition spec is a storage partition.
- // Let partition key be partition spec.
- return this.#expandStoragePartitionSpecByStorageKey(partitionSpec);
- }
- #matchCookie(cookie, filter) {
- if (filter === undefined) {
- return true;
- }
- return ((filter.domain === undefined || filter.domain === cookie.domain) &&
- (filter.name === undefined || filter.name === cookie.name) &&
- // `value` contains fields `type` and `value`.
- (filter.value === undefined ||
- (0, NetworkUtils_js_1$2.deserializeByteValue)(filter.value) ===
- (0, NetworkUtils_js_1$2.deserializeByteValue)(cookie.value)) &&
- (filter.path === undefined || filter.path === cookie.path) &&
- (filter.size === undefined || filter.size === cookie.size) &&
- (filter.httpOnly === undefined || filter.httpOnly === cookie.httpOnly) &&
- (filter.secure === undefined || filter.secure === cookie.secure) &&
- (filter.sameSite === undefined || filter.sameSite === cookie.sameSite) &&
- (filter.expiry === undefined || filter.expiry === cookie.expiry));
- }
- }
- StorageProcessor$1.StorageProcessor = StorageProcessor;
- var OutgoingMessage$1 = {};
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(OutgoingMessage$1, "__esModule", { value: true });
- OutgoingMessage$1.OutgoingMessage = void 0;
- class OutgoingMessage {
- #message;
- #channel;
- constructor(message, channel = null) {
- this.#message = message;
- this.#channel = channel;
- }
- static createFromPromise(messagePromise, channel) {
- return messagePromise.then((message) => {
- if (message.kind === 'success') {
- return {
- kind: 'success',
- value: new OutgoingMessage(message.value, channel),
- };
- }
- return message;
- });
- }
- static createResolved(message, channel) {
- return Promise.resolve({
- kind: 'success',
- value: new OutgoingMessage(message, channel),
- });
- }
- get message() {
- return this.#message;
- }
- get channel() {
- return this.#channel;
- }
- }
- OutgoingMessage$1.OutgoingMessage = OutgoingMessage;
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(CommandProcessor$1, "__esModule", { value: true });
- CommandProcessor$1.CommandProcessor = void 0;
- const protocol_js_1$c = protocol;
- const EventEmitter_js_1$3 = EventEmitter$1;
- const log_js_1$a = log$1;
- const BidiNoOpParser_js_1 = BidiNoOpParser$1;
- const BrowserProcessor_js_1 = BrowserProcessor$1;
- const CdpProcessor_js_1 = CdpProcessor$1;
- const BrowsingContextProcessor_js_1 = BrowsingContextProcessor$1;
- const InputProcessor_js_1 = InputProcessor$1;
- const NetworkProcessor_js_1 = NetworkProcessor$1;
- const PermissionsProcessor_js_1 = PermissionsProcessor$1;
- const ScriptProcessor_js_1 = ScriptProcessor$1;
- const SessionProcessor_js_1 = SessionProcessor$1;
- const StorageProcessor_js_1 = StorageProcessor$1;
- const OutgoingMessage_js_1$1 = OutgoingMessage$1;
- class CommandProcessor extends EventEmitter_js_1$3.EventEmitter {
- // keep-sorted start
- #browserProcessor;
- #browsingContextProcessor;
- #cdpProcessor;
- #inputProcessor;
- #networkProcessor;
- #permissionsProcessor;
- #scriptProcessor;
- #sessionProcessor;
- #storageProcessor;
- // keep-sorted end
- #parser;
- #logger;
- constructor(cdpConnection, browserCdpClient, eventManager, browsingContextStorage, realmStorage, preloadScriptStorage, networkStorage, parser = new BidiNoOpParser_js_1.BidiNoOpParser(), logger) {
- super();
- this.#parser = parser;
- this.#logger = logger;
- // keep-sorted start block=yes
- this.#browserProcessor = new BrowserProcessor_js_1.BrowserProcessor(browserCdpClient);
- this.#browsingContextProcessor = new BrowsingContextProcessor_js_1.BrowsingContextProcessor(browserCdpClient, browsingContextStorage);
- this.#cdpProcessor = new CdpProcessor_js_1.CdpProcessor(browsingContextStorage, realmStorage, cdpConnection, browserCdpClient);
- this.#inputProcessor = new InputProcessor_js_1.InputProcessor(browsingContextStorage, realmStorage);
- this.#networkProcessor = new NetworkProcessor_js_1.NetworkProcessor(browsingContextStorage, networkStorage);
- this.#permissionsProcessor = new PermissionsProcessor_js_1.PermissionsProcessor(browserCdpClient);
- this.#scriptProcessor = new ScriptProcessor_js_1.ScriptProcessor(browsingContextStorage, realmStorage, preloadScriptStorage, logger);
- this.#sessionProcessor = new SessionProcessor_js_1.SessionProcessor(eventManager, browserCdpClient);
- this.#storageProcessor = new StorageProcessor_js_1.StorageProcessor(browserCdpClient, browsingContextStorage, logger);
- // keep-sorted end
- }
- async #processCommand(command) {
- switch (command.method) {
- case 'session.end':
- // TODO: Implement.
- break;
- // Browser domain
- // keep-sorted start block=yes
- case 'browser.close':
- return this.#browserProcessor.close();
- case 'browser.createUserContext':
- return await this.#browserProcessor.createUserContext(command.params);
- case 'browser.getUserContexts':
- return await this.#browserProcessor.getUserContexts();
- case 'browser.removeUserContext':
- return await this.#browserProcessor.removeUserContext(this.#parser.parseRemoveUserContextParams(command.params));
- // keep-sorted end
- // Browsing Context domain
- // keep-sorted start block=yes
- case 'browsingContext.activate':
- return await this.#browsingContextProcessor.activate(this.#parser.parseActivateParams(command.params));
- case 'browsingContext.captureScreenshot':
- return await this.#browsingContextProcessor.captureScreenshot(this.#parser.parseCaptureScreenshotParams(command.params));
- case 'browsingContext.close':
- return await this.#browsingContextProcessor.close(this.#parser.parseCloseParams(command.params));
- case 'browsingContext.create':
- return await this.#browsingContextProcessor.create(this.#parser.parseCreateParams(command.params));
- case 'browsingContext.getTree':
- return this.#browsingContextProcessor.getTree(this.#parser.parseGetTreeParams(command.params));
- case 'browsingContext.handleUserPrompt':
- return await this.#browsingContextProcessor.handleUserPrompt(this.#parser.parseHandleUserPromptParams(command.params));
- case 'browsingContext.locateNodes':
- return await this.#browsingContextProcessor.locateNodes(this.#parser.parseLocateNodesParams(command.params));
- case 'browsingContext.navigate':
- return await this.#browsingContextProcessor.navigate(this.#parser.parseNavigateParams(command.params));
- case 'browsingContext.print':
- return await this.#browsingContextProcessor.print(this.#parser.parsePrintParams(command.params));
- case 'browsingContext.reload':
- return await this.#browsingContextProcessor.reload(this.#parser.parseReloadParams(command.params));
- case 'browsingContext.setViewport':
- return await this.#browsingContextProcessor.setViewport(this.#parser.parseSetViewportParams(command.params));
- case 'browsingContext.traverseHistory':
- return await this.#browsingContextProcessor.traverseHistory(this.#parser.parseTraverseHistoryParams(command.params));
- // keep-sorted end
- // CDP domain
- // keep-sorted start block=yes
- case 'cdp.getSession':
- return this.#cdpProcessor.getSession(this.#parser.parseGetSessionParams(command.params));
- case 'cdp.resolveRealm':
- return this.#cdpProcessor.resolveRealm(this.#parser.parseResolveRealmParams(command.params));
- case 'cdp.sendCommand':
- return await this.#cdpProcessor.sendCommand(this.#parser.parseSendCommandParams(command.params));
- // keep-sorted end
- // Input domain
- // keep-sorted start block=yes
- case 'input.performActions':
- return await this.#inputProcessor.performActions(this.#parser.parsePerformActionsParams(command.params));
- case 'input.releaseActions':
- return await this.#inputProcessor.releaseActions(this.#parser.parseReleaseActionsParams(command.params));
- case 'input.setFiles':
- return await this.#inputProcessor.setFiles(this.#parser.parseSetFilesParams(command.params));
- // keep-sorted end
- // Network domain
- // keep-sorted start block=yes
- case 'network.addIntercept':
- return await this.#networkProcessor.addIntercept(this.#parser.parseAddInterceptParams(command.params));
- case 'network.continueRequest':
- return await this.#networkProcessor.continueRequest(this.#parser.parseContinueRequestParams(command.params));
- case 'network.continueResponse':
- return await this.#networkProcessor.continueResponse(this.#parser.parseContinueResponseParams(command.params));
- case 'network.continueWithAuth':
- return await this.#networkProcessor.continueWithAuth(this.#parser.parseContinueWithAuthParams(command.params));
- case 'network.failRequest':
- return await this.#networkProcessor.failRequest(this.#parser.parseFailRequestParams(command.params));
- case 'network.provideResponse':
- return await this.#networkProcessor.provideResponse(this.#parser.parseProvideResponseParams(command.params));
- case 'network.removeIntercept':
- return await this.#networkProcessor.removeIntercept(this.#parser.parseRemoveInterceptParams(command.params));
- // keep-sorted end
- // Permissions domain
- // keep-sorted start block=yes
- case 'permissions.setPermission':
- return await this.#permissionsProcessor.setPermissions(this.#parser.parseSetPermissionsParams(command.params));
- // keep-sorted end
- // Script domain
- // keep-sorted start block=yes
- case 'script.addPreloadScript':
- return await this.#scriptProcessor.addPreloadScript(this.#parser.parseAddPreloadScriptParams(command.params));
- case 'script.callFunction':
- return await this.#scriptProcessor.callFunction(this.#parser.parseCallFunctionParams(this.#processTargetParams(command.params)));
- case 'script.disown':
- return await this.#scriptProcessor.disown(this.#parser.parseDisownParams(this.#processTargetParams(command.params)));
- case 'script.evaluate':
- return await this.#scriptProcessor.evaluate(this.#parser.parseEvaluateParams(this.#processTargetParams(command.params)));
- case 'script.getRealms':
- return this.#scriptProcessor.getRealms(this.#parser.parseGetRealmsParams(command.params));
- case 'script.removePreloadScript':
- return await this.#scriptProcessor.removePreloadScript(this.#parser.parseRemovePreloadScriptParams(command.params));
- // keep-sorted end
- // Session domain
- // keep-sorted start block=yes
- case 'session.new':
- return await this.#sessionProcessor.create(command.params);
- case 'session.status':
- return this.#sessionProcessor.status();
- case 'session.subscribe':
- return await this.#sessionProcessor.subscribe(this.#parser.parseSubscribeParams(command.params), command.channel);
- case 'session.unsubscribe':
- return await this.#sessionProcessor.unsubscribe(this.#parser.parseSubscribeParams(command.params), command.channel);
- // keep-sorted end
- // Storage domain
- // keep-sorted start block=yes
- case 'storage.deleteCookies':
- return await this.#storageProcessor.deleteCookies(this.#parser.parseDeleteCookiesParams(command.params));
- case 'storage.getCookies':
- return await this.#storageProcessor.getCookies(this.#parser.parseGetCookiesParams(command.params));
- case 'storage.setCookie':
- return await this.#storageProcessor.setCookie(this.#parser.parseSetCookieParams(command.params));
- // keep-sorted end
- }
- // Intentionally kept outside the switch statement to ensure that
- // ESLint @typescript-eslint/switch-exhaustiveness-check triggers if a new
- // command is added.
- throw new protocol_js_1$c.UnknownCommandException(`Unknown command '${command.method}'.`);
- }
- // Workaround for as zod.union always take the first schema
- // https://github.com/w3c/webdriver-bidi/issues/635
- #processTargetParams(params) {
- if (typeof params === 'object' &&
- params &&
- 'target' in params &&
- typeof params.target === 'object' &&
- params.target &&
- 'context' in params.target) {
- delete params.target['realm'];
- }
- return params;
- }
- async processCommand(command) {
- try {
- const result = await this.#processCommand(command);
- const response = {
- type: 'success',
- id: command.id,
- result,
- };
- this.emit("response" /* CommandProcessorEvents.Response */, {
- message: OutgoingMessage_js_1$1.OutgoingMessage.createResolved(response, command.channel),
- event: command.method,
- });
- }
- catch (e) {
- if (e instanceof protocol_js_1$c.Exception) {
- this.emit("response" /* CommandProcessorEvents.Response */, {
- message: OutgoingMessage_js_1$1.OutgoingMessage.createResolved(e.toErrorResponse(command.id), command.channel),
- event: command.method,
- });
- }
- else {
- const error = e;
- this.#logger?.(log_js_1$a.LogType.bidi, error);
- this.emit("response" /* CommandProcessorEvents.Response */, {
- message: OutgoingMessage_js_1$1.OutgoingMessage.createResolved(new protocol_js_1$c.UnknownErrorException(error.message, error.stack).toErrorResponse(command.id), command.channel),
- event: command.method,
- });
- }
- }
- }
- }
- CommandProcessor$1.CommandProcessor = CommandProcessor;
- var CdpTargetManager$1 = {};
- var BrowsingContextImpl$1 = {};
- var Deferred$1 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(Deferred$1, "__esModule", { value: true });
- Deferred$1.Deferred = void 0;
- class Deferred {
- #isFinished = false;
- #promise;
- #resolve;
- #reject;
- get isFinished() {
- return this.#isFinished;
- }
- constructor() {
- this.#promise = new Promise((resolve, reject) => {
- this.#resolve = resolve;
- this.#reject = reject;
- });
- // Needed to avoid `Uncaught (in promise)`. The promises returned by `then`
- // and `catch` will be rejected anyway.
- this.#promise.catch((_error) => {
- // Intentionally empty.
- });
- }
- then(onFulfilled, onRejected) {
- return this.#promise.then(onFulfilled, onRejected);
- }
- catch(onRejected) {
- return this.#promise.catch(onRejected);
- }
- resolve(value) {
- if (!this.#isFinished) {
- this.#isFinished = true;
- this.#resolve(value);
- }
- }
- reject(reason) {
- if (!this.#isFinished) {
- this.#isFinished = true;
- this.#reject(reason);
- }
- }
- finally(onFinally) {
- return this.#promise.finally(onFinally);
- }
- [Symbol.toStringTag] = 'Promise';
- }
- Deferred$1.Deferred = Deferred;
- var unitConversions = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(unitConversions, "__esModule", { value: true });
- unitConversions.inchesFromCm = void 0;
- /** @return Given an input in cm, convert it to inches. */
- function inchesFromCm(cm) {
- return cm / 2.54;
- }
- unitConversions.inchesFromCm = inchesFromCm;
- var WindowRealm$1 = {};
- var Realm$1 = {};
- Object.defineProperty(Realm$1, "__esModule", { value: true });
- Realm$1.Realm = void 0;
- const protocol_js_1$b = protocol;
- const log_js_1$9 = log$1;
- const uuid_js_1$1 = uuid;
- const ChannelProxy_js_1 = ChannelProxy$1;
- class Realm {
- #cdpClient;
- #eventManager;
- #executionContextId;
- #logger;
- #origin;
- #realmId;
- #realmStorage;
- constructor(cdpClient, eventManager, executionContextId, logger, origin, realmId, realmStorage) {
- this.#cdpClient = cdpClient;
- this.#eventManager = eventManager;
- this.#executionContextId = executionContextId;
- this.#logger = logger;
- this.#origin = origin;
- this.#realmId = realmId;
- this.#realmStorage = realmStorage;
- this.#realmStorage.addRealm(this);
- }
- cdpToBidiValue(cdpValue, resultOwnership) {
- const bidiValue = this.serializeForBiDi(cdpValue.result.deepSerializedValue, new Map());
- if (cdpValue.result.objectId) {
- const objectId = cdpValue.result.objectId;
- if (resultOwnership === "root" /* Script.ResultOwnership.Root */) {
- // Extend BiDi value with `handle` based on required `resultOwnership`
- // and CDP response but not on the actual BiDi type.
- bidiValue.handle = objectId;
- // Remember all the handles sent to client.
- this.#realmStorage.knownHandlesToRealmMap.set(objectId, this.realmId);
- }
- else {
- // No need to await for the object to be released.
- void this.#releaseObject(objectId).catch((error) => this.#logger?.(log_js_1$9.LogType.debugError, error));
- }
- }
- return bidiValue;
- }
- /**
- * Relies on the CDP to implement proper BiDi serialization, except:
- * * CDP integer property `backendNodeId` is replaced with `sharedId` of
- * `{documentId}_element_{backendNodeId}`;
- * * CDP integer property `weakLocalObjectReference` is replaced with UUID `internalId`
- * using unique-per serialization `internalIdMap`.
- * * CDP type `platformobject` is replaced with `object`.
- * @param deepSerializedValue - CDP value to be converted to BiDi.
- * @param internalIdMap - Map from CDP integer `weakLocalObjectReference` to BiDi UUID
- * `internalId`.
- */
- serializeForBiDi(deepSerializedValue, internalIdMap) {
- if (Object.hasOwn(deepSerializedValue, 'weakLocalObjectReference')) {
- const weakLocalObjectReference = deepSerializedValue.weakLocalObjectReference;
- if (!internalIdMap.has(weakLocalObjectReference)) {
- internalIdMap.set(weakLocalObjectReference, (0, uuid_js_1$1.uuidv4)());
- }
- deepSerializedValue.internalId = internalIdMap.get(weakLocalObjectReference);
- delete deepSerializedValue['weakLocalObjectReference'];
- }
- // Platform object is a special case. It should have only `{type: object}`
- // without `value` field.
- if (deepSerializedValue.type === 'platformobject') {
- return { type: 'object' };
- }
- const bidiValue = deepSerializedValue.value;
- if (bidiValue === undefined) {
- return deepSerializedValue;
- }
- // Recursively update the nested values.
- if (['array', 'set', 'htmlcollection', 'nodelist'].includes(deepSerializedValue.type)) {
- for (const i in bidiValue) {
- bidiValue[i] = this.serializeForBiDi(bidiValue[i], internalIdMap);
- }
- }
- if (['object', 'map'].includes(deepSerializedValue.type)) {
- for (const i in bidiValue) {
- bidiValue[i] = [
- this.serializeForBiDi(bidiValue[i][0], internalIdMap),
- this.serializeForBiDi(bidiValue[i][1], internalIdMap),
- ];
- }
- }
- return deepSerializedValue;
- }
- get realmId() {
- return this.#realmId;
- }
- get executionContextId() {
- return this.#executionContextId;
- }
- get origin() {
- return this.#origin;
- }
- get source() {
- return {
- realm: this.realmId,
- };
- }
- get cdpClient() {
- return this.#cdpClient;
- }
- get baseInfo() {
- return {
- realm: this.realmId,
- origin: this.origin,
- };
- }
- async evaluate(expression, awaitPromise, resultOwnership = "none" /* Script.ResultOwnership.None */, serializationOptions = {}, userActivation = false) {
- const cdpEvaluateResult = await this.cdpClient.sendCommand('Runtime.evaluate', {
- contextId: this.executionContextId,
- expression,
- awaitPromise,
- serializationOptions: Realm.#getSerializationOptions("deep" /* Protocol.Runtime.SerializationOptionsSerialization.Deep */, serializationOptions),
- userGesture: userActivation,
- });
- if (cdpEvaluateResult.exceptionDetails) {
- return await this.#getExceptionResult(cdpEvaluateResult.exceptionDetails, 0, resultOwnership);
- }
- return {
- realm: this.realmId,
- result: this.cdpToBidiValue(cdpEvaluateResult, resultOwnership),
- type: 'success',
- };
- }
- #registerEvent(event) {
- if (this.associatedBrowsingContexts.length === 0) {
- this.#eventManager.registerEvent(event, null);
- }
- else {
- for (const browsingContext of this.associatedBrowsingContexts) {
- this.#eventManager.registerEvent(event, browsingContext.id);
- }
- }
- }
- initialize() {
- this.#registerEvent({
- type: 'event',
- method: protocol_js_1$b.ChromiumBidi.Script.EventNames.RealmCreated,
- params: this.realmInfo,
- });
- }
- /**
- * Serializes a given CDP object into BiDi, keeping references in the
- * target's `globalThis`.
- */
- async serializeCdpObject(cdpRemoteObject, resultOwnership) {
- const argument = Realm.#cdpRemoteObjectToCallArgument(cdpRemoteObject);
- const cdpValue = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((remoteObject) => remoteObject),
- awaitPromise: false,
- arguments: [argument],
- serializationOptions: {
- serialization: "deep" /* Protocol.Runtime.SerializationOptionsSerialization.Deep */,
- },
- executionContextId: this.executionContextId,
- });
- return this.cdpToBidiValue(cdpValue, resultOwnership);
- }
- static #cdpRemoteObjectToCallArgument(cdpRemoteObject) {
- if (cdpRemoteObject.objectId !== undefined) {
- return { objectId: cdpRemoteObject.objectId };
- }
- if (cdpRemoteObject.unserializableValue !== undefined) {
- return { unserializableValue: cdpRemoteObject.unserializableValue };
- }
- return { value: cdpRemoteObject.value };
- }
- /**
- * Gets the string representation of an object. This is equivalent to
- * calling `toString()` on the object value.
- */
- async stringifyObject(cdpRemoteObject) {
- const { result } = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((remoteObject) => String(remoteObject)),
- awaitPromise: false,
- arguments: [cdpRemoteObject],
- returnByValue: true,
- executionContextId: this.executionContextId,
- });
- return result.value;
- }
- async #flattenKeyValuePairs(mappingLocalValue) {
- const keyValueArray = await Promise.all(mappingLocalValue.map(async ([key, value]) => {
- let keyArg;
- if (typeof key === 'string') {
- // Key is a string.
- keyArg = { value: key };
- }
- else {
- // Key is a serialized value.
- keyArg = await this.deserializeForCdp(key);
- }
- const valueArg = await this.deserializeForCdp(value);
- return [keyArg, valueArg];
- }));
- return keyValueArray.flat();
- }
- async #flattenValueList(listLocalValue) {
- return await Promise.all(listLocalValue.map((localValue) => this.deserializeForCdp(localValue)));
- }
- async #serializeCdpExceptionDetails(cdpExceptionDetails, lineOffset, resultOwnership) {
- const callFrames = cdpExceptionDetails.stackTrace?.callFrames.map((frame) => ({
- url: frame.url,
- functionName: frame.functionName,
- lineNumber: frame.lineNumber - lineOffset,
- columnNumber: frame.columnNumber,
- })) ?? [];
- // Exception should always be there.
- const exception = cdpExceptionDetails.exception;
- return {
- exception: await this.serializeCdpObject(exception, resultOwnership),
- columnNumber: cdpExceptionDetails.columnNumber,
- lineNumber: cdpExceptionDetails.lineNumber - lineOffset,
- stackTrace: {
- callFrames,
- },
- text: (await this.stringifyObject(exception)) || cdpExceptionDetails.text,
- };
- }
- async callFunction(functionDeclaration, awaitPromise, thisLocalValue = {
- type: 'undefined',
- }, argumentsLocalValues = [], resultOwnership = "none" /* Script.ResultOwnership.None */, serializationOptions = {}, userActivation = false) {
- const callFunctionAndSerializeScript = `(...args) => {
- function callFunction(f, args) {
- const deserializedThis = args.shift();
- const deserializedArgs = args;
- return f.apply(deserializedThis, deserializedArgs);
- }
- return callFunction((
- ${functionDeclaration}
- ), args);
- }`;
- const thisAndArgumentsList = [
- await this.deserializeForCdp(thisLocalValue),
- ...(await Promise.all(argumentsLocalValues.map(async (argumentLocalValue) => await this.deserializeForCdp(argumentLocalValue)))),
- ];
- let cdpCallFunctionResult;
- try {
- cdpCallFunctionResult = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: callFunctionAndSerializeScript,
- awaitPromise,
- arguments: thisAndArgumentsList,
- serializationOptions: Realm.#getSerializationOptions("deep" /* Protocol.Runtime.SerializationOptionsSerialization.Deep */, serializationOptions),
- executionContextId: this.executionContextId,
- userGesture: userActivation,
- });
- }
- catch (error) {
- // Heuristic to determine if the problem is in the argument.
- // The check can be done on the `deserialization` step, but this approach
- // helps to save round-trips.
- if (error.code === -32000 /* CdpErrorConstants.GENERIC_ERROR */ &&
- [
- 'Could not find object with given id',
- 'Argument should belong to the same JavaScript world as target object',
- 'Invalid remote object id',
- ].includes(error.message)) {
- throw new protocol_js_1$b.NoSuchHandleException('Handle was not found.');
- }
- throw error;
- }
- if (cdpCallFunctionResult.exceptionDetails) {
- return await this.#getExceptionResult(cdpCallFunctionResult.exceptionDetails, 1, resultOwnership);
- }
- return {
- type: 'success',
- result: this.cdpToBidiValue(cdpCallFunctionResult, resultOwnership),
- realm: this.realmId,
- };
- }
- async deserializeForCdp(localValue) {
- if ('handle' in localValue && localValue.handle) {
- return { objectId: localValue.handle };
- // We tried to find a handle value but failed
- // This allows us to have exhaustive switch on `localValue.type`
- }
- else if ('handle' in localValue || 'sharedId' in localValue) {
- throw new protocol_js_1$b.NoSuchHandleException('Handle was not found.');
- }
- switch (localValue.type) {
- case 'undefined':
- return { unserializableValue: 'undefined' };
- case 'null':
- return { unserializableValue: 'null' };
- case 'string':
- return { value: localValue.value };
- case 'number':
- if (localValue.value === 'NaN') {
- return { unserializableValue: 'NaN' };
- }
- else if (localValue.value === '-0') {
- return { unserializableValue: '-0' };
- }
- else if (localValue.value === 'Infinity') {
- return { unserializableValue: 'Infinity' };
- }
- else if (localValue.value === '-Infinity') {
- return { unserializableValue: '-Infinity' };
- }
- return {
- value: localValue.value,
- };
- case 'boolean':
- return { value: Boolean(localValue.value) };
- case 'bigint':
- return {
- unserializableValue: `BigInt(${JSON.stringify(localValue.value)})`,
- };
- case 'date':
- return {
- unserializableValue: `new Date(Date.parse(${JSON.stringify(localValue.value)}))`,
- };
- case 'regexp':
- return {
- unserializableValue: `new RegExp(${JSON.stringify(localValue.value.pattern)}, ${JSON.stringify(localValue.value.flags)})`,
- };
- case 'map': {
- // TODO: If none of the nested keys and values has a remote
- // reference, serialize to `unserializableValue` without CDP roundtrip.
- const keyValueArray = await this.#flattenKeyValuePairs(localValue.value);
- const { result } = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((...args) => {
- const result = new Map();
- for (let i = 0; i < args.length; i += 2) {
- result.set(args[i], args[i + 1]);
- }
- return result;
- }),
- awaitPromise: false,
- arguments: keyValueArray,
- returnByValue: false,
- executionContextId: this.executionContextId,
- });
- // TODO(#375): Release `result.objectId` after using.
- return { objectId: result.objectId };
- }
- case 'object': {
- // TODO: If none of the nested keys and values has a remote
- // reference, serialize to `unserializableValue` without CDP roundtrip.
- const keyValueArray = await this.#flattenKeyValuePairs(localValue.value);
- const { result } = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((...args) => {
- const result = {};
- for (let i = 0; i < args.length; i += 2) {
- // Key should be either `string`, `number`, or `symbol`.
- const key = args[i];
- result[key] = args[i + 1];
- }
- return result;
- }),
- awaitPromise: false,
- arguments: keyValueArray,
- returnByValue: false,
- executionContextId: this.executionContextId,
- });
- // TODO(#375): Release `result.objectId` after using.
- return { objectId: result.objectId };
- }
- case 'array': {
- // TODO: If none of the nested items has a remote reference,
- // serialize to `unserializableValue` without CDP roundtrip.
- const args = await this.#flattenValueList(localValue.value);
- const { result } = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((...args) => args),
- awaitPromise: false,
- arguments: args,
- returnByValue: false,
- executionContextId: this.executionContextId,
- });
- // TODO(#375): Release `result.objectId` after using.
- return { objectId: result.objectId };
- }
- case 'set': {
- // TODO: if none of the nested items has a remote reference,
- // serialize to `unserializableValue` without CDP roundtrip.
- const args = await this.#flattenValueList(localValue.value);
- const { result } = await this.cdpClient.sendCommand('Runtime.callFunctionOn', {
- functionDeclaration: String((...args) => new Set(args)),
- awaitPromise: false,
- arguments: args,
- returnByValue: false,
- executionContextId: this.executionContextId,
- });
- // TODO(#375): Release `result.objectId` after using.
- return { objectId: result.objectId };
- }
- case 'channel': {
- const channelProxy = new ChannelProxy_js_1.ChannelProxy(localValue.value, this.#logger);
- const channelProxySendMessageHandle = await channelProxy.init(this, this.#eventManager);
- return { objectId: channelProxySendMessageHandle };
- }
- // TODO(#375): Dispose of nested objects.
- }
- // Intentionally outside to handle unknown types
- throw new Error(`Value ${JSON.stringify(localValue)} is not deserializable.`);
- }
- async #getExceptionResult(exceptionDetails, lineOffset, resultOwnership) {
- return {
- exceptionDetails: await this.#serializeCdpExceptionDetails(exceptionDetails, lineOffset, resultOwnership),
- realm: this.realmId,
- type: 'exception',
- };
- }
- static #getSerializationOptions(serialization, serializationOptions) {
- return {
- serialization,
- additionalParameters: Realm.#getAdditionalSerializationParameters(serializationOptions),
- ...Realm.#getMaxObjectDepth(serializationOptions),
- };
- }
- static #getAdditionalSerializationParameters(serializationOptions) {
- const additionalParameters = {};
- if (serializationOptions.maxDomDepth !== undefined) {
- additionalParameters['maxNodeDepth'] =
- serializationOptions.maxDomDepth === null
- ? 1000
- : serializationOptions.maxDomDepth;
- }
- if (serializationOptions.includeShadowTree !== undefined) {
- additionalParameters['includeShadowTree'] =
- serializationOptions.includeShadowTree;
- }
- return additionalParameters;
- }
- static #getMaxObjectDepth(serializationOptions) {
- return serializationOptions.maxObjectDepth === undefined ||
- serializationOptions.maxObjectDepth === null
- ? {}
- : { maxDepth: serializationOptions.maxObjectDepth };
- }
- async #releaseObject(handle) {
- try {
- await this.cdpClient.sendCommand('Runtime.releaseObject', {
- objectId: handle,
- });
- }
- catch (error) {
- // Heuristic to determine if the problem is in the unknown handler.
- // Ignore the error if so.
- if (!(error.code === -32000 /* CdpErrorConstants.GENERIC_ERROR */ &&
- error.message === 'Invalid remote object id')) {
- throw error;
- }
- }
- }
- async disown(handle) {
- // Disowning an object from different realm does nothing.
- if (this.#realmStorage.knownHandlesToRealmMap.get(handle) !== this.realmId) {
- return;
- }
- await this.#releaseObject(handle);
- this.#realmStorage.knownHandlesToRealmMap.delete(handle);
- }
- dispose() {
- this.#registerEvent({
- type: 'event',
- method: protocol_js_1$b.ChromiumBidi.Script.EventNames.RealmDestroyed,
- params: {
- realm: this.realmId,
- },
- });
- }
- }
- Realm$1.Realm = Realm;
- var SharedId = {};
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(SharedId, "__esModule", { value: true });
- SharedId.parseSharedId = SharedId.getSharedId = void 0;
- const SHARED_ID_DIVIDER = '_element_';
- function getSharedId(frameId, documentId, backendNodeId) {
- return `f.${frameId}.d.${documentId}.e.${backendNodeId}`;
- }
- SharedId.getSharedId = getSharedId;
- function parseLegacySharedId(sharedId) {
- const match = sharedId.match(new RegExp(`(.*)${SHARED_ID_DIVIDER}(.*)`));
- if (!match) {
- // SharedId is incorrectly formatted.
- return null;
- }
- const documentId = match[1];
- const elementId = match[2];
- if (documentId === undefined || elementId === undefined) {
- return null;
- }
- const backendNodeId = parseInt(elementId ?? '');
- if (isNaN(backendNodeId)) {
- return null;
- }
- return {
- documentId,
- backendNodeId,
- };
- }
- function parseSharedId(sharedId) {
- // TODO: remove legacy check once ChromeDriver provides sharedId in the new format.
- const legacyFormattedSharedId = parseLegacySharedId(sharedId);
- if (legacyFormattedSharedId !== null) {
- return { ...legacyFormattedSharedId, frameId: undefined };
- }
- const match = sharedId.match(/f\.(.*)\.d\.(.*)\.e\.([0-9]*)/);
- if (!match) {
- // SharedId is incorrectly formatted.
- return null;
- }
- const frameId = match[1];
- const documentId = match[2];
- const elementId = match[3];
- if (frameId === undefined ||
- documentId === undefined ||
- elementId === undefined) {
- return null;
- }
- const backendNodeId = parseInt(elementId ?? '');
- if (isNaN(backendNodeId)) {
- return null;
- }
- return {
- frameId,
- documentId,
- backendNodeId,
- };
- }
- SharedId.parseSharedId = parseSharedId;
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(WindowRealm$1, "__esModule", { value: true });
- WindowRealm$1.WindowRealm = void 0;
- const protocol_js_1$a = protocol;
- const Realm_js_1$1 = Realm$1;
- const SharedId_js_1 = SharedId;
- class WindowRealm extends Realm_js_1$1.Realm {
- #browsingContextId;
- #browsingContextStorage;
- sandbox;
- constructor(browsingContextId, browsingContextStorage, cdpClient, eventManager, executionContextId, logger, origin, realmId, realmStorage, sandbox) {
- super(cdpClient, eventManager, executionContextId, logger, origin, realmId, realmStorage);
- this.#browsingContextId = browsingContextId;
- this.#browsingContextStorage = browsingContextStorage;
- this.sandbox = sandbox;
- this.initialize();
- }
- #getBrowsingContextId(navigableId) {
- const maybeBrowsingContext = this.#browsingContextStorage
- .getAllContexts()
- .find((context) => context.navigableId === navigableId);
- return maybeBrowsingContext?.id ?? 'UNKNOWN';
- }
- get browsingContext() {
- return this.#browsingContextStorage.getContext(this.#browsingContextId);
- }
- get associatedBrowsingContexts() {
- return [this.browsingContext];
- }
- get realmType() {
- return 'window';
- }
- get realmInfo() {
- return {
- ...this.baseInfo,
- type: this.realmType,
- context: this.#browsingContextId,
- sandbox: this.sandbox,
- };
- }
- get source() {
- return {
- realm: this.realmId,
- context: this.browsingContext.id,
- };
- }
- serializeForBiDi(deepSerializedValue, internalIdMap) {
- const bidiValue = deepSerializedValue.value;
- if (deepSerializedValue.type === 'node' && bidiValue !== undefined) {
- if (Object.hasOwn(bidiValue, 'backendNodeId')) {
- let navigableId = this.browsingContext.navigableId ?? 'UNKNOWN';
- if (Object.hasOwn(bidiValue, 'loaderId')) {
- // `loaderId` should be always there after ~2024-03-05, when
- // https://crrev.com/c/5116240 reaches stable.
- // TODO: remove the check after the date.
- navigableId = bidiValue.loaderId;
- delete bidiValue['loaderId'];
- }
- deepSerializedValue.sharedId =
- (0, SharedId_js_1.getSharedId)(this.#getBrowsingContextId(navigableId), navigableId, bidiValue.backendNodeId);
- delete bidiValue['backendNodeId'];
- }
- if (Object.hasOwn(bidiValue, 'children')) {
- for (const i in bidiValue.children) {
- bidiValue.children[i] = this.serializeForBiDi(bidiValue.children[i], internalIdMap);
- }
- }
- if (Object.hasOwn(bidiValue, 'shadowRoot') &&
- bidiValue.shadowRoot !== null) {
- bidiValue.shadowRoot = this.serializeForBiDi(bidiValue.shadowRoot, internalIdMap);
- }
- // `namespaceURI` can be is either `null` or non-empty string.
- if (bidiValue.namespaceURI === '') {
- bidiValue.namespaceURI = null;
- }
- }
- return super.serializeForBiDi(deepSerializedValue, internalIdMap);
- }
- async deserializeForCdp(localValue) {
- if ('sharedId' in localValue && localValue.sharedId) {
- const parsedSharedId = (0, SharedId_js_1.parseSharedId)(localValue.sharedId);
- if (parsedSharedId === null) {
- throw new protocol_js_1$a.NoSuchNodeException(`SharedId "${localValue.sharedId}" was not found.`);
- }
- const { documentId, backendNodeId } = parsedSharedId;
- // TODO: add proper validation if the element is accessible from the current realm.
- if (this.browsingContext.navigableId !== documentId) {
- throw new protocol_js_1$a.NoSuchNodeException(`SharedId "${localValue.sharedId}" belongs to different document. Current document is ${this.browsingContext.navigableId}.`);
- }
- try {
- const { object } = await this.cdpClient.sendCommand('DOM.resolveNode', {
- backendNodeId,
- executionContextId: this.executionContextId,
- });
- // TODO(#375): Release `obj.object.objectId` after using.
- return { objectId: object.objectId };
- }
- catch (error) {
- // Heuristic to detect "no such node" exception. Based on the specific
- // CDP implementation.
- if (error.code === -32000 /* CdpErrorConstants.GENERIC_ERROR */ &&
- error.message === 'No node with given id found') {
- throw new protocol_js_1$a.NoSuchNodeException(`SharedId "${localValue.sharedId}" was not found.`);
- }
- throw new protocol_js_1$a.UnknownErrorException(error.message, error.stack);
- }
- }
- return await super.deserializeForCdp(localValue);
- }
- async evaluate(expression, awaitPromise, resultOwnership, serializationOptions, userActivation) {
- await this.#browsingContextStorage
- .getContext(this.#browsingContextId)
- .targetUnblockedOrThrow();
- return await super.evaluate(expression, awaitPromise, resultOwnership, serializationOptions, userActivation);
- }
- async callFunction(functionDeclaration, awaitPromise, thisLocalValue, argumentsLocalValues, resultOwnership, serializationOptions, userActivation) {
- await this.#browsingContextStorage
- .getContext(this.#browsingContextId)
- .targetUnblockedOrThrow();
- return await super.callFunction(functionDeclaration, awaitPromise, thisLocalValue, argumentsLocalValues, resultOwnership, serializationOptions, userActivation);
- }
- }
- WindowRealm$1.WindowRealm = WindowRealm;
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(BrowsingContextImpl$1, "__esModule", { value: true });
- BrowsingContextImpl$1.serializeOrigin = BrowsingContextImpl$1.BrowsingContextImpl = void 0;
- const protocol_js_1$9 = protocol;
- const assert_js_1$2 = assert$1;
- const Deferred_js_1$2 = Deferred$1;
- const log_js_1$8 = log$1;
- const unitConversions_js_1 = unitConversions;
- const WindowRealm_js_1$1 = WindowRealm$1;
- class BrowsingContextImpl {
- static LOGGER_PREFIX = `${log_js_1$8.LogType.debug}:browsingContext`;
- /** The ID of this browsing context. */
- #id;
- userContext;
- /**
- * The ID of the parent browsing context.
- * If null, this is a top-level context.
- */
- #parentId;
- /** Direct children browsing contexts. */
- #children = new Set();
- #browsingContextStorage;
- #lifecycle = {
- DOMContentLoaded: new Deferred_js_1$2.Deferred(),
- load: new Deferred_js_1$2.Deferred(),
- };
- #navigation = {
- withinDocument: new Deferred_js_1$2.Deferred(),
- };
- #url = 'about:blank';
- #eventManager;
- #realmStorage;
- #loaderId;
- #cdpTarget;
- #maybeDefaultRealm;
- #logger;
- // Keeps track of the previously set viewport.
- #previousViewport = { width: 0, height: 0 };
- constructor(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger) {
- this.#cdpTarget = cdpTarget;
- this.#id = id;
- this.#parentId = parentId;
- this.userContext = userContext;
- this.#eventManager = eventManager;
- this.#browsingContextStorage = browsingContextStorage;
- this.#realmStorage = realmStorage;
- this.#logger = logger;
- }
- static create(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger) {
- const context = new BrowsingContextImpl(id, parentId, userContext, cdpTarget, eventManager, browsingContextStorage, realmStorage, logger);
- context.#initListeners();
- browsingContextStorage.addContext(context);
- if (!context.isTopLevelContext()) {
- context.parent.addChild(context.id);
- }
- eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.ContextCreated,
- params: context.serializeToBidiValue(),
- }, context.id);
- return context;
- }
- static getTimestamp() {
- // `timestamp` from the event is MonotonicTime, not real time, so
- // the best Mapper can do is to set the timestamp to the epoch time
- // of the event arrived.
- // https://chromedevtools.github.io/devtools-protocol/tot/Network/#type-MonotonicTime
- return new Date().getTime();
- }
- /**
- * @see https://html.spec.whatwg.org/multipage/document-sequences.html#navigable
- */
- get navigableId() {
- return this.#loaderId;
- }
- dispose() {
- this.#deleteAllChildren();
- this.#realmStorage.deleteRealms({
- browsingContextId: this.id,
- });
- // Remove context from the parent.
- if (!this.isTopLevelContext()) {
- this.parent.#children.delete(this.id);
- }
- // Fail all ongoing navigations.
- this.#failLifecycleIfNotFinished();
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.ContextDestroyed,
- params: this.serializeToBidiValue(),
- }, this.id);
- this.#browsingContextStorage.deleteContextById(this.id);
- }
- /** Returns the ID of this context. */
- get id() {
- return this.#id;
- }
- /** Returns the parent context ID. */
- get parentId() {
- return this.#parentId;
- }
- /** Returns the parent context. */
- get parent() {
- if (this.parentId === null) {
- return null;
- }
- return this.#browsingContextStorage.getContext(this.parentId);
- }
- /** Returns all direct children contexts. */
- get directChildren() {
- return [...this.#children].map((id) => this.#browsingContextStorage.getContext(id));
- }
- /** Returns all children contexts, flattened. */
- get allChildren() {
- const children = this.directChildren;
- return children.concat(...children.map((child) => child.allChildren));
- }
- /**
- * Returns true if this is a top-level context.
- * This is the case whenever the parent context ID is null.
- */
- isTopLevelContext() {
- return this.#parentId === null;
- }
- get top() {
- // eslint-disable-next-line @typescript-eslint/no-this-alias
- let topContext = this;
- let parent = topContext.parent;
- while (parent) {
- topContext = parent;
- parent = topContext.parent;
- }
- return topContext;
- }
- addChild(childId) {
- this.#children.add(childId);
- }
- #deleteAllChildren() {
- this.directChildren.map((child) => child.dispose());
- }
- get #defaultRealm() {
- (0, assert_js_1$2.assert)(this.#maybeDefaultRealm, `No default realm for browsing context ${this.#id}`);
- return this.#maybeDefaultRealm;
- }
- get cdpTarget() {
- return this.#cdpTarget;
- }
- updateCdpTarget(cdpTarget) {
- this.#cdpTarget = cdpTarget;
- this.#initListeners();
- }
- get url() {
- return this.#url;
- }
- async lifecycleLoaded() {
- await this.#lifecycle.load;
- }
- async targetUnblockedOrThrow() {
- const result = await this.#cdpTarget.unblocked;
- if (result.kind === 'error') {
- throw result.error;
- }
- }
- async getOrCreateSandbox(sandbox) {
- if (sandbox === undefined || sandbox === '') {
- return this.#defaultRealm;
- }
- let maybeSandboxes = this.#realmStorage.findRealms({
- browsingContextId: this.id,
- sandbox,
- });
- if (maybeSandboxes.length === 0) {
- await this.#cdpTarget.cdpClient.sendCommand('Page.createIsolatedWorld', {
- frameId: this.id,
- worldName: sandbox,
- });
- // `Runtime.executionContextCreated` should be emitted by the time the
- // previous command is done.
- maybeSandboxes = this.#realmStorage.findRealms({
- browsingContextId: this.id,
- sandbox,
- });
- (0, assert_js_1$2.assert)(maybeSandboxes.length !== 0);
- }
- // It's possible for more than one sandbox to be created due to provisional
- // frames. In this case, it's always the first one (i.e. the oldest one)
- // that is more relevant since the user may have set that one up already
- // through evaluation.
- return maybeSandboxes[0];
- }
- serializeToBidiValue(maxDepth = 0, addParentField = true) {
- return {
- context: this.#id,
- url: this.url,
- userContext: this.userContext,
- children: maxDepth > 0
- ? this.directChildren.map((c) => c.serializeToBidiValue(maxDepth - 1, false))
- : null,
- ...(addParentField ? { parent: this.#parentId } : {}),
- };
- }
- onTargetInfoChanged(params) {
- this.#url = params.targetInfo.url;
- }
- #initListeners() {
- this.#cdpTarget.cdpClient.on('Page.frameNavigated', (params) => {
- if (this.id !== params.frame.id) {
- return;
- }
- this.#url = params.frame.url + (params.frame.urlFragment ?? '');
- // At the point the page is initialized, all the nested iframes from the
- // previous page are detached and realms are destroyed.
- // Remove children from context.
- this.#deleteAllChildren();
- });
- this.#cdpTarget.cdpClient.on('Page.navigatedWithinDocument', (params) => {
- if (this.id !== params.frameId) {
- return;
- }
- const timestamp = BrowsingContextImpl.getTimestamp();
- this.#url = params.url;
- this.#navigation.withinDocument.resolve(params);
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.FragmentNavigated,
- params: {
- context: this.id,
- navigation: null,
- timestamp,
- url: this.#url,
- },
- }, this.id);
- });
- this.#cdpTarget.cdpClient.on('Page.frameStartedLoading', (params) => {
- if (this.id !== params.frameId) {
- return;
- }
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.NavigationStarted,
- params: {
- context: this.id,
- navigation: null,
- timestamp: BrowsingContextImpl.getTimestamp(),
- url: '',
- },
- }, this.id);
- });
- this.#cdpTarget.cdpClient.on('Page.lifecycleEvent', (params) => {
- if (this.id !== params.frameId) {
- return;
- }
- if (params.name === 'init') {
- this.#documentChanged(params.loaderId);
- return;
- }
- if (params.name === 'commit') {
- this.#loaderId = params.loaderId;
- return;
- }
- // If mapper attached to the page late, it might miss init and
- // commit events. In that case, save the first loaderId for this
- // frameId.
- if (!this.#loaderId) {
- this.#loaderId = params.loaderId;
- }
- // Ignore event from not current navigation.
- if (params.loaderId !== this.#loaderId) {
- return;
- }
- const timestamp = BrowsingContextImpl.getTimestamp();
- switch (params.name) {
- case 'DOMContentLoaded':
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.DomContentLoaded,
- params: {
- context: this.id,
- navigation: this.#loaderId ?? null,
- timestamp,
- url: this.#url,
- },
- }, this.id);
- this.#lifecycle.DOMContentLoaded.resolve(params);
- break;
- case 'load':
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.Load,
- params: {
- context: this.id,
- navigation: this.#loaderId ?? null,
- timestamp,
- url: this.#url,
- },
- }, this.id);
- this.#lifecycle.load.resolve(params);
- break;
- }
- });
- this.#cdpTarget.cdpClient.on('Runtime.executionContextCreated', (params) => {
- const { auxData, name, uniqueId, id } = params.context;
- if (!auxData || auxData.frameId !== this.id) {
- return;
- }
- let origin;
- let sandbox;
- // Only these execution contexts are supported for now.
- switch (auxData.type) {
- case 'isolated':
- sandbox = name;
- // Sandbox should have the same origin as the context itself, but in CDP
- // it has an empty one.
- origin = this.#defaultRealm.origin;
- break;
- case 'default':
- origin = serializeOrigin(params.context.origin);
- break;
- default:
- return;
- }
- const realm = new WindowRealm_js_1$1.WindowRealm(this.id, this.#browsingContextStorage, this.#cdpTarget.cdpClient, this.#eventManager, id, this.#logger, origin, uniqueId, this.#realmStorage, sandbox);
- if (auxData.isDefault) {
- this.#maybeDefaultRealm = realm;
- // Initialize ChannelProxy listeners for all the channels of all the
- // preload scripts related to this BrowsingContext.
- // TODO: extend for not default realms by the sandbox name.
- void Promise.all(this.#cdpTarget
- .getChannels()
- .map((channel) => channel.startListenerFromWindow(realm, this.#eventManager)));
- }
- });
- this.#cdpTarget.cdpClient.on('Runtime.executionContextDestroyed', (params) => {
- this.#realmStorage.deleteRealms({
- cdpSessionId: this.#cdpTarget.cdpSessionId,
- executionContextId: params.executionContextId,
- });
- });
- this.#cdpTarget.cdpClient.on('Runtime.executionContextsCleared', () => {
- this.#realmStorage.deleteRealms({
- cdpSessionId: this.#cdpTarget.cdpSessionId,
- });
- });
- this.#cdpTarget.cdpClient.on('Page.javascriptDialogClosed', (params) => {
- const accepted = params.result;
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.UserPromptClosed,
- params: {
- context: this.id,
- accepted,
- userText: accepted && params.userInput ? params.userInput : undefined,
- },
- }, this.id);
- });
- this.#cdpTarget.cdpClient.on('Page.javascriptDialogOpening', (params) => {
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.UserPromptOpened,
- params: {
- context: this.id,
- type: params.type,
- message: params.message,
- // Don't set the value if empty string
- defaultValue: params.defaultPrompt || undefined,
- },
- }, this.id);
- });
- }
- #documentChanged(loaderId) {
- // Same document navigation.
- if (loaderId === undefined || this.#loaderId === loaderId) {
- if (this.#navigation.withinDocument.isFinished) {
- this.#navigation.withinDocument =
- new Deferred_js_1$2.Deferred();
- }
- else {
- this.#logger?.(BrowsingContextImpl.LOGGER_PREFIX, 'Document changed (navigatedWithinDocument)');
- }
- return;
- }
- this.#resetLifecycleIfFinished();
- this.#loaderId = loaderId;
- }
- #resetLifecycleIfFinished() {
- if (this.#lifecycle.DOMContentLoaded.isFinished) {
- this.#lifecycle.DOMContentLoaded =
- new Deferred_js_1$2.Deferred();
- }
- else {
- this.#logger?.(BrowsingContextImpl.LOGGER_PREFIX, 'Document changed (DOMContentLoaded)');
- }
- if (this.#lifecycle.load.isFinished) {
- this.#lifecycle.load = new Deferred_js_1$2.Deferred();
- }
- else {
- this.#logger?.(BrowsingContextImpl.LOGGER_PREFIX, 'Document changed (load)');
- }
- }
- #failLifecycleIfNotFinished() {
- if (!this.#lifecycle.DOMContentLoaded.isFinished) {
- this.#lifecycle.DOMContentLoaded.reject(new protocol_js_1$9.UnknownErrorException('navigation canceled'));
- }
- if (!this.#lifecycle.load.isFinished) {
- this.#lifecycle.load.reject(new protocol_js_1$9.UnknownErrorException('navigation canceled'));
- }
- }
- async navigate(url, wait) {
- try {
- new URL(url);
- }
- catch {
- throw new protocol_js_1$9.InvalidArgumentException(`Invalid URL: ${url}`);
- }
- await this.targetUnblockedOrThrow();
- // TODO: handle loading errors.
- const cdpNavigateResult = await this.#cdpTarget.cdpClient.sendCommand('Page.navigate', {
- url,
- frameId: this.id,
- });
- if (cdpNavigateResult.errorText) {
- this.#eventManager.registerEvent({
- type: 'event',
- method: protocol_js_1$9.ChromiumBidi.BrowsingContext.EventNames.NavigationFailed,
- params: {
- context: this.id,
- navigation: cdpNavigateResult.loaderId ?? null,
- timestamp: BrowsingContextImpl.getTimestamp(),
- url,
- },
- }, this.id);
- throw new protocol_js_1$9.UnknownErrorException(cdpNavigateResult.errorText);
- }
- this.#documentChanged(cdpNavigateResult.loaderId);
- switch (wait) {
- case "none" /* BrowsingContext.ReadinessState.None */:
- break;
- case "interactive" /* BrowsingContext.ReadinessState.Interactive */:
- // No `loaderId` means same-document navigation.
- if (cdpNavigateResult.loaderId === undefined) {
- await this.#navigation.withinDocument;
- }
- else {
- await this.#lifecycle.DOMContentLoaded;
- }
- break;
- case "complete" /* BrowsingContext.ReadinessState.Complete */:
- // No `loaderId` means same-document navigation.
- if (cdpNavigateResult.loaderId === undefined) {
- await this.#navigation.withinDocument;
- }
- else {
- await this.#lifecycle.load;
- }
- break;
- }
- return {
- navigation: cdpNavigateResult.loaderId ?? null,
- // Url can change due to redirect get the latest one.
- url: wait === "none" /* BrowsingContext.ReadinessState.None */ ? url : this.#url,
- };
- }
- async reload(ignoreCache, wait) {
- await this.targetUnblockedOrThrow();
- this.#resetLifecycleIfFinished();
- await this.#cdpTarget.cdpClient.sendCommand('Page.reload', {
- ignoreCache,
- });
- switch (wait) {
- case "none" /* BrowsingContext.ReadinessState.None */:
- break;
- case "interactive" /* BrowsingContext.ReadinessState.Interactive */:
- await this.#lifecycle.DOMContentLoaded;
- break;
- case "complete" /* BrowsingContext.ReadinessState.Complete */:
- await this.#lifecycle.load;
- break;
- }
- return {
- navigation: wait === "none" /* BrowsingContext.ReadinessState.None */
- ? null
- : this.navigableId ?? null,
- url: this.url,
- };
- }
- async setViewport(viewport, devicePixelRatio) {
- if (viewport === null && devicePixelRatio === null) {
- await this.#cdpTarget.cdpClient.sendCommand('Emulation.clearDeviceMetricsOverride');
- }
- else {
- try {
- let appliedViewport;
- if (viewport === undefined) {
- appliedViewport = this.#previousViewport;
- }
- else if (viewport === null) {
- appliedViewport = {
- width: 0,
- height: 0,
- };
- }
- else {
- appliedViewport = viewport;
- }
- this.#previousViewport = appliedViewport;
- await this.#cdpTarget.cdpClient.sendCommand('Emulation.setDeviceMetricsOverride', {
- width: this.#previousViewport.width,
- height: this.#previousViewport.height,
- deviceScaleFactor: devicePixelRatio ? devicePixelRatio : 0,
- mobile: false,
- dontSetVisibleSize: true,
- });
- }
- catch (err) {
- if (err.message.startsWith(
- // https://crsrc.org/c/content/browser/devtools/protocol/emulation_handler.cc;l=257;drc=2f6eee84cf98d4227e7c41718dd71b82f26d90ff
- 'Width and height values must be positive')) {
- throw new protocol_js_1$9.UnsupportedOperationException('Provided viewport dimensions are not supported');
- }
- throw err;
- }
- }
- }
- async handleUserPrompt(params) {
- await this.#cdpTarget.cdpClient.sendCommand('Page.handleJavaScriptDialog', {
- accept: params.accept ?? true,
- promptText: params.userText,
- });
- }
- async activate() {
- await this.#cdpTarget.cdpClient.sendCommand('Page.bringToFront');
- }
- async captureScreenshot(params) {
- if (!this.isTopLevelContext()) {
- throw new protocol_js_1$9.UnsupportedOperationException(`Non-top-level 'context' (${params.context}) is currently not supported`);
- }
- const formatParameters = getImageFormatParameters(params);
- // XXX: Focus the original tab after the screenshot is taken.
- // This is needed because the screenshot gets blocked until the active tab gets focus.
- await this.#cdpTarget.cdpClient.sendCommand('Page.bringToFront');
- let captureBeyondViewport = false;
- let script;
- params.origin ??= 'viewport';
- switch (params.origin) {
- case 'document': {
- script = String(() => {
- const element = document.documentElement;
- return {
- x: 0,
- y: 0,
- width: element.scrollWidth,
- height: element.scrollHeight,
- };
- });
- captureBeyondViewport = true;
- break;
- }
- case 'viewport': {
- script = String(() => {
- const viewport = window.visualViewport;
- return {
- x: viewport.pageLeft,
- y: viewport.pageTop,
- width: viewport.width,
- height: viewport.height,
- };
- });
- break;
- }
- }
- const realm = await this.getOrCreateSandbox(undefined);
- const originResult = await realm.callFunction(script, false);
- (0, assert_js_1$2.assert)(originResult.type === 'success');
- const origin = deserializeDOMRect(originResult.result);
- (0, assert_js_1$2.assert)(origin);
- const rect = params.clip
- ? getIntersectionRect(await this.#parseRect(params.clip), origin)
- : origin;
- if (rect.width === 0 || rect.height === 0) {
- throw new protocol_js_1$9.UnableToCaptureScreenException(`Unable to capture screenshot with zero dimensions: width=${rect.width}, height=${rect.height}`);
- }
- return await this.#cdpTarget.cdpClient.sendCommand('Page.captureScreenshot', {
- clip: { ...rect, scale: 1.0 },
- ...formatParameters,
- captureBeyondViewport,
- });
- }
- async print(params) {
- const cdpParams = {};
- if (params.background !== undefined) {
- cdpParams.printBackground = params.background;
- }
- if (params.margin?.bottom !== undefined) {
- cdpParams.marginBottom = (0, unitConversions_js_1.inchesFromCm)(params.margin.bottom);
- }
- if (params.margin?.left !== undefined) {
- cdpParams.marginLeft = (0, unitConversions_js_1.inchesFromCm)(params.margin.left);
- }
- if (params.margin?.right !== undefined) {
- cdpParams.marginRight = (0, unitConversions_js_1.inchesFromCm)(params.margin.right);
- }
- if (params.margin?.top !== undefined) {
- cdpParams.marginTop = (0, unitConversions_js_1.inchesFromCm)(params.margin.top);
- }
- if (params.orientation !== undefined) {
- cdpParams.landscape = params.orientation === 'landscape';
- }
- if (params.page?.height !== undefined) {
- cdpParams.paperHeight = (0, unitConversions_js_1.inchesFromCm)(params.page.height);
- }
- if (params.page?.width !== undefined) {
- cdpParams.paperWidth = (0, unitConversions_js_1.inchesFromCm)(params.page.width);
- }
- if (params.pageRanges !== undefined) {
- for (const range of params.pageRanges) {
- if (typeof range === 'number') {
- continue;
- }
- const rangeParts = range.split('-');
- if (rangeParts.length < 1 || rangeParts.length > 2) {
- throw new protocol_js_1$9.InvalidArgumentException(`Invalid page range: ${range} is not a valid integer range.`);
- }
- if (rangeParts.length === 1) {
- void parseInteger(rangeParts[0] ?? '');
- continue;
- }
- let lowerBound;
- let upperBound;
- const [rangeLowerPart = '', rangeUpperPart = ''] = rangeParts;
- if (rangeLowerPart === '') {
- lowerBound = 1;
- }
- else {
- lowerBound = parseInteger(rangeLowerPart);
- }
- if (rangeUpperPart === '') {
- upperBound = Number.MAX_SAFE_INTEGER;
- }
- else {
- upperBound = parseInteger(rangeUpperPart);
- }
- if (lowerBound > upperBound) {
- throw new protocol_js_1$9.InvalidArgumentException(`Invalid page range: ${rangeLowerPart} > ${rangeUpperPart}`);
- }
- }
- cdpParams.pageRanges = params.pageRanges.join(',');
- }
- if (params.scale !== undefined) {
- cdpParams.scale = params.scale;
- }
- if (params.shrinkToFit !== undefined) {
- cdpParams.preferCSSPageSize = !params.shrinkToFit;
- }
- try {
- const result = await this.#cdpTarget.cdpClient.sendCommand('Page.printToPDF', cdpParams);
- return {
- data: result.data,
- };
- }
- catch (error) {
- // Effectively zero dimensions.
- if (error.message ===
- 'invalid print parameters: content area is empty') {
- throw new protocol_js_1$9.UnsupportedOperationException(error.message);
- }
- throw error;
- }
- }
- /**
- * See
- * https://w3c.github.io/webdriver-bidi/#:~:text=If%20command%20parameters%20contains%20%22clip%22%3A
- */
- async #parseRect(clip) {
- switch (clip.type) {
- case 'box':
- return { x: clip.x, y: clip.y, width: clip.width, height: clip.height };
- case 'element': {
- // TODO: #1213: Use custom sandbox specifically for Chromium BiDi
- const sandbox = await this.getOrCreateSandbox(undefined);
- const result = await sandbox.callFunction(String((element) => {
- return element instanceof Element;
- }), false, { type: 'undefined' }, [clip.element]);
- if (result.type === 'exception') {
- throw new protocol_js_1$9.NoSuchElementException(`Element '${clip.element.sharedId}' was not found`);
- }
- (0, assert_js_1$2.assert)(result.result.type === 'boolean');
- if (!result.result.value) {
- throw new protocol_js_1$9.NoSuchElementException(`Node '${clip.element.sharedId}' is not an Element`);
- }
- {
- const result = await sandbox.callFunction(String((element) => {
- const rect = element.getBoundingClientRect();
- return {
- x: rect.x,
- y: rect.y,
- height: rect.height,
- width: rect.width,
- };
- }), false, { type: 'undefined' }, [clip.element]);
- (0, assert_js_1$2.assert)(result.type === 'success');
- const rect = deserializeDOMRect(result.result);
- if (!rect) {
- throw new protocol_js_1$9.UnableToCaptureScreenException(`Could not get bounding box for Element '${clip.element.sharedId}'`);
- }
- return rect;
- }
- }
- }
- }
- async close() {
- await this.#cdpTarget.cdpClient.sendCommand('Page.close');
- }
- async traverseHistory(delta) {
- if (delta === 0) {
- return;
- }
- const history = await this.#cdpTarget.cdpClient.sendCommand('Page.getNavigationHistory');
- const entry = history.entries[history.currentIndex + delta];
- if (!entry) {
- throw new protocol_js_1$9.NoSuchHistoryEntryException(`No history entry at delta ${delta}`);
- }
- await this.#cdpTarget.cdpClient.sendCommand('Page.navigateToHistoryEntry', {
- entryId: entry.id,
- });
- }
- async toggleModulesIfNeeded() {
- await this.#cdpTarget.toggleNetworkIfNeeded();
- }
- async locateNodes(params) {
- // TODO: create a dedicated sandbox instead of `#defaultRealm`.
- return await this.#locateNodesByLocator(this.#defaultRealm, params.locator, params.startNodes ?? [], params.maxNodeCount, params.serializationOptions);
- }
- #getLocatorDelegate(locator, maxNodeCount, startNodes) {
- switch (locator.type) {
- case 'css':
- return {
- functionDeclaration: String((cssSelector, maxNodeCount, ...startNodes) => {
- const locateNodesUsingCss = (element) => {
- if (!(element instanceof HTMLElement)) {
- throw new Error('startNodes in css selector should be HTMLElement');
- }
- return [...element.querySelectorAll(cssSelector)];
- };
- startNodes = startNodes.length > 0 ? startNodes : [document.body];
- const returnedNodes = startNodes
- .map((startNode) =>
- // TODO: stop search early if `maxNodeCount` is reached.
- locateNodesUsingCss(startNode))
- .flat(1);
- return maxNodeCount === 0
- ? returnedNodes
- : returnedNodes.slice(0, maxNodeCount);
- }),
- argumentsLocalValues: [
- // `cssSelector`
- { type: 'string', value: locator.value },
- // `maxNodeCount` with `0` means no limit.
- { type: 'number', value: maxNodeCount ?? 0 },
- // `startNodes`
- ...startNodes,
- ],
- };
- case 'xpath':
- return {
- functionDeclaration: String((xPathSelector, maxNodeCount, ...startNodes) => {
- // https://w3c.github.io/webdriver-bidi/#locate-nodes-using-xpath
- const evaluator = new XPathEvaluator();
- const expression = evaluator.createExpression(xPathSelector);
- const locateNodesUsingXpath = (element) => {
- const xPathResult = expression.evaluate(element, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE);
- const returnedNodes = [];
- for (let i = 0; i < xPathResult.snapshotLength; i++) {
- returnedNodes.push(xPathResult.snapshotItem(i));
- }
- return returnedNodes;
- };
- startNodes = startNodes.length > 0 ? startNodes : [document.body];
- const returnedNodes = startNodes
- .map((startNode) =>
- // TODO: stop search early if `maxNodeCount` is reached.
- locateNodesUsingXpath(startNode))
- .flat(1);
- return maxNodeCount === 0
- ? returnedNodes
- : returnedNodes.slice(0, maxNodeCount);
- }),
- argumentsLocalValues: [
- // `xPathSelector`
- { type: 'string', value: locator.value },
- // `maxNodeCount` with `0` means no limit.
- { type: 'number', value: maxNodeCount ?? 0 },
- // `startNodes`
- ...startNodes,
- ],
- };
- case 'innerText':
- // https://w3c.github.io/webdriver-bidi/#locate-nodes-using-inner-text
- if (locator.value === '') {
- throw new protocol_js_1$9.InvalidSelectorException('innerText locator cannot be empty');
- }
- return {
- functionDeclaration: String((innerTextSelector, fullMatch, ignoreCase, maxNodeCount, maxDepth, ...startNodes) => {
- const searchText = ignoreCase
- ? innerTextSelector.toUpperCase()
- : innerTextSelector;
- const locateNodesUsingInnerText = (element, currentMaxDepth) => {
- const returnedNodes = [];
- const nodeInnerText = ignoreCase
- ? element.innerText?.toUpperCase()
- : element.innerText;
- if (!nodeInnerText.includes(searchText)) {
- return [];
- }
- const childNodes = [];
- for (const child of element.children) {
- if (child instanceof HTMLElement) {
- childNodes.push(child);
- }
- }
- if (childNodes.length === 0) {
- if (fullMatch && nodeInnerText === searchText) {
- returnedNodes.push(element);
- }
- else {
- if (!fullMatch) {
- // Note: `nodeInnerText.includes(searchText)` is already checked
- returnedNodes.push(element);
- }
- }
- }
- else {
- const childNodeMatches =
- // Don't search deeper if `maxDepth` is reached.
- currentMaxDepth === 0
- ? []
- : childNodes
- .map((child) => locateNodesUsingInnerText(child, currentMaxDepth - 1))
- .flat(1);
- if (childNodeMatches.length === 0) {
- // Note: `nodeInnerText.includes(searchText)` is already checked
- if (!fullMatch || nodeInnerText === searchText) {
- returnedNodes.push(element);
- }
- }
- else {
- returnedNodes.push(...childNodeMatches);
- }
- }
- // TODO: stop search early if `maxNodeCount` is reached.
- return returnedNodes;
- };
- // TODO: add maxDepth.
- // TODO: stop search early if `maxNodeCount` is reached.
- startNodes = startNodes.length > 0 ? startNodes : [document.body];
- const returnedNodes = startNodes
- .map((startNode) =>
- // TODO: stop search early if `maxNodeCount` is reached.
- locateNodesUsingInnerText(startNode, maxDepth))
- .flat(1);
- return maxNodeCount === 0
- ? returnedNodes
- : returnedNodes.slice(0, maxNodeCount);
- }),
- argumentsLocalValues: [
- // `innerTextSelector`
- { type: 'string', value: locator.value },
- // `fullMatch` with default `true`.
- { type: 'boolean', value: locator.matchType !== 'partial' },
- // `ignoreCase` with default `false`.
- { type: 'boolean', value: locator.ignoreCase === true },
- // `maxNodeCount` with `0` means no limit.
- { type: 'number', value: maxNodeCount ?? 0 },
- // `maxDepth` with default `1000` (same as default full serialization depth).
- { type: 'number', value: locator.maxDepth ?? 1000 },
- // `startNodes`
- ...startNodes,
- ],
- };
- }
- }
- async #locateNodesByLocator(realm, locator, startNodes, maxNodeCount, serializationOptions) {
- const locatorDelegate = this.#getLocatorDelegate(locator, maxNodeCount, startNodes);
- serializationOptions = {
- ...serializationOptions,
- // The returned object is an array of nodes, so no need in deeper JS serialization.
- maxObjectDepth: 1,
- };
- const locatorResult = await realm.callFunction(locatorDelegate.functionDeclaration, false, { type: 'undefined' }, locatorDelegate.argumentsLocalValues, "none" /* Script.ResultOwnership.None */, serializationOptions);
- if (locatorResult.type !== 'success') {
- this.#logger?.(BrowsingContextImpl.LOGGER_PREFIX, 'Failed locateNodesByLocator', locatorResult);
- // Heuristic to detect invalid selector for different types of selectors.
- if (
- // CSS selector.
- locatorResult.exceptionDetails.text?.endsWith('is not a valid selector.') ||
- // XPath selector.
- locatorResult.exceptionDetails.text?.endsWith('is not a valid XPath expression.')) {
- throw new protocol_js_1$9.InvalidSelectorException(`Not valid selector ${locator.value}`);
- }
- // Heuristic to detect if the `startNode` is not an `HTMLElement` in css selector.
- if (locatorResult.exceptionDetails.text ===
- 'Error: startNodes in css selector should be HTMLElement') {
- throw new protocol_js_1$9.InvalidArgumentException(`startNodes in css selector should be HTMLElement`);
- }
- throw new protocol_js_1$9.UnknownErrorException(`Unexpected error in selector script: ${locatorResult.exceptionDetails.text}`);
- }
- if (locatorResult.result.type !== 'array') {
- throw new protocol_js_1$9.UnknownErrorException(`Unexpected selector script result type: ${locatorResult.result.type}`);
- }
- // Check there are no non-node elements in the result.
- const nodes = locatorResult.result.value.map((value) => {
- if (value.type !== 'node') {
- throw new protocol_js_1$9.UnknownErrorException(`Unexpected selector script result element: ${value.type}`);
- }
- return value;
- });
- return { nodes };
- }
- }
- BrowsingContextImpl$1.BrowsingContextImpl = BrowsingContextImpl;
- function serializeOrigin(origin) {
- // https://html.spec.whatwg.org/multipage/origin.html#ascii-serialisation-of-an-origin
- if (['://', ''].includes(origin)) {
- origin = 'null';
- }
- return origin;
- }
- BrowsingContextImpl$1.serializeOrigin = serializeOrigin;
- function getImageFormatParameters(params) {
- const { quality, type } = params.format ?? {
- type: 'image/png',
- };
- switch (type) {
- case 'image/png': {
- return { format: 'png' };
- }
- case 'image/jpeg': {
- return {
- format: 'jpeg',
- ...(quality === undefined ? {} : { quality: Math.round(quality * 100) }),
- };
- }
- case 'image/webp': {
- return {
- format: 'webp',
- ...(quality === undefined ? {} : { quality: Math.round(quality * 100) }),
- };
- }
- }
- throw new protocol_js_1$9.InvalidArgumentException(`Image format '${type}' is not a supported format`);
- }
- function deserializeDOMRect(result) {
- if (result.type !== 'object' || result.value === undefined) {
- return;
- }
- const x = result.value.find(([key]) => {
- return key === 'x';
- })?.[1];
- const y = result.value.find(([key]) => {
- return key === 'y';
- })?.[1];
- const height = result.value.find(([key]) => {
- return key === 'height';
- })?.[1];
- const width = result.value.find(([key]) => {
- return key === 'width';
- })?.[1];
- if (x?.type !== 'number' ||
- y?.type !== 'number' ||
- height?.type !== 'number' ||
- width?.type !== 'number') {
- return;
- }
- return {
- x: x.value,
- y: y.value,
- width: width.value,
- height: height.value,
- };
- }
- /** @see https://w3c.github.io/webdriver-bidi/#normalize-rect */
- function normalizeRect(box) {
- return {
- ...(box.width < 0
- ? {
- x: box.x + box.width,
- width: -box.width,
- }
- : {
- x: box.x,
- width: box.width,
- }),
- ...(box.height < 0
- ? {
- y: box.y + box.height,
- height: -box.height,
- }
- : {
- y: box.y,
- height: box.height,
- }),
- };
- }
- /** @see https://w3c.github.io/webdriver-bidi/#rectangle-intersection */
- function getIntersectionRect(first, second) {
- first = normalizeRect(first);
- second = normalizeRect(second);
- const x = Math.max(first.x, second.x);
- const y = Math.max(first.y, second.y);
- return {
- x,
- y,
- width: Math.max(Math.min(first.x + first.width, second.x + second.width) - x, 0),
- height: Math.max(Math.min(first.y + first.height, second.y + second.height) - y, 0),
- };
- }
- function parseInteger(value) {
- value = value.trim();
- if (!/^[0-9]+$/.test(value)) {
- throw new protocol_js_1$9.InvalidArgumentException(`Invalid integer: ${value}`);
- }
- return parseInt(value);
- }
- var WorkerRealm$1 = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(WorkerRealm$1, "__esModule", { value: true });
- WorkerRealm$1.WorkerRealm = void 0;
- const Realm_js_1 = Realm$1;
- class WorkerRealm extends Realm_js_1.Realm {
- #realmType;
- #ownerRealms;
- constructor(cdpClient, eventManager, executionContextId, logger, origin, ownerRealms, realmId, realmStorage, realmType) {
- super(cdpClient, eventManager, executionContextId, logger, origin, realmId, realmStorage);
- this.#ownerRealms = ownerRealms;
- this.#realmType = realmType;
- this.initialize();
- }
- get associatedBrowsingContexts() {
- return this.#ownerRealms.flatMap((realm) => realm.associatedBrowsingContexts);
- }
- get realmType() {
- return this.#realmType;
- }
- get source() {
- return {
- realm: this.realmId,
- // This is a hack to make Puppeteer able to track workers.
- // TODO: remove after Puppeteer tracks workers by owners and use the base version.
- context: this.associatedBrowsingContexts[0]?.id,
- };
- }
- get realmInfo() {
- const owners = this.#ownerRealms.map((realm) => realm.realmId);
- const { realmType } = this;
- switch (realmType) {
- case 'dedicated-worker': {
- const owner = owners[0];
- if (owner === undefined || owners.length !== 1) {
- throw new Error('Dedicated worker must have exactly one owner');
- }
- return {
- ...this.baseInfo,
- type: realmType,
- owners: [owner],
- };
- }
- case 'service-worker':
- case 'shared-worker': {
- return {
- ...this.baseInfo,
- type: realmType,
- };
- }
- }
- }
- }
- WorkerRealm$1.WorkerRealm = WorkerRealm;
- var CdpTarget$1 = {};
- var LogManager$1 = {};
- var logHelper = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(logHelper, "__esModule", { value: true });
- logHelper.getRemoteValuesText = logHelper.logMessageFormatter = void 0;
- const assert_js_1$1 = assert$1;
- const specifiers = ['%s', '%d', '%i', '%f', '%o', '%O', '%c'];
- function isFormatSpecifier(str) {
- return specifiers.some((spec) => str.includes(spec));
- }
- /**
- * @param args input remote values to be format printed
- * @return parsed text of the remote values in specific format
- */
- function logMessageFormatter(args) {
- let output = '';
- const argFormat = args[0].value.toString();
- const argValues = args.slice(1, undefined);
- const tokens = argFormat.split(new RegExp(specifiers.map((spec) => `(${spec})`).join('|'), 'g'));
- for (const token of tokens) {
- if (token === undefined || token === '') {
- continue;
- }
- if (isFormatSpecifier(token)) {
- const arg = argValues.shift();
- // raise an exception when less value is provided
- (0, assert_js_1$1.assert)(arg, `Less value is provided: "${getRemoteValuesText(args, false)}"`);
- if (token === '%s') {
- output += stringFromArg(arg);
- }
- else if (token === '%d' || token === '%i') {
- if (arg.type === 'bigint' ||
- arg.type === 'number' ||
- arg.type === 'string') {
- output += parseInt(arg.value.toString(), 10);
- }
- else {
- output += 'NaN';
- }
- }
- else if (token === '%f') {
- if (arg.type === 'bigint' ||
- arg.type === 'number' ||
- arg.type === 'string') {
- output += parseFloat(arg.value.toString());
- }
- else {
- output += 'NaN';
- }
- }
- else {
- // %o, %O, %c
- output += toJson(arg);
- }
- }
- else {
- output += token;
- }
- }
- // raise an exception when more value is provided
- if (argValues.length > 0) {
- throw new Error(`More value is provided: "${getRemoteValuesText(args, false)}"`);
- }
- return output;
- }
- logHelper.logMessageFormatter = logMessageFormatter;
- /**
- * @param arg input remote value to be parsed
- * @return parsed text of the remote value
- *
- * input: {"type": "number", "value": 1}
- * output: 1
- *
- * input: {"type": "string", "value": "abc"}
- * output: "abc"
- *
- * input: {"type": "object", "value": [["id", {"type": "number", "value": 1}]]}
- * output: '{"id": 1}'
- *
- * input: {"type": "object", "value": [["font-size", {"type": "string", "value": "20px"}]]}
- * output: '{"font-size": "20px"}'
- */
- function toJson(arg) {
- // arg type validation
- if (arg.type !== 'array' &&
- arg.type !== 'bigint' &&
- arg.type !== 'date' &&
- arg.type !== 'number' &&
- arg.type !== 'object' &&
- arg.type !== 'string') {
- return stringFromArg(arg);
- }
- if (arg.type === 'bigint') {
- return `${arg.value.toString()}n`;
- }
- if (arg.type === 'number') {
- return arg.value.toString();
- }
- if (['date', 'string'].includes(arg.type)) {
- return JSON.stringify(arg.value);
- }
- if (arg.type === 'object') {
- return `{${arg.value
- .map((pair) => {
- return `${JSON.stringify(pair[0])}:${toJson(pair[1])}`;
- })
- .join(',')}}`;
- }
- if (arg.type === 'array') {
- return `[${arg.value?.map((val) => toJson(val)).join(',') ?? ''}]`;
- }
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- throw Error(`Invalid value type: ${arg}`);
- }
- function stringFromArg(arg) {
- if (!Object.hasOwn(arg, 'value')) {
- return arg.type;
- }
- switch (arg.type) {
- case 'string':
- case 'number':
- case 'boolean':
- case 'bigint':
- return String(arg.value);
- case 'regexp':
- return `/${arg.value.pattern}/${arg.value.flags ?? ''}`;
- case 'date':
- return new Date(arg.value).toString();
- case 'object':
- return `Object(${arg.value?.length ?? ''})`;
- case 'array':
- return `Array(${arg.value?.length ?? ''})`;
- case 'map':
- return `Map(${arg.value?.length})`;
- case 'set':
- return `Set(${arg.value?.length})`;
- default:
- return arg.type;
- }
- }
- function getRemoteValuesText(args, formatText) {
- const arg = args[0];
- if (!arg) {
- return '';
- }
- // if args[0] is a format specifier, format the args as output
- if (arg.type === 'string' &&
- isFormatSpecifier(arg.value.toString()) &&
- formatText) {
- return logMessageFormatter(args);
- }
- // if args[0] is not a format specifier, just join the args with \u0020 (unicode 'SPACE')
- return args
- .map((arg) => {
- return stringFromArg(arg);
- })
- .join('\u0020');
- }
- logHelper.getRemoteValuesText = getRemoteValuesText;
- Object.defineProperty(LogManager$1, "__esModule", { value: true });
- LogManager$1.LogManager = void 0;
- const protocol_js_1$8 = protocol;
- const log_js_1$7 = log$1;
- const logHelper_js_1 = logHelper;
- /** Converts CDP StackTrace object to BiDi StackTrace object. */
- function getBidiStackTrace(cdpStackTrace) {
- const stackFrames = cdpStackTrace?.callFrames.map((callFrame) => {
- return {
- columnNumber: callFrame.columnNumber,
- functionName: callFrame.functionName,
- lineNumber: callFrame.lineNumber,
- url: callFrame.url,
- };
- });
- return stackFrames ? { callFrames: stackFrames } : undefined;
- }
- function getLogLevel(consoleApiType) {
- if (["error" /* Log.Level.Error */, 'assert'].includes(consoleApiType)) {
- return "error" /* Log.Level.Error */;
- }
- if (["debug" /* Log.Level.Debug */, 'trace'].includes(consoleApiType)) {
- return "debug" /* Log.Level.Debug */;
- }
- if (["warn" /* Log.Level.Warn */, 'warning'].includes(consoleApiType)) {
- return "warn" /* Log.Level.Warn */;
- }
- return "info" /* Log.Level.Info */;
- }
- class LogManager {
- #eventManager;
- #realmStorage;
- #cdpTarget;
- #logger;
- constructor(cdpTarget, realmStorage, eventManager, logger) {
- this.#cdpTarget = cdpTarget;
- this.#realmStorage = realmStorage;
- this.#eventManager = eventManager;
- this.#logger = logger;
- }
- static create(cdpTarget, realmStorage, eventManager, logger) {
- const logManager = new LogManager(cdpTarget, realmStorage, eventManager, logger);
- logManager.#initializeEntryAddedEventListener();
- return logManager;
- }
- #initializeEntryAddedEventListener() {
- this.#cdpTarget.cdpClient.on('Runtime.consoleAPICalled', (params) => {
- // Try to find realm by `cdpSessionId` and `executionContextId`,
- // if provided.
- const realm = this.#realmStorage.findRealm({
- cdpSessionId: this.#cdpTarget.cdpSessionId,
- executionContextId: params.executionContextId,
- });
- if (realm === undefined) {
- // Ignore exceptions not attached to any realm.
- this.#logger?.(log_js_1$7.LogType.cdp, params);
- return;
- }
- const argsPromise = realm === undefined
- ? Promise.resolve(params.args)
- : // Properly serialize arguments if possible.
- Promise.all(params.args.map((arg) => {
- return realm.serializeCdpObject(arg, "none" /* Script.ResultOwnership.None */);
- }));
- for (const browsingContext of realm.associatedBrowsingContexts) {
- this.#eventManager.registerPromiseEvent(argsPromise.then((args) => ({
- kind: 'success',
- value: {
- type: 'event',
- method: protocol_js_1$8.ChromiumBidi.Log.EventNames.LogEntryAdded,
- params: {
- level: getLogLevel(params.type),
- source: realm.source,
- text: (0, logHelper_js_1.getRemoteValuesText)(args, true),
- timestamp: Math.round(params.timestamp),
- stackTrace: getBidiStackTrace(params.stackTrace),
- type: 'console',
- // Console method is `warn`, not `warning`.
- method: params.type === 'warning' ? 'warn' : params.type,
- args,
- },
- },
- })), browsingContext.id, protocol_js_1$8.ChromiumBidi.Log.EventNames.LogEntryAdded);
- }
- });
- this.#cdpTarget.cdpClient.on('Runtime.exceptionThrown', (params) => {
- // Try to find realm by `cdpSessionId` and `executionContextId`,
- // if provided.
- const realm = this.#realmStorage.findRealm({
- cdpSessionId: this.#cdpTarget.cdpSessionId,
- executionContextId: params.exceptionDetails.executionContextId,
- });
- if (realm === undefined) {
- // Ignore exceptions not attached to any realm.
- this.#logger?.(log_js_1$7.LogType.cdp, params);
- return;
- }
- for (const browsingContext of realm.associatedBrowsingContexts) {
- this.#eventManager.registerPromiseEvent(LogManager.#getExceptionText(params, realm).then((text) => ({
- kind: 'success',
- value: {
- type: 'event',
- method: protocol_js_1$8.ChromiumBidi.Log.EventNames.LogEntryAdded,
- params: {
- level: "error" /* Log.Level.Error */,
- source: realm.source,
- text,
- timestamp: Math.round(params.timestamp),
- stackTrace: getBidiStackTrace(params.exceptionDetails.stackTrace),
- type: 'javascript',
- },
- },
- })), browsingContext.id, protocol_js_1$8.ChromiumBidi.Log.EventNames.LogEntryAdded);
- }
- });
- }
- /**
- * Try the best to get the exception text.
- */
- static async #getExceptionText(params, realm) {
- if (!params.exceptionDetails.exception) {
- return params.exceptionDetails.text;
- }
- if (realm === undefined) {
- return JSON.stringify(params.exceptionDetails.exception);
- }
- return await realm.stringifyObject(params.exceptionDetails.exception);
- }
- }
- LogManager$1.LogManager = LogManager;
- Object.defineProperty(CdpTarget$1, "__esModule", { value: true });
- CdpTarget$1.CdpTarget = void 0;
- const chromium_bidi_js_1 = chromiumBidi;
- const Deferred_js_1$1 = Deferred$1;
- const LogManager_js_1 = LogManager$1;
- class CdpTarget {
- #id;
- #cdpClient;
- #browserCdpClient;
- #eventManager;
- #preloadScriptStorage;
- #browsingContextStorage;
- #networkStorage;
- #unblocked = new Deferred_js_1$1.Deferred();
- #acceptInsecureCerts;
- #networkDomainEnabled = false;
- #fetchDomainStages = {
- request: false,
- response: false,
- auth: false,
- };
- static create(targetId, cdpClient, browserCdpClient, realmStorage, eventManager, preloadScriptStorage, browsingContextStorage, networkStorage, acceptInsecureCerts, logger) {
- const cdpTarget = new CdpTarget(targetId, cdpClient, browserCdpClient, eventManager, preloadScriptStorage, browsingContextStorage, networkStorage, acceptInsecureCerts);
- LogManager_js_1.LogManager.create(cdpTarget, realmStorage, eventManager, logger);
- cdpTarget.#setEventListeners();
- // No need to await.
- // Deferred will be resolved when the target is unblocked.
- void cdpTarget.#unblock();
- return cdpTarget;
- }
- constructor(targetId, cdpClient, browserCdpClient, eventManager, preloadScriptStorage, browsingContextStorage, networkStorage, acceptInsecureCerts) {
- this.#id = targetId;
- this.#cdpClient = cdpClient;
- this.#browserCdpClient = browserCdpClient;
- this.#eventManager = eventManager;
- this.#preloadScriptStorage = preloadScriptStorage;
- this.#networkStorage = networkStorage;
- this.#browsingContextStorage = browsingContextStorage;
- this.#acceptInsecureCerts = acceptInsecureCerts;
- }
- /** Returns a deferred that resolves when the target is unblocked. */
- get unblocked() {
- return this.#unblocked;
- }
- get id() {
- return this.#id;
- }
- get cdpClient() {
- return this.#cdpClient;
- }
- get browserCdpClient() {
- return this.#browserCdpClient;
- }
- /** Needed for CDP escape path. */
- get cdpSessionId() {
- // SAFETY we got the client by it's id for creating
- return this.#cdpClient.sessionId;
- }
- /**
- * Enables all the required CDP domains and unblocks the target.
- */
- async #unblock() {
- try {
- await Promise.all([
- this.#cdpClient.sendCommand('Runtime.enable'),
- this.#cdpClient.sendCommand('Page.enable'),
- this.#cdpClient.sendCommand('Page.setLifecycleEventsEnabled', {
- enabled: true,
- }),
- // Set ignore certificate errors for each target.
- this.#cdpClient.sendCommand('Security.setIgnoreCertificateErrors', {
- ignore: this.#acceptInsecureCerts,
- }),
- this.toggleNetworkIfNeeded(),
- this.#cdpClient.sendCommand('Target.setAutoAttach', {
- autoAttach: true,
- waitForDebuggerOnStart: true,
- flatten: true,
- }),
- this.#initAndEvaluatePreloadScripts(),
- this.#cdpClient.sendCommand('Runtime.runIfWaitingForDebugger'),
- ]);
- }
- catch (error) {
- // The target might have been closed before the initialization finished.
- if (!this.#cdpClient.isCloseError(error)) {
- this.#unblocked.resolve({
- kind: 'error',
- error,
- });
- return;
- }
- }
- this.#unblocked.resolve({
- kind: 'success',
- value: undefined,
- });
- }
- async toggleFetchIfNeeded() {
- const stages = this.#networkStorage.getInterceptionStages(this.topLevelId);
- if (
- // Only toggle interception when Network is enabled
- !this.#networkDomainEnabled ||
- (this.#fetchDomainStages.request === stages.request &&
- this.#fetchDomainStages.response === stages.response &&
- this.#fetchDomainStages.auth === stages.auth)) {
- return;
- }
- const patterns = [];
- this.#fetchDomainStages = stages;
- if (stages.request || stages.auth) {
- // CDP quirk we need request interception when we intercept auth
- patterns.push({
- urlPattern: '*',
- requestStage: 'Request',
- });
- }
- if (stages.response) {
- patterns.push({
- urlPattern: '*',
- requestStage: 'Response',
- });
- }
- if (patterns.length) {
- await this.#cdpClient.sendCommand('Fetch.enable', {
- patterns,
- handleAuthRequests: stages.auth,
- });
- }
- else {
- await this.#cdpClient.sendCommand('Fetch.disable');
- }
- }
- /**
- * Toggles both Network and Fetch domains.
- */
- async toggleNetworkIfNeeded() {
- const enabled = this.isSubscribedTo(chromium_bidi_js_1.BiDiModule.Network);
- if (enabled === this.#networkDomainEnabled) {
- return;
- }
- this.#networkDomainEnabled = enabled;
- try {
- await Promise.all([
- this.#cdpClient.sendCommand(enabled ? 'Network.enable' : 'Network.disable'),
- this.toggleFetchIfNeeded(),
- ]);
- }
- catch (err) {
- this.#networkDomainEnabled = !enabled;
- }
- }
- #setEventListeners() {
- this.#cdpClient.on('*', (event, params) => {
- // We may encounter uses for EventEmitter other than CDP events,
- // which we want to skip.
- if (typeof event !== 'string') {
- return;
- }
- this.#eventManager.registerEvent({
- type: 'event',
- method: `cdp.${event}`,
- params: {
- event,
- params,
- session: this.cdpSessionId,
- },
- }, this.id);
- });
- }
- /**
- * All the ProxyChannels from all the preload scripts of the given
- * BrowsingContext.
- */
- getChannels() {
- return this.#preloadScriptStorage
- .find()
- .flatMap((script) => script.channels);
- }
- /** Loads all top-level preload scripts. */
- async #initAndEvaluatePreloadScripts() {
- await Promise.all(this.#preloadScriptStorage
- .find({
- // Needed for OOPIF
- targetId: this.topLevelId,
- global: true,
- })
- .map((script) => {
- return script.initInTarget(this, true);
- }));
- }
- get topLevelId() {
- return (this.#browsingContextStorage.findTopLevelContextId(this.id) ?? this.id);
- }
- isSubscribedTo(moduleOrEvent) {
- return this.#eventManager.subscriptionManager.isSubscribedTo(moduleOrEvent, this.topLevelId);
- }
- }
- CdpTarget$1.CdpTarget = CdpTarget;
- Object.defineProperty(CdpTargetManager$1, "__esModule", { value: true });
- CdpTargetManager$1.CdpTargetManager = void 0;
- const log_js_1$6 = log$1;
- const BrowsingContextImpl_js_1 = BrowsingContextImpl$1;
- const WorkerRealm_js_1 = WorkerRealm$1;
- const CdpTarget_js_1 = CdpTarget$1;
- const cdpToBidiTargetTypes = {
- service_worker: 'service-worker',
- shared_worker: 'shared-worker',
- worker: 'dedicated-worker',
- };
- class CdpTargetManager {
- #browserCdpClient;
- #cdpConnection;
- #selfTargetId;
- #eventManager;
- #browsingContextStorage;
- #networkStorage;
- #acceptInsecureCerts;
- #preloadScriptStorage;
- #realmStorage;
- #defaultUserContextId;
- #logger;
- constructor(cdpConnection, browserCdpClient, selfTargetId, eventManager, browsingContextStorage, realmStorage, networkStorage, preloadScriptStorage, acceptInsecureCerts, defaultUserContextId, logger) {
- this.#acceptInsecureCerts = acceptInsecureCerts;
- this.#cdpConnection = cdpConnection;
- this.#browserCdpClient = browserCdpClient;
- this.#selfTargetId = selfTargetId;
- this.#eventManager = eventManager;
- this.#browsingContextStorage = browsingContextStorage;
- this.#preloadScriptStorage = preloadScriptStorage;
- this.#networkStorage = networkStorage;
- this.#realmStorage = realmStorage;
- this.#defaultUserContextId = defaultUserContextId;
- this.#logger = logger;
- this.#setEventListeners(browserCdpClient);
- }
- /**
- * This method is called for each CDP session, since this class is responsible
- * for creating and destroying all targets and browsing contexts.
- */
- #setEventListeners(cdpClient) {
- cdpClient.on('Target.attachedToTarget', (params) => {
- this.#handleAttachedToTargetEvent(params, cdpClient);
- });
- cdpClient.on('Target.detachedFromTarget', this.#handleDetachedFromTargetEvent.bind(this));
- cdpClient.on('Target.targetInfoChanged', this.#handleTargetInfoChangedEvent.bind(this));
- cdpClient.on('Inspector.targetCrashed', () => {
- this.#handleTargetCrashedEvent(cdpClient);
- });
- cdpClient.on('Page.frameAttached', this.#handleFrameAttachedEvent.bind(this));
- cdpClient.on('Page.frameDetached', this.#handleFrameDetachedEvent.bind(this));
- }
- #handleFrameAttachedEvent(params) {
- const parentBrowsingContext = this.#browsingContextStorage.findContext(params.parentFrameId);
- if (parentBrowsingContext !== undefined) {
- BrowsingContextImpl_js_1.BrowsingContextImpl.create(params.frameId, params.parentFrameId, parentBrowsingContext.userContext, parentBrowsingContext.cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, this.#logger);
- }
- }
- #handleFrameDetachedEvent(params) {
- // In case of OOPiF no need in deleting BrowsingContext.
- if (params.reason === 'swap') {
- return;
- }
- this.#browsingContextStorage.findContext(params.frameId)?.dispose();
- }
- #handleAttachedToTargetEvent(params, parentSessionCdpClient) {
- const { sessionId, targetInfo } = params;
- const targetCdpClient = this.#cdpConnection.getCdpClient(sessionId);
- switch (targetInfo.type) {
- case 'page':
- case 'iframe': {
- if (targetInfo.targetId === this.#selfTargetId) {
- break;
- }
- const cdpTarget = this.#createCdpTarget(targetCdpClient, targetInfo);
- const maybeContext = this.#browsingContextStorage.findContext(targetInfo.targetId);
- if (maybeContext) {
- // OOPiF.
- maybeContext.updateCdpTarget(cdpTarget);
- }
- else {
- const userContext = targetInfo.browserContextId &&
- targetInfo.browserContextId !== this.#defaultUserContextId
- ? targetInfo.browserContextId
- : 'default';
- // New context.
- BrowsingContextImpl_js_1.BrowsingContextImpl.create(targetInfo.targetId, null, userContext, cdpTarget, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, this.#logger);
- }
- return;
- }
- case 'service_worker':
- case 'worker': {
- const realm = this.#realmStorage.findRealm({
- cdpSessionId: parentSessionCdpClient.sessionId,
- });
- // If there is no browsing context, this worker is already terminated.
- if (!realm) {
- break;
- }
- const cdpTarget = this.#createCdpTarget(targetCdpClient, targetInfo);
- this.#handleWorkerTarget(cdpToBidiTargetTypes[targetInfo.type], cdpTarget, realm);
- return;
- }
- // In CDP, we only emit shared workers on the browser and not the set of
- // frames that use the shared worker. If we change this in the future to
- // behave like service workers (emits on both browser and frame targets),
- // we can remove this block and merge service workers with the above one.
- case 'shared_worker': {
- const cdpTarget = this.#createCdpTarget(targetCdpClient, targetInfo);
- this.#handleWorkerTarget(cdpToBidiTargetTypes[targetInfo.type], cdpTarget);
- return;
- }
- }
- // DevTools or some other not supported by BiDi target. Just release
- // debugger and ignore them.
- targetCdpClient
- .sendCommand('Runtime.runIfWaitingForDebugger')
- .then(() => parentSessionCdpClient.sendCommand('Target.detachFromTarget', params))
- .catch((error) => this.#logger?.(log_js_1$6.LogType.debugError, error));
- }
- #createCdpTarget(targetCdpClient, targetInfo) {
- this.#setEventListeners(targetCdpClient);
- const target = CdpTarget_js_1.CdpTarget.create(targetInfo.targetId, targetCdpClient, this.#browserCdpClient, this.#realmStorage, this.#eventManager, this.#preloadScriptStorage, this.#browsingContextStorage, this.#networkStorage, this.#acceptInsecureCerts, this.#logger);
- this.#networkStorage.onCdpTargetCreated(target);
- return target;
- }
- #workers = new Map();
- #handleWorkerTarget(realmType, cdpTarget, ownerRealm) {
- cdpTarget.cdpClient.on('Runtime.executionContextCreated', (params) => {
- const { uniqueId, id, origin } = params.context;
- const workerRealm = new WorkerRealm_js_1.WorkerRealm(cdpTarget.cdpClient, this.#eventManager, id, this.#logger, (0, BrowsingContextImpl_js_1.serializeOrigin)(origin), ownerRealm ? [ownerRealm] : [], uniqueId, this.#realmStorage, realmType);
- this.#workers.set(cdpTarget.cdpSessionId, workerRealm);
- });
- }
- #handleDetachedFromTargetEvent({ sessionId, targetId, }) {
- if (targetId) {
- this.#preloadScriptStorage.find({ targetId }).map((preloadScript) => {
- preloadScript.dispose(targetId);
- });
- }
- const context = this.#browsingContextStorage.findContextBySession(sessionId);
- if (context) {
- context.dispose();
- return;
- }
- const worker = this.#workers.get(sessionId);
- if (worker) {
- this.#realmStorage.deleteRealms({
- cdpSessionId: worker.cdpClient.sessionId,
- });
- }
- }
- #handleTargetInfoChangedEvent(params) {
- const context = this.#browsingContextStorage.findContext(params.targetInfo.targetId);
- if (context) {
- context.onTargetInfoChanged(params);
- }
- }
- #handleTargetCrashedEvent(cdpClient) {
- // This is primarily used for service and shared workers. CDP tends to not
- // signal they closed gracefully and instead says they crashed to signal
- // they are closed.
- const realms = this.#realmStorage.findRealms({
- cdpSessionId: cdpClient.sessionId,
- });
- for (const realm of realms) {
- realm.dispose();
- }
- }
- }
- CdpTargetManager$1.CdpTargetManager = CdpTargetManager;
- var BrowsingContextStorage$1 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(BrowsingContextStorage$1, "__esModule", { value: true });
- BrowsingContextStorage$1.BrowsingContextStorage = void 0;
- const protocol_js_1$7 = protocol;
- /** Container class for browsing contexts. */
- class BrowsingContextStorage {
- /** Map from context ID to context implementation. */
- #contexts = new Map();
- /** Gets all top-level contexts, i.e. those with no parent. */
- getTopLevelContexts() {
- return this.getAllContexts().filter((context) => context.isTopLevelContext());
- }
- /** Gets all contexts. */
- getAllContexts() {
- return Array.from(this.#contexts.values());
- }
- /** Deletes the context with the given ID. */
- deleteContextById(id) {
- this.#contexts.delete(id);
- }
- /** Deletes the given context. */
- deleteContext(context) {
- this.#contexts.delete(context.id);
- }
- /** Tracks the given context. */
- addContext(context) {
- this.#contexts.set(context.id, context);
- }
- /** Returns true whether there is an existing context with the given ID. */
- hasContext(id) {
- return this.#contexts.has(id);
- }
- /** Gets the context with the given ID, if any. */
- findContext(id) {
- return this.#contexts.get(id);
- }
- /** Returns the top-level context ID of the given context, if any. */
- findTopLevelContextId(id) {
- if (id === null) {
- return null;
- }
- const maybeContext = this.findContext(id);
- const parentId = maybeContext?.parentId ?? null;
- if (parentId === null) {
- return id;
- }
- return this.findTopLevelContextId(parentId);
- }
- findContextBySession(sessionId) {
- for (const context of this.#contexts.values()) {
- if (context.cdpTarget.cdpSessionId === sessionId) {
- return context;
- }
- }
- return;
- }
- /** Gets the context with the given ID, if any, otherwise throws. */
- getContext(id) {
- const result = this.findContext(id);
- if (result === undefined) {
- throw new protocol_js_1$7.NoSuchFrameException(`Context ${id} not found`);
- }
- return result;
- }
- verifyTopLevelContextsList(contexts) {
- const foundContexts = new Set();
- if (!contexts) {
- return foundContexts;
- }
- for (const contextId of contexts) {
- const context = this.getContext(contextId);
- if (context.isTopLevelContext()) {
- foundContexts.add(context);
- }
- else {
- throw new protocol_js_1$7.InvalidArgumentException(`Non top-level context '${contextId}' given.`);
- }
- }
- return foundContexts;
- }
- }
- BrowsingContextStorage$1.BrowsingContextStorage = BrowsingContextStorage;
- var NetworkStorage$1 = {};
- var NetworkRequest$1 = {};
- /*
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
- Object.defineProperty(NetworkRequest$1, "__esModule", { value: true });
- NetworkRequest$1.NetworkRequest = void 0;
- const protocol_js_1$6 = protocol;
- const assert_js_1 = assert$1;
- const Deferred_js_1 = Deferred$1;
- const log_js_1$5 = log$1;
- const NetworkUtils_js_1$1 = NetworkUtils;
- const REALM_REGEX = /(?<=realm=").*(?=")/;
- /** Abstracts one individual network request. */
- class NetworkRequest {
- static unknownParameter = 'UNKNOWN';
- /**
- * Each network request has an associated request id, which is a string
- * uniquely identifying that request.
- *
- * The identifier for a request resulting from a redirect matches that of the
- * request that initiated it.
- */
- #id;
- #fetchId;
- /**
- * Indicates the network intercept phase, if the request is currently blocked.
- * Undefined necessarily implies that the request is not blocked.
- */
- #interceptPhase;
- #servedFromCache = false;
- #redirectCount;
- #request = {};
- #response = {};
- #eventManager;
- #networkStorage;
- #cdpTarget;
- #logger;
- #emittedEvents = {
- [protocol_js_1$6.ChromiumBidi.Network.EventNames.AuthRequired]: false,
- [protocol_js_1$6.ChromiumBidi.Network.EventNames.BeforeRequestSent]: false,
- [protocol_js_1$6.ChromiumBidi.Network.EventNames.FetchError]: false,
- [protocol_js_1$6.ChromiumBidi.Network.EventNames.ResponseCompleted]: false,
- [protocol_js_1$6.ChromiumBidi.Network.EventNames.ResponseStarted]: false,
- };
- waitNextPhase = new Deferred_js_1.Deferred();
- constructor(id, eventManager, networkStorage, cdpTarget, redirectCount = 0, logger) {
- this.#id = id;
- this.#eventManager = eventManager;
- this.#networkStorage = networkStorage;
- this.#cdpTarget = cdpTarget;
- this.#redirectCount = redirectCount;
- this.#logger = logger;
- }
- get id() {
- return this.#id;
- }
- get fetchId() {
- return this.#fetchId;
- }
- /**
- * When blocked returns the phase for it
- */
- get interceptPhase() {
- return this.#interceptPhase;
- }
- get url() {
- const fragment = this.#request.info?.request.urlFragment ??
- this.#request.paused?.request.urlFragment ??
- '';
- const url = this.#response.info?.url ??
- this.#response.paused?.request.url ??
- this.#request.auth?.request.url ??
- this.#request.info?.request.url ??
- this.#request.paused?.request.url ??
- NetworkRequest.unknownParameter;
- return `${url}${fragment}`;
- }
- get method() {
- return (this.#request.info?.request.method ??
- this.#request.paused?.request.method ??
- this.#request.auth?.request.method ??
- this.#response.paused?.request.method ??
- NetworkRequest.unknownParameter);
- }
- get redirectCount() {
- return this.#redirectCount;
- }
- get cdpTarget() {
- return this.#cdpTarget;
- }
- get cdpClient() {
- return this.#cdpTarget.cdpClient;
- }
- isRedirecting() {
- return Boolean(this.#request.info);
- }
- isDataUrl() {
- return this.url.startsWith('data:');
- }
- #phaseChanged() {
- this.waitNextPhase.resolve();
- this.waitNextPhase = new Deferred_js_1.Deferred();
- }
- #interceptsInPhase(phase) {
- if (!this.#cdpTarget.isSubscribedTo(`network.${phase}`)) {
- return new Set();
- }
- return this.#networkStorage.getInterceptsForPhase(this, phase);
- }
- #isBlockedInPhase(phase) {
- return this.#interceptsInPhase(phase).size > 0;
- }
- handleRedirect(event) {
- // TODO: use event.redirectResponse;
- // Temporary workaround to emit ResponseCompleted event for redirects
- this.#response.hasExtraInfo = false;
- this.#response.info = event.redirectResponse;
- this.#emitEventsIfReady({
- wasRedirected: true,
- });
- }
- #emitEventsIfReady(options = {}) {
- const requestExtraInfoCompleted =
- // Flush redirects
- options.wasRedirected ||
- options.hasFailed ||
- this.isDataUrl() ||
- Boolean(this.#request.extraInfo) ||
- // Requests from cache don't have extra info
- this.#servedFromCache ||
- // Sometimes there is no extra info and the response
- // is the only place we can find out
- Boolean(this.#response.info && !this.#response.hasExtraInfo);
- const noInterceptionExpected =
- // We can't intercept data urls from CDP
- this.isDataUrl() ||
- // Cached requests never hit the network
- this.#servedFromCache;
- const requestInterceptionExpected = !noInterceptionExpected &&
- this.#isBlockedInPhase("beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */);
- const requestInterceptionCompleted = !requestInterceptionExpected ||
- (requestInterceptionExpected && Boolean(this.#request.paused));
- if (Boolean(this.#request.info) &&
- (requestInterceptionExpected
- ? requestInterceptionCompleted
- : requestExtraInfoCompleted)) {
- this.#emitEvent(this.#getBeforeRequestEvent.bind(this));
- }
- const responseExtraInfoCompleted = Boolean(this.#response.extraInfo) ||
- // Response from cache don't have extra info
- this.#servedFromCache ||
- // Don't expect extra info if the flag is false
- Boolean(this.#response.info && !this.#response.hasExtraInfo);
- const responseInterceptionExpected = !noInterceptionExpected &&
- this.#isBlockedInPhase("responseStarted" /* Network.InterceptPhase.ResponseStarted */);
- if (this.#response.info ||
- (responseInterceptionExpected && Boolean(this.#response.paused))) {
- this.#emitEvent(this.#getResponseStartedEvent.bind(this));
- }
- const responseInterceptionCompleted = !responseInterceptionExpected ||
- (responseInterceptionExpected && Boolean(this.#response.paused));
- if (Boolean(this.#response.info) &&
- responseExtraInfoCompleted &&
- responseInterceptionCompleted) {
- this.#emitEvent(this.#getResponseReceivedEvent.bind(this));
- }
- }
- onRequestWillBeSentEvent(event) {
- this.#request.info = event;
- this.#emitEventsIfReady();
- }
- onRequestWillBeSentExtraInfoEvent(event) {
- this.#request.extraInfo = event;
- this.#emitEventsIfReady();
- }
- onResponseReceivedExtraInfoEvent(event) {
- this.#response.extraInfo = event;
- this.#emitEventsIfReady();
- }
- onResponseReceivedEvent(event) {
- this.#response.hasExtraInfo = event.hasExtraInfo;
- this.#response.info = event.response;
- this.#emitEventsIfReady();
- }
- onServedFromCache() {
- this.#servedFromCache = true;
- this.#emitEventsIfReady();
- }
- onLoadingFailedEvent(event) {
- this.#emitEventsIfReady({
- hasFailed: true,
- });
- this.#emitEvent(() => {
- return {
- method: protocol_js_1$6.ChromiumBidi.Network.EventNames.FetchError,
- params: {
- ...this.#getBaseEventParams(),
- errorText: event.errorText,
- },
- };
- });
- }
- /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-failRequest */
- async failRequest(errorReason) {
- (0, assert_js_1.assert)(this.#fetchId, 'Network Interception not set-up.');
- await this.cdpClient.sendCommand('Fetch.failRequest', {
- requestId: this.#fetchId,
- errorReason,
- });
- this.#interceptPhase = undefined;
- }
- onRequestPaused(event) {
- this.#fetchId = event.requestId;
- // CDP https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#event-requestPaused
- if (event.responseStatusCode || event.responseErrorReason) {
- this.#response.paused = event;
- if (this.#isBlockedInPhase("responseStarted" /* Network.InterceptPhase.ResponseStarted */) &&
- // CDP may emit multiple events for a single request
- !this.#emittedEvents[protocol_js_1$6.ChromiumBidi.Network.EventNames.ResponseStarted] &&
- // Continue all response that have not enabled Network domain
- this.#fetchId !== this.id) {
- this.#interceptPhase = "responseStarted" /* Network.InterceptPhase.ResponseStarted */;
- }
- else {
- void this.continueResponse();
- }
- }
- else {
- this.#request.paused = event;
- if (this.#isBlockedInPhase("beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */) &&
- // CDP may emit multiple events for a single request
- !this.#emittedEvents[protocol_js_1$6.ChromiumBidi.Network.EventNames.BeforeRequestSent] &&
- // Continue all requests that have not enabled Network domain
- this.#fetchId !== this.id) {
- this.#interceptPhase = "beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */;
- }
- else {
- void this.continueRequest();
- }
- }
- this.#emitEventsIfReady();
- }
- onAuthRequired(event) {
- this.#fetchId = event.requestId;
- this.#request.auth = event;
- if (this.#isBlockedInPhase("authRequired" /* Network.InterceptPhase.AuthRequired */) &&
- // Continue all auth requests that have not enabled Network domain
- this.#fetchId !== this.id) {
- this.#interceptPhase = "authRequired" /* Network.InterceptPhase.AuthRequired */;
- }
- else {
- void this.continueWithAuth();
- }
- this.#emitEvent(() => {
- return {
- method: protocol_js_1$6.ChromiumBidi.Network.EventNames.AuthRequired,
- params: {
- ...this.#getBaseEventParams("authRequired" /* Network.InterceptPhase.AuthRequired */),
- response: this.#getResponseEventParams(),
- },
- };
- });
- }
- /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-continueRequest */
- async continueRequest({ url, method, headers, postData, } = {}) {
- (0, assert_js_1.assert)(this.#fetchId, 'Network Interception not set-up.');
- await this.cdpClient.sendCommand('Fetch.continueRequest', {
- requestId: this.#fetchId,
- url,
- method,
- headers,
- postData,
- });
- this.#interceptPhase = undefined;
- }
- /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-continueResponse */
- async continueResponse({ responseCode, responsePhrase, responseHeaders, } = {}) {
- (0, assert_js_1.assert)(this.#fetchId, 'Network Interception not set-up.');
- await this.cdpClient.sendCommand('Fetch.continueResponse', {
- requestId: this.#fetchId,
- responseCode,
- responsePhrase,
- responseHeaders,
- });
- this.#interceptPhase = undefined;
- }
- /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-continueWithAuth */
- async continueWithAuth(authChallengeResponse = {
- response: 'Default',
- }) {
- (0, assert_js_1.assert)(this.#fetchId, 'Network Interception not set-up.');
- await this.cdpClient.sendCommand('Fetch.continueWithAuth', {
- requestId: this.#fetchId,
- authChallengeResponse,
- });
- this.#interceptPhase = undefined;
- }
- /** @see https://chromedevtools.github.io/devtools-protocol/tot/Fetch/#method-provideResponse */
- async provideResponse({ responseCode, responsePhrase, responseHeaders, body, }) {
- (0, assert_js_1.assert)(this.#fetchId, 'Network Interception not set-up.');
- await this.cdpClient.sendCommand('Fetch.fulfillRequest', {
- requestId: this.#fetchId,
- responseCode,
- responsePhrase,
- responseHeaders,
- body,
- });
- this.#interceptPhase = undefined;
- }
- get #context() {
- return (this.#response.paused?.frameId ??
- this.#request.info?.frameId ??
- this.#request.paused?.frameId ??
- this.#request.auth?.frameId ??
- null);
- }
- /** Returns the HTTP status code associated with this request if any. */
- get statusCode() {
- return (this.#response.paused?.responseStatusCode ??
- this.#response.extraInfo?.statusCode ??
- this.#response.info?.status);
- }
- #emitEvent(getEvent) {
- let event;
- try {
- event = getEvent();
- }
- catch (error) {
- this.#logger?.(log_js_1$5.LogType.debugError, error);
- return;
- }
- if (this.#isIgnoredEvent() ||
- (this.#emittedEvents[event.method] &&
- // Special case this event can be emitted multiple times
- event.method !== protocol_js_1$6.ChromiumBidi.Network.EventNames.AuthRequired)) {
- return;
- }
- this.#phaseChanged();
- this.#emittedEvents[event.method] = true;
- this.#eventManager.registerEvent(Object.assign(event, {
- type: 'event',
- }), this.#context);
- }
- #getBaseEventParams(phase) {
- const interceptProps = {
- isBlocked: false,
- };
- if (phase) {
- const blockedBy = this.#interceptsInPhase(phase);
- interceptProps.isBlocked = blockedBy.size > 0;
- if (interceptProps.isBlocked) {
- interceptProps.intercepts = [...blockedBy];
- }
- }
- return {
- context: this.#context,
- navigation: this.#getNavigationId(),
- redirectCount: this.#redirectCount,
- request: this.#getRequestData(),
- // Timestamp should be in milliseconds, while CDP provides it in seconds.
- timestamp: Math.round((this.#request.info?.wallTime ?? 0) * 1000),
- // Contains isBlocked and intercepts
- ...interceptProps,
- };
- }
- #getResponseEventParams() {
- // Chromium sends wrong extraInfo events for responses served from cache.
- // See https://github.com/puppeteer/puppeteer/issues/9965 and
- // https://crbug.com/1340398.
- if (this.#response.info?.fromDiskCache) {
- this.#response.extraInfo = undefined;
- }
- // TODO: get headers from Fetch.requestPaused
- const headers = (0, NetworkUtils_js_1$1.bidiNetworkHeadersFromCdpNetworkHeaders)(this.#response.info?.headers);
- // TODO: get headers from Fetch.requestPaused
- const authChallenges = this.#authChallenges(this.#response.info?.headers ?? {});
- return {
- url: this.url,
- protocol: this.#response.info?.protocol ?? '',
- status: this.statusCode ?? -1, // TODO: Throw an exception or use some other status code?
- statusText: this.#response.info?.statusText ||
- this.#response.paused?.responseStatusText ||
- '',
- fromCache: this.#response.info?.fromDiskCache ||
- this.#response.info?.fromPrefetchCache ||
- this.#servedFromCache,
- headers,
- mimeType: this.#response.info?.mimeType || '',
- bytesReceived: this.#response.info?.encodedDataLength || 0,
- headersSize: (0, NetworkUtils_js_1$1.computeHeadersSize)(headers),
- // TODO: consider removing from spec.
- bodySize: 0,
- content: {
- // TODO: consider removing from spec.
- size: 0,
- },
- ...(authChallenges ? { authChallenges } : {}),
- };
- }
- #getNavigationId() {
- if (!this.#request.info ||
- !this.#request.info.loaderId ||
- // When we navigate all CDP network events have `loaderId`
- // CDP's `loaderId` and `requestId` match when
- // that request triggered the loading
- this.#request.info.loaderId !== this.#request.info.requestId) {
- return null;
- }
- return this.#request.info.loaderId;
- }
- #getRequestData() {
- const cookies = this.#request.extraInfo
- ? NetworkRequest.#getCookies(this.#request.extraInfo.associatedCookies)
- : [];
- const headers = (0, NetworkUtils_js_1$1.bidiNetworkHeadersFromCdpNetworkHeaders)(this.#request.info?.request.headers);
- return {
- request: this.#id,
- url: this.url,
- method: this.method,
- headers,
- cookies,
- headersSize: (0, NetworkUtils_js_1$1.computeHeadersSize)(headers),
- // TODO: implement.
- bodySize: 0,
- timings: this.#getTimings(),
- };
- }
- // TODO: implement.
- #getTimings() {
- return {
- timeOrigin: 0,
- requestTime: 0,
- redirectStart: 0,
- redirectEnd: 0,
- fetchStart: 0,
- dnsStart: 0,
- dnsEnd: 0,
- connectStart: 0,
- connectEnd: 0,
- tlsStart: 0,
- requestStart: 0,
- responseStart: 0,
- responseEnd: 0,
- };
- }
- #getBeforeRequestEvent() {
- (0, assert_js_1.assert)(this.#request.info, 'RequestWillBeSentEvent is not set');
- return {
- method: protocol_js_1$6.ChromiumBidi.Network.EventNames.BeforeRequestSent,
- params: {
- ...this.#getBaseEventParams("beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */),
- initiator: {
- type: NetworkRequest.#getInitiatorType(this.#request.info.initiator.type),
- columnNumber: this.#request.info.initiator.columnNumber,
- lineNumber: this.#request.info.initiator.lineNumber,
- stackTrace: this.#request.info.initiator.stack,
- request: this.#request.info.initiator.requestId,
- },
- },
- };
- }
- #getResponseStartedEvent() {
- (0, assert_js_1.assert)(this.#request.info, 'RequestWillBeSentEvent is not set');
- (0, assert_js_1.assert)(
- // The response paused comes before any data for the response
- this.#response.paused || this.#response.info, 'ResponseReceivedEvent is not set');
- return {
- method: protocol_js_1$6.ChromiumBidi.Network.EventNames.ResponseStarted,
- params: {
- ...this.#getBaseEventParams("responseStarted" /* Network.InterceptPhase.ResponseStarted */),
- response: this.#getResponseEventParams(),
- },
- };
- }
- #getResponseReceivedEvent() {
- (0, assert_js_1.assert)(this.#request.info, 'RequestWillBeSentEvent is not set');
- (0, assert_js_1.assert)(this.#response.info, 'ResponseReceivedEvent is not set');
- return {
- method: protocol_js_1$6.ChromiumBidi.Network.EventNames.ResponseCompleted,
- params: {
- ...this.#getBaseEventParams(),
- response: this.#getResponseEventParams(),
- },
- };
- }
- #isIgnoredEvent() {
- const faviconUrl = '/favicon.ico';
- return (this.#request.paused?.request.url.endsWith(faviconUrl) ??
- this.#request.info?.request.url.endsWith(faviconUrl) ??
- false);
- }
- #authChallenges(headers) {
- if (!(this.statusCode === 401 || this.statusCode === 407)) {
- return undefined;
- }
- const headerName = this.statusCode === 401 ? 'WWW-Authenticate' : 'Proxy-Authenticate';
- const authChallenges = [];
- for (const [header, value] of Object.entries(headers)) {
- // TODO: Do a proper match based on https://httpwg.org/specs/rfc9110.html#credentials
- // Or verify this works
- if (header.localeCompare(headerName, undefined, { sensitivity: 'base' }) === 0) {
- authChallenges.push({
- scheme: value.split(' ').at(0) ?? '',
- realm: value.match(REALM_REGEX)?.at(0) ?? '',
- });
- }
- }
- return authChallenges;
- }
- static #getInitiatorType(initiatorType) {
- switch (initiatorType) {
- case 'parser':
- case 'script':
- case 'preflight':
- return initiatorType;
- default:
- return 'other';
- }
- }
- static #getCookies(associatedCookies) {
- return associatedCookies
- .filter(({ blockedReasons }) => {
- return !Array.isArray(blockedReasons) || blockedReasons.length === 0;
- })
- .map(({ cookie }) => (0, NetworkUtils_js_1$1.cdpToBiDiCookie)(cookie));
- }
- }
- NetworkRequest$1.NetworkRequest = NetworkRequest;
- Object.defineProperty(NetworkStorage$1, "__esModule", { value: true });
- NetworkStorage$1.NetworkStorage = void 0;
- const protocol_js_1$5 = protocol;
- const uuid_js_1 = uuid;
- const NetworkRequest_js_1 = NetworkRequest$1;
- const NetworkUtils_js_1 = NetworkUtils;
- /** Stores network and intercept maps. */
- class NetworkStorage {
- #eventManager;
- #logger;
- /**
- * A map from network request ID to Network Request objects.
- * Needed as long as information about requests comes from different events.
- */
- #requests = new Map();
- /** A map from intercept ID to track active network intercepts. */
- #intercepts = new Map();
- constructor(eventManager, browserClient, logger) {
- this.#eventManager = eventManager;
- browserClient.on('Target.detachedFromTarget', ({ sessionId }) => {
- this.disposeRequestMap(sessionId);
- });
- this.#logger = logger;
- }
- /**
- * Gets the network request with the given ID, if any.
- * Otherwise, creates a new network request with the given ID and cdp target.
- */
- #getOrCreateNetworkRequest(id, cdpTarget, redirectCount) {
- let request = this.getRequestById(id);
- if (request) {
- return request;
- }
- request = new NetworkRequest_js_1.NetworkRequest(id, this.#eventManager, this, cdpTarget, redirectCount, this.#logger);
- this.addRequest(request);
- return request;
- }
- onCdpTargetCreated(cdpTarget) {
- const cdpClient = cdpTarget.cdpClient;
- // TODO: Wrap into object
- const listeners = [
- [
- 'Network.requestWillBeSent',
- (params) => {
- const request = this.getRequestById(params.requestId);
- if (request && request.isRedirecting()) {
- request.handleRedirect(params);
- this.deleteRequest(params.requestId);
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget, request.redirectCount + 1).onRequestWillBeSentEvent(params);
- }
- else {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onRequestWillBeSentEvent(params);
- }
- },
- ],
- [
- 'Network.requestWillBeSentExtraInfo',
- (params) => {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onRequestWillBeSentExtraInfoEvent(params);
- },
- ],
- [
- 'Network.responseReceived',
- (params) => {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onResponseReceivedEvent(params);
- },
- ],
- [
- 'Network.responseReceivedExtraInfo',
- (params) => {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onResponseReceivedExtraInfoEvent(params);
- },
- ],
- [
- 'Network.requestServedFromCache',
- (params) => {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onServedFromCache();
- },
- ],
- [
- 'Network.loadingFailed',
- (params) => {
- this.#getOrCreateNetworkRequest(params.requestId, cdpTarget).onLoadingFailedEvent(params);
- },
- ],
- [
- 'Fetch.requestPaused',
- (event) => {
- this.#getOrCreateNetworkRequest(
- // CDP quirk if the Network domain is not present this is undefined
- event.networkId ?? event.requestId, cdpTarget).onRequestPaused(event);
- },
- ],
- [
- 'Fetch.authRequired',
- (event) => {
- let request = this.getRequestByFetchId(event.requestId);
- if (!request) {
- request = this.#getOrCreateNetworkRequest(event.requestId, cdpTarget);
- }
- request.onAuthRequired(event);
- },
- ],
- ];
- for (const [event, listener] of listeners) {
- cdpClient.on(event, listener);
- }
- }
- getInterceptionStages(browsingContextId) {
- const stages = {
- request: false,
- response: false,
- auth: false,
- };
- for (const intercept of this.#intercepts.values()) {
- if (intercept.contexts &&
- !intercept.contexts.includes(browsingContextId)) {
- continue;
- }
- stages.request ||= intercept.phases.includes("beforeRequestSent" /* Network.InterceptPhase.BeforeRequestSent */);
- stages.response ||= intercept.phases.includes("responseStarted" /* Network.InterceptPhase.ResponseStarted */);
- stages.auth ||= intercept.phases.includes("authRequired" /* Network.InterceptPhase.AuthRequired */);
- }
- return stages;
- }
- getInterceptsForPhase(request, phase) {
- if (request.url === NetworkRequest_js_1.NetworkRequest.unknownParameter) {
- return new Set();
- }
- const intercepts = new Set();
- for (const [interceptId, intercept] of this.#intercepts.entries()) {
- if (!intercept.phases.includes(phase) ||
- (intercept.contexts &&
- !intercept.contexts.includes(request.cdpTarget.topLevelId))) {
- continue;
- }
- if (intercept.urlPatterns.length === 0) {
- intercepts.add(interceptId);
- continue;
- }
- for (const pattern of intercept.urlPatterns) {
- if ((0, NetworkUtils_js_1.matchUrlPattern)(pattern, request.url)) {
- intercepts.add(interceptId);
- break;
- }
- }
- }
- return intercepts;
- }
- disposeRequestMap(sessionId) {
- for (const request of this.#requests.values()) {
- if (request.cdpClient.sessionId === sessionId) {
- this.#requests.delete(request.id);
- }
- }
- }
- /**
- * Adds the given entry to the intercept map.
- * URL patterns are assumed to be parsed.
- *
- * @return The intercept ID.
- */
- addIntercept(value) {
- const interceptId = (0, uuid_js_1.uuidv4)();
- this.#intercepts.set(interceptId, value);
- return interceptId;
- }
- /**
- * Removes the given intercept from the intercept map.
- * Throws NoSuchInterceptException if the intercept does not exist.
- */
- removeIntercept(intercept) {
- if (!this.#intercepts.has(intercept)) {
- throw new protocol_js_1$5.NoSuchInterceptException(`Intercept '${intercept}' does not exist.`);
- }
- this.#intercepts.delete(intercept);
- }
- getRequestById(id) {
- return this.#requests.get(id);
- }
- getRequestByFetchId(fetchId) {
- for (const request of this.#requests.values()) {
- if (request.fetchId === fetchId) {
- return request;
- }
- }
- return;
- }
- addRequest(request) {
- this.#requests.set(request.id, request);
- }
- deleteRequest(id) {
- this.#requests.delete(id);
- }
- }
- NetworkStorage$1.NetworkStorage = NetworkStorage;
- var PreloadScriptStorage$1 = {};
- Object.defineProperty(PreloadScriptStorage$1, "__esModule", { value: true });
- PreloadScriptStorage$1.PreloadScriptStorage = void 0;
- /**
- * Container class for preload scripts.
- */
- class PreloadScriptStorage {
- /** Tracks all BiDi preload scripts. */
- #scripts = new Set();
- /**
- * Finds all entries that match the given filter (OR logic).
- */
- find(filter) {
- if (!filter) {
- return [...this.#scripts];
- }
- return [...this.#scripts].filter((script) => {
- if (filter.id !== undefined && filter.id === script.id) {
- return true;
- }
- if (filter.targetId !== undefined &&
- script.targetIds.has(filter.targetId)) {
- return true;
- }
- if (filter.global !== undefined &&
- // Global scripts have no contexts
- ((filter.global && script.contexts === undefined) ||
- // Non global scripts always have contexts
- (!filter.global && script.contexts !== undefined))) {
- return true;
- }
- return false;
- });
- }
- add(preloadScript) {
- this.#scripts.add(preloadScript);
- }
- /** Deletes all BiDi preload script entries that match the given filter. */
- remove(filter) {
- for (const preloadScript of this.find(filter)) {
- this.#scripts.delete(preloadScript);
- }
- }
- }
- PreloadScriptStorage$1.PreloadScriptStorage = PreloadScriptStorage;
- var RealmStorage$1 = {};
- Object.defineProperty(RealmStorage$1, "__esModule", { value: true });
- RealmStorage$1.RealmStorage = void 0;
- const protocol_js_1$4 = protocol;
- const WindowRealm_js_1 = WindowRealm$1;
- /** Container class for browsing realms. */
- class RealmStorage {
- /** Tracks handles and their realms sent to the client. */
- #knownHandlesToRealmMap = new Map();
- /** Map from realm ID to Realm. */
- #realmMap = new Map();
- get knownHandlesToRealmMap() {
- return this.#knownHandlesToRealmMap;
- }
- addRealm(realm) {
- this.#realmMap.set(realm.realmId, realm);
- }
- /** Finds all realms that match the given filter. */
- findRealms(filter) {
- return Array.from(this.#realmMap.values()).filter((realm) => {
- if (filter.realmId !== undefined && filter.realmId !== realm.realmId) {
- return false;
- }
- if (filter.browsingContextId !== undefined &&
- !realm.associatedBrowsingContexts
- .map((browsingContext) => browsingContext.id)
- .includes(filter.browsingContextId)) {
- return false;
- }
- if (filter.sandbox !== undefined &&
- (!(realm instanceof WindowRealm_js_1.WindowRealm) || filter.sandbox !== realm.sandbox)) {
- return false;
- }
- if (filter.executionContextId !== undefined &&
- filter.executionContextId !== realm.executionContextId) {
- return false;
- }
- if (filter.origin !== undefined && filter.origin !== realm.origin) {
- return false;
- }
- if (filter.type !== undefined && filter.type !== realm.realmType) {
- return false;
- }
- if (filter.cdpSessionId !== undefined &&
- filter.cdpSessionId !== realm.cdpClient.sessionId) {
- return false;
- }
- return true;
- });
- }
- findRealm(filter) {
- const maybeRealms = this.findRealms(filter);
- if (maybeRealms.length !== 1) {
- return undefined;
- }
- return maybeRealms[0];
- }
- /** Gets the only realm that matches the given filter, if any, otherwise throws. */
- getRealm(filter) {
- const maybeRealm = this.findRealm(filter);
- if (maybeRealm === undefined) {
- throw new protocol_js_1$4.NoSuchFrameException(`Realm ${JSON.stringify(filter)} not found`);
- }
- return maybeRealm;
- }
- /** Deletes all realms that match the given filter. */
- deleteRealms(filter) {
- this.findRealms(filter).map((realm) => {
- realm.dispose();
- this.#realmMap.delete(realm.realmId);
- Array.from(this.knownHandlesToRealmMap.entries())
- .filter(([, r]) => r === realm.realmId)
- .map(([handle]) => this.knownHandlesToRealmMap.delete(handle));
- });
- }
- }
- RealmStorage$1.RealmStorage = RealmStorage;
- var EventManager$1 = {};
- var Buffer$2 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(Buffer$2, "__esModule", { value: true });
- Buffer$2.Buffer = void 0;
- /** Implements a FIFO buffer with a fixed size. */
- let Buffer$1 = class Buffer {
- #capacity;
- #entries = [];
- #onItemRemoved;
- /**
- * @param capacity The buffer capacity.
- * @param onItemRemoved Delegate called for each removed element.
- */
- constructor(capacity, onItemRemoved) {
- this.#capacity = capacity;
- this.#onItemRemoved = onItemRemoved;
- }
- get() {
- return this.#entries;
- }
- add(value) {
- this.#entries.push(value);
- while (this.#entries.length > this.#capacity) {
- const item = this.#entries.shift();
- if (item !== undefined) {
- this.#onItemRemoved?.(item);
- }
- }
- }
- };
- Buffer$2.Buffer = Buffer$1;
- var DefaultMap$1 = {};
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(DefaultMap$1, "__esModule", { value: true });
- DefaultMap$1.DefaultMap = void 0;
- /**
- * A subclass of Map whose functionality is almost the same as its parent
- * except for the fact that DefaultMap never returns undefined. It provides a
- * default value for keys that do not exist.
- */
- class DefaultMap extends Map {
- /** The default value to return whenever a key is not present in the map. */
- #getDefaultValue;
- constructor(getDefaultValue, entries) {
- super(entries);
- this.#getDefaultValue = getDefaultValue;
- }
- get(key) {
- if (!this.has(key)) {
- this.set(key, this.#getDefaultValue(key));
- }
- return super.get(key);
- }
- }
- DefaultMap$1.DefaultMap = DefaultMap;
- var IdWrapper$1 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(IdWrapper$1, "__esModule", { value: true });
- IdWrapper$1.IdWrapper = void 0;
- /**
- * Creates an object with a positive unique incrementing id.
- */
- class IdWrapper {
- static #counter = 0;
- #id;
- constructor() {
- this.#id = ++IdWrapper.#counter;
- }
- get id() {
- return this.#id;
- }
- }
- IdWrapper$1.IdWrapper = IdWrapper;
- var events = {};
- Object.defineProperty(events, "__esModule", { value: true });
- events.assertSupportedEvent = events.isCdpEvent = void 0;
- /**
- * Copyright 2023 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const protocol_js_1$3 = protocol;
- /**
- * Returns true if the given event is a CDP event.
- * @see https://chromedevtools.github.io/devtools-protocol/
- */
- function isCdpEvent(name) {
- return (name.split('.').at(0)?.startsWith(protocol_js_1$3.ChromiumBidi.BiDiModule.Cdp) ?? false);
- }
- events.isCdpEvent = isCdpEvent;
- /**
- * Asserts that the given event is known to BiDi or BiDi+, or throws otherwise.
- */
- function assertSupportedEvent(name) {
- if (!protocol_js_1$3.ChromiumBidi.EVENT_NAMES.has(name) && !isCdpEvent(name)) {
- throw new protocol_js_1$3.InvalidArgumentException(`Unknown event: ${name}`);
- }
- }
- events.assertSupportedEvent = assertSupportedEvent;
- var SubscriptionManager$1 = {};
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(SubscriptionManager$1, "__esModule", { value: true });
- SubscriptionManager$1.SubscriptionManager = SubscriptionManager$1.unrollEvents = SubscriptionManager$1.cartesianProduct = void 0;
- const protocol_js_1$2 = protocol;
- const events_js_1$1 = events;
- /**
- * Returns the cartesian product of the given arrays.
- *
- * Example:
- * cartesian([1, 2], ['a', 'b']); => [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']]
- */
- function cartesianProduct(...a) {
- return a.reduce((a, b) => a.flatMap((d) => b.map((e) => [d, e].flat())));
- }
- SubscriptionManager$1.cartesianProduct = cartesianProduct;
- /** Expands "AllEvents" events into atomic events. */
- function unrollEvents(events) {
- const allEvents = new Set();
- function addEvents(events) {
- for (const event of events) {
- allEvents.add(event);
- }
- }
- for (const event of events) {
- switch (event) {
- case protocol_js_1$2.ChromiumBidi.BiDiModule.BrowsingContext:
- addEvents(Object.values(protocol_js_1$2.ChromiumBidi.BrowsingContext.EventNames));
- break;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Log:
- addEvents(Object.values(protocol_js_1$2.ChromiumBidi.Log.EventNames));
- break;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Network:
- addEvents(Object.values(protocol_js_1$2.ChromiumBidi.Network.EventNames));
- break;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Script:
- addEvents(Object.values(protocol_js_1$2.ChromiumBidi.Script.EventNames));
- break;
- default:
- allEvents.add(event);
- }
- }
- return [...allEvents.values()];
- }
- SubscriptionManager$1.unrollEvents = unrollEvents;
- class SubscriptionManager {
- #subscriptionPriority = 0;
- // BrowsingContext `null` means the event has subscription across all the
- // browsing contexts.
- // Channel `null` means no `channel` should be added.
- #channelToContextToEventMap = new Map();
- #browsingContextStorage;
- constructor(browsingContextStorage) {
- this.#browsingContextStorage = browsingContextStorage;
- }
- getChannelsSubscribedToEvent(eventMethod, contextId) {
- const prioritiesAndChannels = Array.from(this.#channelToContextToEventMap.keys())
- .map((channel) => ({
- priority: this.#getEventSubscriptionPriorityForChannel(eventMethod, contextId, channel),
- channel,
- }))
- .filter(({ priority }) => priority !== null);
- // Sort channels by priority.
- return prioritiesAndChannels
- .sort((a, b) => a.priority - b.priority)
- .map(({ channel }) => channel);
- }
- #getEventSubscriptionPriorityForChannel(eventMethod, contextId, channel) {
- const contextToEventMap = this.#channelToContextToEventMap.get(channel);
- if (contextToEventMap === undefined) {
- return null;
- }
- const maybeTopLevelContextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
- // `null` covers global subscription.
- const relevantContexts = [...new Set([null, maybeTopLevelContextId])];
- // Get all the subscription priorities.
- const priorities = relevantContexts
- .map((context) => {
- // Get the priority for exact event name
- const priority = contextToEventMap.get(context)?.get(eventMethod);
- // For CDP we can't provide specific event name when subscribing
- // to the module directly.
- // Because of that we need to see event `cdp` exits in the map.
- if ((0, events_js_1$1.isCdpEvent)(eventMethod)) {
- const cdpPriority = contextToEventMap
- .get(context)
- ?.get(protocol_js_1$2.ChromiumBidi.BiDiModule.Cdp);
- // If we subscribe to the event directly and `cdp` module as well
- // priority will be different we take minimal priority
- return priority && cdpPriority
- ? Math.min(priority, cdpPriority)
- : // At this point we know that we have subscribed
- // to only one of the two
- priority ?? cdpPriority;
- }
- return priority;
- })
- .filter((p) => p !== undefined);
- if (priorities.length === 0) {
- // Not subscribed, return null.
- return null;
- }
- // Return minimal priority.
- return Math.min(...priorities);
- }
- /**
- * @param module BiDi+ module
- * @param contextId `null` == globally subscribed
- *
- * @returns
- */
- isSubscribedTo(moduleOrEvent, contextId = null) {
- const topLevelContext = this.#browsingContextStorage.findTopLevelContextId(contextId);
- for (const browserContextToEventMap of this.#channelToContextToEventMap.values()) {
- for (const [id, eventMap] of browserContextToEventMap.entries()) {
- // Not subscribed to this context or globally
- if (topLevelContext !== id && id !== null) {
- continue;
- }
- for (const event of eventMap.keys()) {
- // This also covers the `cdp` case where
- // we don't unroll the event names
- if (
- // Event explicitly subscribed
- event === moduleOrEvent ||
- // Event subscribed via module
- event === moduleOrEvent.split('.').at(0) ||
- // Event explicitly subscribed compared to module
- event.split('.').at(0) === moduleOrEvent) {
- return true;
- }
- }
- }
- }
- return false;
- }
- subscribe(event, contextId, channel) {
- // All the subscriptions are handled on the top-level contexts.
- contextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
- // Check if subscribed event is a whole module
- switch (event) {
- case protocol_js_1$2.ChromiumBidi.BiDiModule.BrowsingContext:
- Object.values(protocol_js_1$2.ChromiumBidi.BrowsingContext.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
- return;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Log:
- Object.values(protocol_js_1$2.ChromiumBidi.Log.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
- return;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Network:
- Object.values(protocol_js_1$2.ChromiumBidi.Network.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
- return;
- case protocol_js_1$2.ChromiumBidi.BiDiModule.Script:
- Object.values(protocol_js_1$2.ChromiumBidi.Script.EventNames).map((specificEvent) => this.subscribe(specificEvent, contextId, channel));
- return;
- // Intentionally left empty.
- }
- if (!this.#channelToContextToEventMap.has(channel)) {
- this.#channelToContextToEventMap.set(channel, new Map());
- }
- const contextToEventMap = this.#channelToContextToEventMap.get(channel);
- if (!contextToEventMap.has(contextId)) {
- contextToEventMap.set(contextId, new Map());
- }
- const eventMap = contextToEventMap.get(contextId);
- // Do not re-subscribe to events to keep the priority.
- if (eventMap.has(event)) {
- return;
- }
- eventMap.set(event, this.#subscriptionPriority++);
- }
- /**
- * Unsubscribes atomically from all events in the given contexts and channel.
- */
- unsubscribeAll(events, contextIds, channel) {
- // Assert all contexts are known.
- for (const contextId of contextIds) {
- if (contextId !== null) {
- this.#browsingContextStorage.getContext(contextId);
- }
- }
- const eventContextPairs = cartesianProduct(unrollEvents(events), contextIds);
- // Assert all unsubscriptions are valid.
- // If any of the unsubscriptions are invalid, do not unsubscribe from anything.
- eventContextPairs
- .map(([event, contextId]) => this.#checkUnsubscribe(event, contextId, channel))
- .forEach((unsubscribe) => unsubscribe());
- }
- /**
- * Unsubscribes from the event in the given context and channel.
- * Syntactic sugar for "unsubscribeAll".
- */
- unsubscribe(eventName, contextId, channel) {
- this.unsubscribeAll([eventName], [contextId], channel);
- }
- #checkUnsubscribe(event, contextId, channel) {
- // All the subscriptions are handled on the top-level contexts.
- contextId = this.#browsingContextStorage.findTopLevelContextId(contextId);
- if (!this.#channelToContextToEventMap.has(channel)) {
- throw new protocol_js_1$2.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
- }
- const contextToEventMap = this.#channelToContextToEventMap.get(channel);
- if (!contextToEventMap.has(contextId)) {
- throw new protocol_js_1$2.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
- }
- const eventMap = contextToEventMap.get(contextId);
- if (!eventMap.has(event)) {
- throw new protocol_js_1$2.InvalidArgumentException(`Cannot unsubscribe from ${event}, ${contextId === null ? 'null' : contextId}. No subscription found.`);
- }
- return () => {
- eventMap.delete(event);
- // Clean up maps if empty.
- if (eventMap.size === 0) {
- contextToEventMap.delete(event);
- }
- if (contextToEventMap.size === 0) {
- this.#channelToContextToEventMap.delete(channel);
- }
- };
- }
- }
- SubscriptionManager$1.SubscriptionManager = SubscriptionManager;
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(EventManager$1, "__esModule", { value: true });
- EventManager$1.EventManager = void 0;
- const protocol_js_1$1 = protocol;
- const Buffer_js_1 = Buffer$2;
- const DefaultMap_js_1 = DefaultMap$1;
- const EventEmitter_js_1$2 = EventEmitter$1;
- const IdWrapper_js_1 = IdWrapper$1;
- const OutgoingMessage_js_1 = OutgoingMessage$1;
- const events_js_1 = events;
- const SubscriptionManager_js_1 = SubscriptionManager$1;
- class EventWrapper {
- #idWrapper = new IdWrapper_js_1.IdWrapper();
- #contextId;
- #event;
- constructor(event, contextId) {
- this.#event = event;
- this.#contextId = contextId;
- }
- get id() {
- return this.#idWrapper.id;
- }
- get contextId() {
- return this.#contextId;
- }
- get event() {
- return this.#event;
- }
- }
- /**
- * Maps event name to a desired buffer length.
- */
- const eventBufferLength = new Map([[protocol_js_1$1.ChromiumBidi.Log.EventNames.LogEntryAdded, 100]]);
- class EventManager extends EventEmitter_js_1$2.EventEmitter {
- /**
- * Maps event name to a set of contexts where this event already happened.
- * Needed for getting buffered events from all the contexts in case of
- * subscripting to all contexts.
- */
- #eventToContextsMap = new DefaultMap_js_1.DefaultMap(() => new Set());
- /**
- * Maps `eventName` + `browsingContext` to buffer. Used to get buffered events
- * during subscription. Channel-agnostic.
- */
- #eventBuffers = new Map();
- /**
- * Maps `eventName` + `browsingContext` + `channel` to last sent event id.
- * Used to avoid sending duplicated events when user
- * subscribes -> unsubscribes -> subscribes.
- */
- #lastMessageSent = new Map();
- #subscriptionManager;
- #browsingContextStorage;
- constructor(browsingContextStorage) {
- super();
- this.#browsingContextStorage = browsingContextStorage;
- this.#subscriptionManager = new SubscriptionManager_js_1.SubscriptionManager(browsingContextStorage);
- }
- get subscriptionManager() {
- return this.#subscriptionManager;
- }
- /**
- * Returns consistent key to be used to access value maps.
- */
- static #getMapKey(eventName, browsingContext, channel) {
- return JSON.stringify({ eventName, browsingContext, channel });
- }
- registerEvent(event, contextId) {
- this.registerPromiseEvent(Promise.resolve({
- kind: 'success',
- value: event,
- }), contextId, event.method);
- }
- registerPromiseEvent(event, contextId, eventName) {
- const eventWrapper = new EventWrapper(event, contextId);
- const sortedChannels = this.#subscriptionManager.getChannelsSubscribedToEvent(eventName, contextId);
- this.#bufferEvent(eventWrapper, eventName);
- // Send events to channels in the subscription priority.
- for (const channel of sortedChannels) {
- this.emit("event" /* EventManagerEvents.Event */, {
- message: OutgoingMessage_js_1.OutgoingMessage.createFromPromise(event, channel),
- event: eventName,
- });
- this.#markEventSent(eventWrapper, channel, eventName);
- }
- }
- async subscribe(eventNames, contextIds, channel) {
- for (const name of eventNames) {
- (0, events_js_1.assertSupportedEvent)(name);
- }
- // First check if all the contexts are known.
- for (const contextId of contextIds) {
- if (contextId !== null) {
- // Assert the context is known. Throw exception otherwise.
- this.#browsingContextStorage.getContext(contextId);
- }
- }
- for (const eventName of eventNames) {
- for (const contextId of contextIds) {
- this.#subscriptionManager.subscribe(eventName, contextId, channel);
- for (const eventWrapper of this.#getBufferedEvents(eventName, contextId, channel)) {
- // The order of the events is important.
- this.emit("event" /* EventManagerEvents.Event */, {
- message: OutgoingMessage_js_1.OutgoingMessage.createFromPromise(eventWrapper.event, channel),
- event: eventName,
- });
- this.#markEventSent(eventWrapper, channel, eventName);
- }
- }
- }
- await this.toggleModulesIfNeeded();
- }
- async unsubscribe(eventNames, contextIds, channel) {
- for (const name of eventNames) {
- (0, events_js_1.assertSupportedEvent)(name);
- }
- this.#subscriptionManager.unsubscribeAll(eventNames, contextIds, channel);
- await this.toggleModulesIfNeeded();
- }
- async toggleModulesIfNeeded() {
- // TODO(1): Only update changed subscribers
- // TODO(2): Enable for Worker Targets
- await Promise.all(this.#browsingContextStorage.getAllContexts().map(async (context) => {
- return await context.toggleModulesIfNeeded();
- }));
- }
- /**
- * If the event is buffer-able, put it in the buffer.
- */
- #bufferEvent(eventWrapper, eventName) {
- if (!eventBufferLength.has(eventName)) {
- // Do nothing if the event is no buffer-able.
- return;
- }
- const bufferMapKey = EventManager.#getMapKey(eventName, eventWrapper.contextId);
- if (!this.#eventBuffers.has(bufferMapKey)) {
- this.#eventBuffers.set(bufferMapKey, new Buffer_js_1.Buffer(eventBufferLength.get(eventName)));
- }
- this.#eventBuffers.get(bufferMapKey).add(eventWrapper);
- // Add the context to the list of contexts having `eventName` events.
- this.#eventToContextsMap.get(eventName).add(eventWrapper.contextId);
- }
- /**
- * If the event is buffer-able, mark it as sent to the given contextId and channel.
- */
- #markEventSent(eventWrapper, channel, eventName) {
- if (!eventBufferLength.has(eventName)) {
- // Do nothing if the event is no buffer-able.
- return;
- }
- const lastSentMapKey = EventManager.#getMapKey(eventName, eventWrapper.contextId, channel);
- this.#lastMessageSent.set(lastSentMapKey, Math.max(this.#lastMessageSent.get(lastSentMapKey) ?? 0, eventWrapper.id));
- }
- /**
- * Returns events which are buffered and not yet sent to the given channel events.
- */
- #getBufferedEvents(eventName, contextId, channel) {
- const bufferMapKey = EventManager.#getMapKey(eventName, contextId);
- const lastSentMapKey = EventManager.#getMapKey(eventName, contextId, channel);
- const lastSentMessageId = this.#lastMessageSent.get(lastSentMapKey) ?? -Infinity;
- const result = this.#eventBuffers
- .get(bufferMapKey)
- ?.get()
- .filter((wrapper) => wrapper.id > lastSentMessageId) ?? [];
- if (contextId === null) {
- // For global subscriptions, events buffered in each context should be sent back.
- Array.from(this.#eventToContextsMap.get(eventName).keys())
- .filter((_contextId) =>
- // Events without context are already in the result.
- _contextId !== null &&
- // Events from deleted contexts should not be sent.
- this.#browsingContextStorage.hasContext(_contextId))
- .map((_contextId) => this.#getBufferedEvents(eventName, _contextId, channel))
- .forEach((events) => result.push(...events));
- }
- return result.sort((e1, e2) => e1.id - e2.id);
- }
- }
- EventManager$1.EventManager = EventManager;
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(BidiServer$1, "__esModule", { value: true });
- BidiServer$1.BidiServer = void 0;
- const EventEmitter_js_1$1 = EventEmitter$1;
- const log_js_1$4 = log$1;
- const ProcessingQueue_js_1 = ProcessingQueue$1;
- const CommandProcessor_js_1 = CommandProcessor$1;
- const CdpTargetManager_js_1 = CdpTargetManager$1;
- const BrowsingContextStorage_js_1 = BrowsingContextStorage$1;
- const NetworkStorage_js_1 = NetworkStorage$1;
- const PreloadScriptStorage_js_1 = PreloadScriptStorage$1;
- const RealmStorage_js_1 = RealmStorage$1;
- const EventManager_js_1 = EventManager$1;
- class BidiServer extends EventEmitter_js_1$1.EventEmitter {
- #messageQueue;
- #transport;
- #commandProcessor;
- #eventManager;
- #browsingContextStorage = new BrowsingContextStorage_js_1.BrowsingContextStorage();
- #realmStorage = new RealmStorage_js_1.RealmStorage();
- #preloadScriptStorage = new PreloadScriptStorage_js_1.PreloadScriptStorage();
- #logger;
- #handleIncomingMessage = (message) => {
- void this.#commandProcessor.processCommand(message).catch((error) => {
- this.#logger?.(log_js_1$4.LogType.debugError, error);
- });
- };
- #processOutgoingMessage = async (messageEntry) => {
- const message = messageEntry.message;
- if (messageEntry.channel !== null) {
- message['channel'] = messageEntry.channel;
- }
- await this.#transport.sendMessage(message);
- };
- constructor(bidiTransport, cdpConnection, browserCdpClient, selfTargetId, defaultUserContextId, options, parser, logger) {
- super();
- this.#logger = logger;
- this.#messageQueue = new ProcessingQueue_js_1.ProcessingQueue(this.#processOutgoingMessage, this.#logger);
- this.#transport = bidiTransport;
- this.#transport.setOnMessage(this.#handleIncomingMessage);
- this.#eventManager = new EventManager_js_1.EventManager(this.#browsingContextStorage);
- const networkStorage = new NetworkStorage_js_1.NetworkStorage(this.#eventManager, browserCdpClient, logger);
- new CdpTargetManager_js_1.CdpTargetManager(cdpConnection, browserCdpClient, selfTargetId, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, networkStorage, this.#preloadScriptStorage, options?.acceptInsecureCerts ?? false, defaultUserContextId, logger);
- this.#commandProcessor = new CommandProcessor_js_1.CommandProcessor(cdpConnection, browserCdpClient, this.#eventManager, this.#browsingContextStorage, this.#realmStorage, this.#preloadScriptStorage, networkStorage, parser, this.#logger);
- this.#eventManager.on("event" /* EventManagerEvents.Event */, ({ message, event }) => {
- this.emitOutgoingMessage(message, event);
- });
- this.#commandProcessor.on("response" /* CommandProcessorEvents.Response */, ({ message, event }) => {
- this.emitOutgoingMessage(message, event);
- });
- }
- /**
- * Creates and starts BiDi Mapper instance.
- */
- static async createAndStart(bidiTransport, cdpConnection, browserCdpClient, selfTargetId, options, parser, logger) {
- // The default context is not exposed in Target.getBrowserContexts but can
- // be observed via Target.getTargets. To determine the default browser
- // context, we check which one is mentioned in Target.getTargets and not in
- // Target.getBrowserContexts.
- const [{ browserContextIds }, { targetInfos }] = await Promise.all([
- browserCdpClient.sendCommand('Target.getBrowserContexts'),
- browserCdpClient.sendCommand('Target.getTargets'),
- ]);
- let defaultUserContextId = 'default';
- for (const info of targetInfos) {
- if (info.browserContextId &&
- !browserContextIds.includes(info.browserContextId)) {
- defaultUserContextId = info.browserContextId;
- break;
- }
- }
- const server = new BidiServer(bidiTransport, cdpConnection, browserCdpClient, selfTargetId, defaultUserContextId, options, parser, logger);
- // Needed to get events about new targets.
- await browserCdpClient.sendCommand('Target.setDiscoverTargets', {
- discover: true,
- });
- // Needed to automatically attach to new targets.
- await browserCdpClient.sendCommand('Target.setAutoAttach', {
- autoAttach: true,
- waitForDebuggerOnStart: true,
- flatten: true,
- });
- await server.#topLevelContextsLoaded();
- return server;
- }
- /**
- * Sends BiDi message.
- */
- emitOutgoingMessage(messageEntry, event) {
- this.#messageQueue.add(messageEntry, event);
- }
- close() {
- this.#transport.close();
- }
- async #topLevelContextsLoaded() {
- await Promise.all(this.#browsingContextStorage
- .getTopLevelContexts()
- .map((c) => c.lifecycleLoaded()));
- }
- }
- BidiServer$1.BidiServer = BidiServer;
- (function (exports) {
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.OutgoingMessage = exports.EventEmitter = exports.BidiServer = void 0;
- /**
- * @fileoverview The entry point to the BiDi Mapper namespace.
- * Other modules should only access exports defined in this file.
- * XXX: Add ESlint rule for this (https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-restricted-paths.md)
- */
- var BidiServer_js_1 = BidiServer$1;
- Object.defineProperty(exports, "BidiServer", { enumerable: true, get: function () { return BidiServer_js_1.BidiServer; } });
- var EventEmitter_js_1 = EventEmitter$1;
- Object.defineProperty(exports, "EventEmitter", { enumerable: true, get: function () { return EventEmitter_js_1.EventEmitter; } });
- var OutgoingMessage_js_1 = OutgoingMessage$1;
- Object.defineProperty(exports, "OutgoingMessage", { enumerable: true, get: function () { return OutgoingMessage_js_1.OutgoingMessage; } });
-
- } (BidiMapper));
- var CdpConnection = {};
- var CdpClient = {};
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- Object.defineProperty(CdpClient, "__esModule", { value: true });
- CdpClient.MapperCdpClient = CdpClient.CloseError = void 0;
- const EventEmitter_js_1 = EventEmitter$1;
- /** A error that will be thrown if/when the connection is closed. */
- class CloseError extends Error {
- }
- CdpClient.CloseError = CloseError;
- /** Represents a high-level CDP connection to the browser. */
- class MapperCdpClient extends EventEmitter_js_1.EventEmitter {
- #cdpConnection;
- #sessionId;
- constructor(cdpConnection, sessionId) {
- super();
- this.#cdpConnection = cdpConnection;
- this.#sessionId = sessionId;
- }
- get sessionId() {
- return this.#sessionId;
- }
- sendCommand(method, ...params) {
- return this.#cdpConnection.sendCommand(method, params[0], this.#sessionId);
- }
- isCloseError(error) {
- return error instanceof CloseError;
- }
- }
- CdpClient.MapperCdpClient = MapperCdpClient;
- Object.defineProperty(CdpConnection, "__esModule", { value: true });
- CdpConnection.MapperCdpConnection = void 0;
- const log_js_1$3 = log$1;
- const CdpClient_js_1 = CdpClient;
- /**
- * Represents a high-level CDP connection to the browser backend.
- *
- * Manages all CdpClients (each backed by a Session ID) instance for each active
- * CDP session.
- */
- class MapperCdpConnection {
- static LOGGER_PREFIX_RECV = `${log_js_1$3.LogType.cdp}:RECV ◂`;
- static LOGGER_PREFIX_SEND = `${log_js_1$3.LogType.cdp}:SEND ▸`;
- #mainBrowserCdpClient;
- #transport;
- /** Map from session ID to CdpClient.
- * `undefined` points to the main browser session. */
- #sessionCdpClients = new Map();
- #commandCallbacks = new Map();
- #logger;
- #nextId = 0;
- constructor(transport, logger) {
- this.#transport = transport;
- this.#logger = logger;
- this.#transport.setOnMessage(this.#onMessage);
- // Create default Browser CDP Session.
- this.#mainBrowserCdpClient = this.#createCdpClient(undefined);
- }
- /** Closes the connection to the browser. */
- close() {
- this.#transport.close();
- for (const [, { reject, error }] of this.#commandCallbacks) {
- reject(error);
- }
- this.#commandCallbacks.clear();
- this.#sessionCdpClients.clear();
- }
- async createBrowserSession() {
- const { sessionId } = await this.#mainBrowserCdpClient.sendCommand('Target.attachToBrowserTarget');
- return this.#createCdpClient(sessionId);
- }
- /**
- * Gets a CdpClient instance attached to the given session ID,
- * or null if the session is not attached.
- */
- getCdpClient(sessionId) {
- const cdpClient = this.#sessionCdpClients.get(sessionId);
- if (!cdpClient) {
- throw new Error(`Unknown CDP session ID: ${sessionId}`);
- }
- return cdpClient;
- }
- sendCommand(method, params, sessionId) {
- return new Promise((resolve, reject) => {
- const id = this.#nextId++;
- this.#commandCallbacks.set(id, {
- resolve,
- reject,
- error: new CdpClient_js_1.CloseError(`${method} ${JSON.stringify(params)} ${sessionId ?? ''} call rejected because the connection has been closed.`),
- });
- const cdpMessage = { id, method, params };
- if (sessionId) {
- cdpMessage.sessionId = sessionId;
- }
- void this.#transport
- .sendMessage(JSON.stringify(cdpMessage))
- ?.catch((error) => {
- this.#logger?.(log_js_1$3.LogType.debugError, error);
- this.#transport.close();
- });
- this.#logger?.(MapperCdpConnection.LOGGER_PREFIX_SEND, cdpMessage);
- });
- }
- #onMessage = (json) => {
- const message = JSON.parse(json);
- this.#logger?.(MapperCdpConnection.LOGGER_PREFIX_RECV, message);
- // Update client map if a session is attached
- // Listen for these events on every session.
- if (message.method === 'Target.attachedToTarget') {
- const { sessionId } = message.params;
- this.#createCdpClient(sessionId);
- }
- if (message.id !== undefined) {
- // Handle command response.
- const callbacks = this.#commandCallbacks.get(message.id);
- this.#commandCallbacks.delete(message.id);
- if (callbacks) {
- if (message.result) {
- callbacks.resolve(message.result);
- }
- else if (message.error) {
- callbacks.reject(message.error);
- }
- }
- }
- else if (message.method) {
- const client = this.#sessionCdpClients.get(message.sessionId ?? undefined);
- client?.emit(message.method, message.params || {});
- // Update client map if a session is detached
- // But emit on that session
- if (message.method === 'Target.detachedFromTarget') {
- const { sessionId } = message.params;
- const client = this.#sessionCdpClients.get(sessionId);
- if (client) {
- this.#sessionCdpClients.delete(sessionId);
- client.removeAllListeners();
- }
- }
- }
- };
- /**
- * Creates a new CdpClient instance for the given session ID.
- * @param sessionId either a string, or undefined for the main browser session.
- * The main browser session is used only to create new browser sessions.
- * @private
- */
- #createCdpClient(sessionId) {
- const cdpClient = new CdpClient_js_1.MapperCdpClient(this, sessionId);
- this.#sessionCdpClients.set(sessionId, cdpClient);
- return cdpClient;
- }
- }
- CdpConnection.MapperCdpConnection = MapperCdpConnection;
- var BidiParser$1 = {};
- var protocolParser = {};
- var lib = {};
- var external = {};
- var errors = {};
- var en = {};
- var util = {};
- (function (exports) {
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
- var util;
- (function (util) {
- util.assertEqual = (val) => val;
- function assertIs(_arg) { }
- util.assertIs = assertIs;
- function assertNever(_x) {
- throw new Error();
- }
- util.assertNever = assertNever;
- util.arrayToEnum = (items) => {
- const obj = {};
- for (const item of items) {
- obj[item] = item;
- }
- return obj;
- };
- util.getValidEnumValues = (obj) => {
- const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
- const filtered = {};
- for (const k of validKeys) {
- filtered[k] = obj[k];
- }
- return util.objectValues(filtered);
- };
- util.objectValues = (obj) => {
- return util.objectKeys(obj).map(function (e) {
- return obj[e];
- });
- };
- util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
- ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
- : (object) => {
- const keys = [];
- for (const key in object) {
- if (Object.prototype.hasOwnProperty.call(object, key)) {
- keys.push(key);
- }
- }
- return keys;
- };
- util.find = (arr, checker) => {
- for (const item of arr) {
- if (checker(item))
- return item;
- }
- return undefined;
- };
- util.isInteger = typeof Number.isInteger === "function"
- ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
- function joinValues(array, separator = " | ") {
- return array
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
- .join(separator);
- }
- util.joinValues = joinValues;
- util.jsonStringifyReplacer = (_, value) => {
- if (typeof value === "bigint") {
- return value.toString();
- }
- return value;
- };
- })(util = exports.util || (exports.util = {}));
- (function (objectUtil) {
- objectUtil.mergeShapes = (first, second) => {
- return {
- ...first,
- ...second, // second overwrites first
- };
- };
- })(exports.objectUtil || (exports.objectUtil = {}));
- exports.ZodParsedType = util.arrayToEnum([
- "string",
- "nan",
- "number",
- "integer",
- "float",
- "boolean",
- "date",
- "bigint",
- "symbol",
- "function",
- "undefined",
- "null",
- "array",
- "object",
- "unknown",
- "promise",
- "void",
- "never",
- "map",
- "set",
- ]);
- const getParsedType = (data) => {
- const t = typeof data;
- switch (t) {
- case "undefined":
- return exports.ZodParsedType.undefined;
- case "string":
- return exports.ZodParsedType.string;
- case "number":
- return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
- case "boolean":
- return exports.ZodParsedType.boolean;
- case "function":
- return exports.ZodParsedType.function;
- case "bigint":
- return exports.ZodParsedType.bigint;
- case "symbol":
- return exports.ZodParsedType.symbol;
- case "object":
- if (Array.isArray(data)) {
- return exports.ZodParsedType.array;
- }
- if (data === null) {
- return exports.ZodParsedType.null;
- }
- if (data.then &&
- typeof data.then === "function" &&
- data.catch &&
- typeof data.catch === "function") {
- return exports.ZodParsedType.promise;
- }
- if (typeof Map !== "undefined" && data instanceof Map) {
- return exports.ZodParsedType.map;
- }
- if (typeof Set !== "undefined" && data instanceof Set) {
- return exports.ZodParsedType.set;
- }
- if (typeof Date !== "undefined" && data instanceof Date) {
- return exports.ZodParsedType.date;
- }
- return exports.ZodParsedType.object;
- default:
- return exports.ZodParsedType.unknown;
- }
- };
- exports.getParsedType = getParsedType;
- } (util));
- var ZodError$1 = {};
- Object.defineProperty(ZodError$1, "__esModule", { value: true });
- ZodError$1.ZodError = ZodError$1.quotelessJson = ZodError$1.ZodIssueCode = void 0;
- const util_1$1 = util;
- ZodError$1.ZodIssueCode = util_1$1.util.arrayToEnum([
- "invalid_type",
- "invalid_literal",
- "custom",
- "invalid_union",
- "invalid_union_discriminator",
- "invalid_enum_value",
- "unrecognized_keys",
- "invalid_arguments",
- "invalid_return_type",
- "invalid_date",
- "invalid_string",
- "too_small",
- "too_big",
- "invalid_intersection_types",
- "not_multiple_of",
- "not_finite",
- ]);
- const quotelessJson = (obj) => {
- const json = JSON.stringify(obj, null, 2);
- return json.replace(/"([^"]+)":/g, "$1:");
- };
- ZodError$1.quotelessJson = quotelessJson;
- class ZodError extends Error {
- constructor(issues) {
- super();
- this.issues = [];
- this.addIssue = (sub) => {
- this.issues = [...this.issues, sub];
- };
- this.addIssues = (subs = []) => {
- this.issues = [...this.issues, ...subs];
- };
- const actualProto = new.target.prototype;
- if (Object.setPrototypeOf) {
- // eslint-disable-next-line ban/ban
- Object.setPrototypeOf(this, actualProto);
- }
- else {
- this.__proto__ = actualProto;
- }
- this.name = "ZodError";
- this.issues = issues;
- }
- get errors() {
- return this.issues;
- }
- format(_mapper) {
- const mapper = _mapper ||
- function (issue) {
- return issue.message;
- };
- const fieldErrors = { _errors: [] };
- const processError = (error) => {
- for (const issue of error.issues) {
- if (issue.code === "invalid_union") {
- issue.unionErrors.map(processError);
- }
- else if (issue.code === "invalid_return_type") {
- processError(issue.returnTypeError);
- }
- else if (issue.code === "invalid_arguments") {
- processError(issue.argumentsError);
- }
- else if (issue.path.length === 0) {
- fieldErrors._errors.push(mapper(issue));
- }
- else {
- let curr = fieldErrors;
- let i = 0;
- while (i < issue.path.length) {
- const el = issue.path[i];
- const terminal = i === issue.path.length - 1;
- if (!terminal) {
- curr[el] = curr[el] || { _errors: [] };
- // if (typeof el === "string") {
- // curr[el] = curr[el] || { _errors: [] };
- // } else if (typeof el === "number") {
- // const errorArray: any = [];
- // errorArray._errors = [];
- // curr[el] = curr[el] || errorArray;
- // }
- }
- else {
- curr[el] = curr[el] || { _errors: [] };
- curr[el]._errors.push(mapper(issue));
- }
- curr = curr[el];
- i++;
- }
- }
- }
- };
- processError(this);
- return fieldErrors;
- }
- toString() {
- return this.message;
- }
- get message() {
- return JSON.stringify(this.issues, util_1$1.util.jsonStringifyReplacer, 2);
- }
- get isEmpty() {
- return this.issues.length === 0;
- }
- flatten(mapper = (issue) => issue.message) {
- const fieldErrors = {};
- const formErrors = [];
- for (const sub of this.issues) {
- if (sub.path.length > 0) {
- fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
- fieldErrors[sub.path[0]].push(mapper(sub));
- }
- else {
- formErrors.push(mapper(sub));
- }
- }
- return { formErrors, fieldErrors };
- }
- get formErrors() {
- return this.flatten();
- }
- }
- ZodError$1.ZodError = ZodError;
- ZodError.create = (issues) => {
- const error = new ZodError(issues);
- return error;
- };
- Object.defineProperty(en, "__esModule", { value: true });
- const util_1 = util;
- const ZodError_1 = ZodError$1;
- const errorMap = (issue, _ctx) => {
- let message;
- switch (issue.code) {
- case ZodError_1.ZodIssueCode.invalid_type:
- if (issue.received === util_1.ZodParsedType.undefined) {
- message = "Required";
- }
- else {
- message = `Expected ${issue.expected}, received ${issue.received}`;
- }
- break;
- case ZodError_1.ZodIssueCode.invalid_literal:
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_1.util.jsonStringifyReplacer)}`;
- break;
- case ZodError_1.ZodIssueCode.unrecognized_keys:
- message = `Unrecognized key(s) in object: ${util_1.util.joinValues(issue.keys, ", ")}`;
- break;
- case ZodError_1.ZodIssueCode.invalid_union:
- message = `Invalid input`;
- break;
- case ZodError_1.ZodIssueCode.invalid_union_discriminator:
- message = `Invalid discriminator value. Expected ${util_1.util.joinValues(issue.options)}`;
- break;
- case ZodError_1.ZodIssueCode.invalid_enum_value:
- message = `Invalid enum value. Expected ${util_1.util.joinValues(issue.options)}, received '${issue.received}'`;
- break;
- case ZodError_1.ZodIssueCode.invalid_arguments:
- message = `Invalid function arguments`;
- break;
- case ZodError_1.ZodIssueCode.invalid_return_type:
- message = `Invalid function return type`;
- break;
- case ZodError_1.ZodIssueCode.invalid_date:
- message = `Invalid date`;
- break;
- case ZodError_1.ZodIssueCode.invalid_string:
- if (typeof issue.validation === "object") {
- if ("includes" in issue.validation) {
- message = `Invalid input: must include "${issue.validation.includes}"`;
- if (typeof issue.validation.position === "number") {
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
- }
- }
- else if ("startsWith" in issue.validation) {
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
- }
- else if ("endsWith" in issue.validation) {
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
- }
- else {
- util_1.util.assertNever(issue.validation);
- }
- }
- else if (issue.validation !== "regex") {
- message = `Invalid ${issue.validation}`;
- }
- else {
- message = "Invalid";
- }
- break;
- case ZodError_1.ZodIssueCode.too_small:
- if (issue.type === "array")
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
- else if (issue.type === "string")
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
- else if (issue.type === "number")
- message = `Number must be ${issue.exact
- ? `exactly equal to `
- : issue.inclusive
- ? `greater than or equal to `
- : `greater than `}${issue.minimum}`;
- else if (issue.type === "date")
- message = `Date must be ${issue.exact
- ? `exactly equal to `
- : issue.inclusive
- ? `greater than or equal to `
- : `greater than `}${new Date(Number(issue.minimum))}`;
- else
- message = "Invalid input";
- break;
- case ZodError_1.ZodIssueCode.too_big:
- if (issue.type === "array")
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
- else if (issue.type === "string")
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
- else if (issue.type === "number")
- message = `Number must be ${issue.exact
- ? `exactly`
- : issue.inclusive
- ? `less than or equal to`
- : `less than`} ${issue.maximum}`;
- else if (issue.type === "bigint")
- message = `BigInt must be ${issue.exact
- ? `exactly`
- : issue.inclusive
- ? `less than or equal to`
- : `less than`} ${issue.maximum}`;
- else if (issue.type === "date")
- message = `Date must be ${issue.exact
- ? `exactly`
- : issue.inclusive
- ? `smaller than or equal to`
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
- else
- message = "Invalid input";
- break;
- case ZodError_1.ZodIssueCode.custom:
- message = `Invalid input`;
- break;
- case ZodError_1.ZodIssueCode.invalid_intersection_types:
- message = `Intersection results could not be merged`;
- break;
- case ZodError_1.ZodIssueCode.not_multiple_of:
- message = `Number must be a multiple of ${issue.multipleOf}`;
- break;
- case ZodError_1.ZodIssueCode.not_finite:
- message = "Number must be finite";
- break;
- default:
- message = _ctx.defaultError;
- util_1.util.assertNever(issue);
- }
- return { message };
- };
- en.default = errorMap;
- var __importDefault$1 = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(errors, "__esModule", { value: true });
- errors.getErrorMap = errors.setErrorMap = errors.defaultErrorMap = void 0;
- const en_1 = __importDefault$1(en);
- errors.defaultErrorMap = en_1.default;
- let overrideErrorMap = en_1.default;
- function setErrorMap(map) {
- overrideErrorMap = map;
- }
- errors.setErrorMap = setErrorMap;
- function getErrorMap() {
- return overrideErrorMap;
- }
- errors.getErrorMap = getErrorMap;
- var parseUtil = {};
- (function (exports) {
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
- const errors_1 = errors;
- const en_1 = __importDefault(en);
- const makeIssue = (params) => {
- const { data, path, errorMaps, issueData } = params;
- const fullPath = [...path, ...(issueData.path || [])];
- const fullIssue = {
- ...issueData,
- path: fullPath,
- };
- let errorMessage = "";
- const maps = errorMaps
- .filter((m) => !!m)
- .slice()
- .reverse();
- for (const map of maps) {
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
- }
- return {
- ...issueData,
- path: fullPath,
- message: issueData.message || errorMessage,
- };
- };
- exports.makeIssue = makeIssue;
- exports.EMPTY_PATH = [];
- function addIssueToContext(ctx, issueData) {
- const issue = (0, exports.makeIssue)({
- issueData: issueData,
- data: ctx.data,
- path: ctx.path,
- errorMaps: [
- ctx.common.contextualErrorMap,
- ctx.schemaErrorMap,
- (0, errors_1.getErrorMap)(),
- en_1.default, // then global default map
- ].filter((x) => !!x),
- });
- ctx.common.issues.push(issue);
- }
- exports.addIssueToContext = addIssueToContext;
- class ParseStatus {
- constructor() {
- this.value = "valid";
- }
- dirty() {
- if (this.value === "valid")
- this.value = "dirty";
- }
- abort() {
- if (this.value !== "aborted")
- this.value = "aborted";
- }
- static mergeArray(status, results) {
- const arrayValue = [];
- for (const s of results) {
- if (s.status === "aborted")
- return exports.INVALID;
- if (s.status === "dirty")
- status.dirty();
- arrayValue.push(s.value);
- }
- return { status: status.value, value: arrayValue };
- }
- static async mergeObjectAsync(status, pairs) {
- const syncPairs = [];
- for (const pair of pairs) {
- syncPairs.push({
- key: await pair.key,
- value: await pair.value,
- });
- }
- return ParseStatus.mergeObjectSync(status, syncPairs);
- }
- static mergeObjectSync(status, pairs) {
- const finalObject = {};
- for (const pair of pairs) {
- const { key, value } = pair;
- if (key.status === "aborted")
- return exports.INVALID;
- if (value.status === "aborted")
- return exports.INVALID;
- if (key.status === "dirty")
- status.dirty();
- if (value.status === "dirty")
- status.dirty();
- if (key.value !== "__proto__" &&
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
- finalObject[key.value] = value.value;
- }
- }
- return { status: status.value, value: finalObject };
- }
- }
- exports.ParseStatus = ParseStatus;
- exports.INVALID = Object.freeze({
- status: "aborted",
- });
- const DIRTY = (value) => ({ status: "dirty", value });
- exports.DIRTY = DIRTY;
- const OK = (value) => ({ status: "valid", value });
- exports.OK = OK;
- const isAborted = (x) => x.status === "aborted";
- exports.isAborted = isAborted;
- const isDirty = (x) => x.status === "dirty";
- exports.isDirty = isDirty;
- const isValid = (x) => x.status === "valid";
- exports.isValid = isValid;
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
- exports.isAsync = isAsync;
- } (parseUtil));
- var typeAliases = {};
- Object.defineProperty(typeAliases, "__esModule", { value: true });
- var types = {};
- var errorUtil = {};
- (function (exports) {
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.errorUtil = void 0;
- (function (errorUtil) {
- errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
- })(exports.errorUtil || (exports.errorUtil = {}));
- } (errorUtil));
- (function (exports) {
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.date = exports.boolean = exports.bigint = exports.array = exports.any = exports.coerce = exports.ZodFirstPartyTypeKind = exports.late = exports.ZodSchema = exports.Schema = exports.custom = exports.ZodReadonly = exports.ZodPipeline = exports.ZodBranded = exports.BRAND = exports.ZodNaN = exports.ZodCatch = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransformer = exports.ZodEffects = exports.ZodPromise = exports.ZodNativeEnum = exports.ZodEnum = exports.ZodLiteral = exports.ZodLazy = exports.ZodFunction = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodDate = exports.ZodBoolean = exports.ZodBigInt = exports.ZodNumber = exports.ZodString = exports.ZodType = void 0;
- exports.NEVER = exports.void = exports.unknown = exports.union = exports.undefined = exports.tuple = exports.transformer = exports.symbol = exports.string = exports.strictObject = exports.set = exports.record = exports.promise = exports.preprocess = exports.pipeline = exports.ostring = exports.optional = exports.onumber = exports.oboolean = exports.object = exports.number = exports.nullable = exports.null = exports.never = exports.nativeEnum = exports.nan = exports.map = exports.literal = exports.lazy = exports.intersection = exports.instanceof = exports.function = exports.enum = exports.effect = exports.discriminatedUnion = void 0;
- const errors_1 = errors;
- const errorUtil_1 = errorUtil;
- const parseUtil_1 = parseUtil;
- const util_1 = util;
- const ZodError_1 = ZodError$1;
- class ParseInputLazyPath {
- constructor(parent, value, path, key) {
- this._cachedPath = [];
- this.parent = parent;
- this.data = value;
- this._path = path;
- this._key = key;
- }
- get path() {
- if (!this._cachedPath.length) {
- if (this._key instanceof Array) {
- this._cachedPath.push(...this._path, ...this._key);
- }
- else {
- this._cachedPath.push(...this._path, this._key);
- }
- }
- return this._cachedPath;
- }
- }
- const handleResult = (ctx, result) => {
- if ((0, parseUtil_1.isValid)(result)) {
- return { success: true, data: result.value };
- }
- else {
- if (!ctx.common.issues.length) {
- throw new Error("Validation failed but no issues detected.");
- }
- return {
- success: false,
- get error() {
- if (this._error)
- return this._error;
- const error = new ZodError_1.ZodError(ctx.common.issues);
- this._error = error;
- return this._error;
- },
- };
- }
- };
- function processCreateParams(params) {
- if (!params)
- return {};
- const { errorMap, invalid_type_error, required_error, description } = params;
- if (errorMap && (invalid_type_error || required_error)) {
- throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
- }
- if (errorMap)
- return { errorMap: errorMap, description };
- const customMap = (iss, ctx) => {
- if (iss.code !== "invalid_type")
- return { message: ctx.defaultError };
- if (typeof ctx.data === "undefined") {
- return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError };
- }
- return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError };
- };
- return { errorMap: customMap, description };
- }
- class ZodType {
- constructor(def) {
- /** Alias of safeParseAsync */
- this.spa = this.safeParseAsync;
- this._def = def;
- this.parse = this.parse.bind(this);
- this.safeParse = this.safeParse.bind(this);
- this.parseAsync = this.parseAsync.bind(this);
- this.safeParseAsync = this.safeParseAsync.bind(this);
- this.spa = this.spa.bind(this);
- this.refine = this.refine.bind(this);
- this.refinement = this.refinement.bind(this);
- this.superRefine = this.superRefine.bind(this);
- this.optional = this.optional.bind(this);
- this.nullable = this.nullable.bind(this);
- this.nullish = this.nullish.bind(this);
- this.array = this.array.bind(this);
- this.promise = this.promise.bind(this);
- this.or = this.or.bind(this);
- this.and = this.and.bind(this);
- this.transform = this.transform.bind(this);
- this.brand = this.brand.bind(this);
- this.default = this.default.bind(this);
- this.catch = this.catch.bind(this);
- this.describe = this.describe.bind(this);
- this.pipe = this.pipe.bind(this);
- this.readonly = this.readonly.bind(this);
- this.isNullable = this.isNullable.bind(this);
- this.isOptional = this.isOptional.bind(this);
- }
- get description() {
- return this._def.description;
- }
- _getType(input) {
- return (0, util_1.getParsedType)(input.data);
- }
- _getOrReturnCtx(input, ctx) {
- return (ctx || {
- common: input.parent.common,
- data: input.data,
- parsedType: (0, util_1.getParsedType)(input.data),
- schemaErrorMap: this._def.errorMap,
- path: input.path,
- parent: input.parent,
- });
- }
- _processInputParams(input) {
- return {
- status: new parseUtil_1.ParseStatus(),
- ctx: {
- common: input.parent.common,
- data: input.data,
- parsedType: (0, util_1.getParsedType)(input.data),
- schemaErrorMap: this._def.errorMap,
- path: input.path,
- parent: input.parent,
- },
- };
- }
- _parseSync(input) {
- const result = this._parse(input);
- if ((0, parseUtil_1.isAsync)(result)) {
- throw new Error("Synchronous parse encountered promise.");
- }
- return result;
- }
- _parseAsync(input) {
- const result = this._parse(input);
- return Promise.resolve(result);
- }
- parse(data, params) {
- const result = this.safeParse(data, params);
- if (result.success)
- return result.data;
- throw result.error;
- }
- safeParse(data, params) {
- var _a;
- const ctx = {
- common: {
- issues: [],
- async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
- },
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
- schemaErrorMap: this._def.errorMap,
- parent: null,
- data,
- parsedType: (0, util_1.getParsedType)(data),
- };
- const result = this._parseSync({ data, path: ctx.path, parent: ctx });
- return handleResult(ctx, result);
- }
- async parseAsync(data, params) {
- const result = await this.safeParseAsync(data, params);
- if (result.success)
- return result.data;
- throw result.error;
- }
- async safeParseAsync(data, params) {
- const ctx = {
- common: {
- issues: [],
- contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
- async: true,
- },
- path: (params === null || params === void 0 ? void 0 : params.path) || [],
- schemaErrorMap: this._def.errorMap,
- parent: null,
- data,
- parsedType: (0, util_1.getParsedType)(data),
- };
- const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx });
- const result = await ((0, parseUtil_1.isAsync)(maybeAsyncResult)
- ? maybeAsyncResult
- : Promise.resolve(maybeAsyncResult));
- return handleResult(ctx, result);
- }
- refine(check, message) {
- const getIssueProperties = (val) => {
- if (typeof message === "string" || typeof message === "undefined") {
- return { message };
- }
- else if (typeof message === "function") {
- return message(val);
- }
- else {
- return message;
- }
- };
- return this._refinement((val, ctx) => {
- const result = check(val);
- const setError = () => ctx.addIssue({
- code: ZodError_1.ZodIssueCode.custom,
- ...getIssueProperties(val),
- });
- if (typeof Promise !== "undefined" && result instanceof Promise) {
- return result.then((data) => {
- if (!data) {
- setError();
- return false;
- }
- else {
- return true;
- }
- });
- }
- if (!result) {
- setError();
- return false;
- }
- else {
- return true;
- }
- });
- }
- refinement(check, refinementData) {
- return this._refinement((val, ctx) => {
- if (!check(val)) {
- ctx.addIssue(typeof refinementData === "function"
- ? refinementData(val, ctx)
- : refinementData);
- return false;
- }
- else {
- return true;
- }
- });
- }
- _refinement(refinement) {
- return new ZodEffects({
- schema: this,
- typeName: ZodFirstPartyTypeKind.ZodEffects,
- effect: { type: "refinement", refinement },
- });
- }
- superRefine(refinement) {
- return this._refinement(refinement);
- }
- optional() {
- return ZodOptional.create(this, this._def);
- }
- nullable() {
- return ZodNullable.create(this, this._def);
- }
- nullish() {
- return this.nullable().optional();
- }
- array() {
- return ZodArray.create(this, this._def);
- }
- promise() {
- return ZodPromise.create(this, this._def);
- }
- or(option) {
- return ZodUnion.create([this, option], this._def);
- }
- and(incoming) {
- return ZodIntersection.create(this, incoming, this._def);
- }
- transform(transform) {
- return new ZodEffects({
- ...processCreateParams(this._def),
- schema: this,
- typeName: ZodFirstPartyTypeKind.ZodEffects,
- effect: { type: "transform", transform },
- });
- }
- default(def) {
- const defaultValueFunc = typeof def === "function" ? def : () => def;
- return new ZodDefault({
- ...processCreateParams(this._def),
- innerType: this,
- defaultValue: defaultValueFunc,
- typeName: ZodFirstPartyTypeKind.ZodDefault,
- });
- }
- brand() {
- return new ZodBranded({
- typeName: ZodFirstPartyTypeKind.ZodBranded,
- type: this,
- ...processCreateParams(this._def),
- });
- }
- catch(def) {
- const catchValueFunc = typeof def === "function" ? def : () => def;
- return new ZodCatch({
- ...processCreateParams(this._def),
- innerType: this,
- catchValue: catchValueFunc,
- typeName: ZodFirstPartyTypeKind.ZodCatch,
- });
- }
- describe(description) {
- const This = this.constructor;
- return new This({
- ...this._def,
- description,
- });
- }
- pipe(target) {
- return ZodPipeline.create(this, target);
- }
- readonly() {
- return ZodReadonly.create(this);
- }
- isOptional() {
- return this.safeParse(undefined).success;
- }
- isNullable() {
- return this.safeParse(null).success;
- }
- }
- exports.ZodType = ZodType;
- exports.Schema = ZodType;
- exports.ZodSchema = ZodType;
- const cuidRegex = /^c[^\s-]{8,}$/i;
- const cuid2Regex = /^[a-z][a-z0-9]*$/;
- const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
- // const uuidRegex =
- // /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
- const uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
- // from https://stackoverflow.com/a/46181/1550155
- // old version: too slow, didn't support unicode
- // const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
- //old email regex
- // const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
- // eslint-disable-next-line
- // const emailRegex =
- // /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
- // const emailRegex =
- // /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
- // const emailRegex =
- // /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
- const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
- // const emailRegex =
- // /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
- // from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
- const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
- let emojiRegex;
- const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
- const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
- // Adapted from https://stackoverflow.com/a/3143231
- const datetimeRegex = (args) => {
- if (args.precision) {
- if (args.offset) {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
- }
- else {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
- }
- }
- else if (args.precision === 0) {
- if (args.offset) {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
- }
- else {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
- }
- }
- else {
- if (args.offset) {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
- }
- else {
- return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
- }
- }
- };
- function isValidIP(ip, version) {
- if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
- return true;
- }
- if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
- return true;
- }
- return false;
- }
- class ZodString extends ZodType {
- _parse(input) {
- if (this._def.coerce) {
- input.data = String(input.data);
- }
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.string) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.string,
- received: ctx.parsedType,
- }
- //
- );
- return parseUtil_1.INVALID;
- }
- const status = new parseUtil_1.ParseStatus();
- let ctx = undefined;
- for (const check of this._def.checks) {
- if (check.kind === "min") {
- if (input.data.length < check.value) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: check.value,
- type: "string",
- inclusive: true,
- exact: false,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "max") {
- if (input.data.length > check.value) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: check.value,
- type: "string",
- inclusive: true,
- exact: false,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "length") {
- const tooBig = input.data.length > check.value;
- const tooSmall = input.data.length < check.value;
- if (tooBig || tooSmall) {
- ctx = this._getOrReturnCtx(input, ctx);
- if (tooBig) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: check.value,
- type: "string",
- inclusive: true,
- exact: true,
- message: check.message,
- });
- }
- else if (tooSmall) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: check.value,
- type: "string",
- inclusive: true,
- exact: true,
- message: check.message,
- });
- }
- status.dirty();
- }
- }
- else if (check.kind === "email") {
- if (!emailRegex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "email",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "emoji") {
- if (!emojiRegex) {
- emojiRegex = new RegExp(_emojiRegex, "u");
- }
- if (!emojiRegex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "emoji",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "uuid") {
- if (!uuidRegex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "uuid",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "cuid") {
- if (!cuidRegex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "cuid",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "cuid2") {
- if (!cuid2Regex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "cuid2",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "ulid") {
- if (!ulidRegex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "ulid",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "url") {
- try {
- new URL(input.data);
- }
- catch (_a) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "url",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "regex") {
- check.regex.lastIndex = 0;
- const testResult = check.regex.test(input.data);
- if (!testResult) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "regex",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "trim") {
- input.data = input.data.trim();
- }
- else if (check.kind === "includes") {
- if (!input.data.includes(check.value, check.position)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_string,
- validation: { includes: check.value, position: check.position },
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "toLowerCase") {
- input.data = input.data.toLowerCase();
- }
- else if (check.kind === "toUpperCase") {
- input.data = input.data.toUpperCase();
- }
- else if (check.kind === "startsWith") {
- if (!input.data.startsWith(check.value)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_string,
- validation: { startsWith: check.value },
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "endsWith") {
- if (!input.data.endsWith(check.value)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_string,
- validation: { endsWith: check.value },
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "datetime") {
- const regex = datetimeRegex(check);
- if (!regex.test(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_string,
- validation: "datetime",
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "ip") {
- if (!isValidIP(input.data, check.version)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- validation: "ip",
- code: ZodError_1.ZodIssueCode.invalid_string,
- message: check.message,
- });
- status.dirty();
- }
- }
- else {
- util_1.util.assertNever(check);
- }
- }
- return { status: status.value, value: input.data };
- }
- _regex(regex, validation, message) {
- return this.refinement((data) => regex.test(data), {
- validation,
- code: ZodError_1.ZodIssueCode.invalid_string,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- _addCheck(check) {
- return new ZodString({
- ...this._def,
- checks: [...this._def.checks, check],
- });
- }
- email(message) {
- return this._addCheck({ kind: "email", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- url(message) {
- return this._addCheck({ kind: "url", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- emoji(message) {
- return this._addCheck({ kind: "emoji", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- uuid(message) {
- return this._addCheck({ kind: "uuid", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- cuid(message) {
- return this._addCheck({ kind: "cuid", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- cuid2(message) {
- return this._addCheck({ kind: "cuid2", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- ulid(message) {
- return this._addCheck({ kind: "ulid", ...errorUtil_1.errorUtil.errToObj(message) });
- }
- ip(options) {
- return this._addCheck({ kind: "ip", ...errorUtil_1.errorUtil.errToObj(options) });
- }
- datetime(options) {
- var _a;
- if (typeof options === "string") {
- return this._addCheck({
- kind: "datetime",
- precision: null,
- offset: false,
- message: options,
- });
- }
- return this._addCheck({
- kind: "datetime",
- precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
- offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
- ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
- });
- }
- regex(regex, message) {
- return this._addCheck({
- kind: "regex",
- regex: regex,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- includes(value, options) {
- return this._addCheck({
- kind: "includes",
- value: value,
- position: options === null || options === void 0 ? void 0 : options.position,
- ...errorUtil_1.errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message),
- });
- }
- startsWith(value, message) {
- return this._addCheck({
- kind: "startsWith",
- value: value,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- endsWith(value, message) {
- return this._addCheck({
- kind: "endsWith",
- value: value,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- min(minLength, message) {
- return this._addCheck({
- kind: "min",
- value: minLength,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- max(maxLength, message) {
- return this._addCheck({
- kind: "max",
- value: maxLength,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- length(len, message) {
- return this._addCheck({
- kind: "length",
- value: len,
- ...errorUtil_1.errorUtil.errToObj(message),
- });
- }
- /**
- * @deprecated Use z.string().min(1) instead.
- * @see {@link ZodString.min}
- */
- nonempty(message) {
- return this.min(1, errorUtil_1.errorUtil.errToObj(message));
- }
- trim() {
- return new ZodString({
- ...this._def,
- checks: [...this._def.checks, { kind: "trim" }],
- });
- }
- toLowerCase() {
- return new ZodString({
- ...this._def,
- checks: [...this._def.checks, { kind: "toLowerCase" }],
- });
- }
- toUpperCase() {
- return new ZodString({
- ...this._def,
- checks: [...this._def.checks, { kind: "toUpperCase" }],
- });
- }
- get isDatetime() {
- return !!this._def.checks.find((ch) => ch.kind === "datetime");
- }
- get isEmail() {
- return !!this._def.checks.find((ch) => ch.kind === "email");
- }
- get isURL() {
- return !!this._def.checks.find((ch) => ch.kind === "url");
- }
- get isEmoji() {
- return !!this._def.checks.find((ch) => ch.kind === "emoji");
- }
- get isUUID() {
- return !!this._def.checks.find((ch) => ch.kind === "uuid");
- }
- get isCUID() {
- return !!this._def.checks.find((ch) => ch.kind === "cuid");
- }
- get isCUID2() {
- return !!this._def.checks.find((ch) => ch.kind === "cuid2");
- }
- get isULID() {
- return !!this._def.checks.find((ch) => ch.kind === "ulid");
- }
- get isIP() {
- return !!this._def.checks.find((ch) => ch.kind === "ip");
- }
- get minLength() {
- let min = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "min") {
- if (min === null || ch.value > min)
- min = ch.value;
- }
- }
- return min;
- }
- get maxLength() {
- let max = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "max") {
- if (max === null || ch.value < max)
- max = ch.value;
- }
- }
- return max;
- }
- }
- exports.ZodString = ZodString;
- ZodString.create = (params) => {
- var _a;
- return new ZodString({
- checks: [],
- typeName: ZodFirstPartyTypeKind.ZodString,
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
- ...processCreateParams(params),
- });
- };
- // https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
- function floatSafeRemainder(val, step) {
- const valDecCount = (val.toString().split(".")[1] || "").length;
- const stepDecCount = (step.toString().split(".")[1] || "").length;
- const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
- const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
- const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
- return (valInt % stepInt) / Math.pow(10, decCount);
- }
- class ZodNumber extends ZodType {
- constructor() {
- super(...arguments);
- this.min = this.gte;
- this.max = this.lte;
- this.step = this.multipleOf;
- }
- _parse(input) {
- if (this._def.coerce) {
- input.data = Number(input.data);
- }
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.number) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.number,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- let ctx = undefined;
- const status = new parseUtil_1.ParseStatus();
- for (const check of this._def.checks) {
- if (check.kind === "int") {
- if (!util_1.util.isInteger(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: "integer",
- received: "float",
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "min") {
- const tooSmall = check.inclusive
- ? input.data < check.value
- : input.data <= check.value;
- if (tooSmall) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: check.value,
- type: "number",
- inclusive: check.inclusive,
- exact: false,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "max") {
- const tooBig = check.inclusive
- ? input.data > check.value
- : input.data >= check.value;
- if (tooBig) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: check.value,
- type: "number",
- inclusive: check.inclusive,
- exact: false,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "multipleOf") {
- if (floatSafeRemainder(input.data, check.value) !== 0) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.not_multiple_of,
- multipleOf: check.value,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "finite") {
- if (!Number.isFinite(input.data)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.not_finite,
- message: check.message,
- });
- status.dirty();
- }
- }
- else {
- util_1.util.assertNever(check);
- }
- }
- return { status: status.value, value: input.data };
- }
- gte(value, message) {
- return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
- }
- gt(value, message) {
- return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
- }
- lte(value, message) {
- return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
- }
- lt(value, message) {
- return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
- }
- setLimit(kind, value, inclusive, message) {
- return new ZodNumber({
- ...this._def,
- checks: [
- ...this._def.checks,
- {
- kind,
- value,
- inclusive,
- message: errorUtil_1.errorUtil.toString(message),
- },
- ],
- });
- }
- _addCheck(check) {
- return new ZodNumber({
- ...this._def,
- checks: [...this._def.checks, check],
- });
- }
- int(message) {
- return this._addCheck({
- kind: "int",
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- positive(message) {
- return this._addCheck({
- kind: "min",
- value: 0,
- inclusive: false,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- negative(message) {
- return this._addCheck({
- kind: "max",
- value: 0,
- inclusive: false,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- nonpositive(message) {
- return this._addCheck({
- kind: "max",
- value: 0,
- inclusive: true,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- nonnegative(message) {
- return this._addCheck({
- kind: "min",
- value: 0,
- inclusive: true,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- multipleOf(value, message) {
- return this._addCheck({
- kind: "multipleOf",
- value: value,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- finite(message) {
- return this._addCheck({
- kind: "finite",
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- safe(message) {
- return this._addCheck({
- kind: "min",
- inclusive: true,
- value: Number.MIN_SAFE_INTEGER,
- message: errorUtil_1.errorUtil.toString(message),
- })._addCheck({
- kind: "max",
- inclusive: true,
- value: Number.MAX_SAFE_INTEGER,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- get minValue() {
- let min = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "min") {
- if (min === null || ch.value > min)
- min = ch.value;
- }
- }
- return min;
- }
- get maxValue() {
- let max = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "max") {
- if (max === null || ch.value < max)
- max = ch.value;
- }
- }
- return max;
- }
- get isInt() {
- return !!this._def.checks.find((ch) => ch.kind === "int" ||
- (ch.kind === "multipleOf" && util_1.util.isInteger(ch.value)));
- }
- get isFinite() {
- let max = null, min = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "finite" ||
- ch.kind === "int" ||
- ch.kind === "multipleOf") {
- return true;
- }
- else if (ch.kind === "min") {
- if (min === null || ch.value > min)
- min = ch.value;
- }
- else if (ch.kind === "max") {
- if (max === null || ch.value < max)
- max = ch.value;
- }
- }
- return Number.isFinite(min) && Number.isFinite(max);
- }
- }
- exports.ZodNumber = ZodNumber;
- ZodNumber.create = (params) => {
- return new ZodNumber({
- checks: [],
- typeName: ZodFirstPartyTypeKind.ZodNumber,
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
- ...processCreateParams(params),
- });
- };
- class ZodBigInt extends ZodType {
- constructor() {
- super(...arguments);
- this.min = this.gte;
- this.max = this.lte;
- }
- _parse(input) {
- if (this._def.coerce) {
- input.data = BigInt(input.data);
- }
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.bigint) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.bigint,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- let ctx = undefined;
- const status = new parseUtil_1.ParseStatus();
- for (const check of this._def.checks) {
- if (check.kind === "min") {
- const tooSmall = check.inclusive
- ? input.data < check.value
- : input.data <= check.value;
- if (tooSmall) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- type: "bigint",
- minimum: check.value,
- inclusive: check.inclusive,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "max") {
- const tooBig = check.inclusive
- ? input.data > check.value
- : input.data >= check.value;
- if (tooBig) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- type: "bigint",
- maximum: check.value,
- inclusive: check.inclusive,
- message: check.message,
- });
- status.dirty();
- }
- }
- else if (check.kind === "multipleOf") {
- if (input.data % check.value !== BigInt(0)) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.not_multiple_of,
- multipleOf: check.value,
- message: check.message,
- });
- status.dirty();
- }
- }
- else {
- util_1.util.assertNever(check);
- }
- }
- return { status: status.value, value: input.data };
- }
- gte(value, message) {
- return this.setLimit("min", value, true, errorUtil_1.errorUtil.toString(message));
- }
- gt(value, message) {
- return this.setLimit("min", value, false, errorUtil_1.errorUtil.toString(message));
- }
- lte(value, message) {
- return this.setLimit("max", value, true, errorUtil_1.errorUtil.toString(message));
- }
- lt(value, message) {
- return this.setLimit("max", value, false, errorUtil_1.errorUtil.toString(message));
- }
- setLimit(kind, value, inclusive, message) {
- return new ZodBigInt({
- ...this._def,
- checks: [
- ...this._def.checks,
- {
- kind,
- value,
- inclusive,
- message: errorUtil_1.errorUtil.toString(message),
- },
- ],
- });
- }
- _addCheck(check) {
- return new ZodBigInt({
- ...this._def,
- checks: [...this._def.checks, check],
- });
- }
- positive(message) {
- return this._addCheck({
- kind: "min",
- value: BigInt(0),
- inclusive: false,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- negative(message) {
- return this._addCheck({
- kind: "max",
- value: BigInt(0),
- inclusive: false,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- nonpositive(message) {
- return this._addCheck({
- kind: "max",
- value: BigInt(0),
- inclusive: true,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- nonnegative(message) {
- return this._addCheck({
- kind: "min",
- value: BigInt(0),
- inclusive: true,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- multipleOf(value, message) {
- return this._addCheck({
- kind: "multipleOf",
- value,
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- get minValue() {
- let min = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "min") {
- if (min === null || ch.value > min)
- min = ch.value;
- }
- }
- return min;
- }
- get maxValue() {
- let max = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "max") {
- if (max === null || ch.value < max)
- max = ch.value;
- }
- }
- return max;
- }
- }
- exports.ZodBigInt = ZodBigInt;
- ZodBigInt.create = (params) => {
- var _a;
- return new ZodBigInt({
- checks: [],
- typeName: ZodFirstPartyTypeKind.ZodBigInt,
- coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
- ...processCreateParams(params),
- });
- };
- class ZodBoolean extends ZodType {
- _parse(input) {
- if (this._def.coerce) {
- input.data = Boolean(input.data);
- }
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.boolean) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.boolean,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodBoolean = ZodBoolean;
- ZodBoolean.create = (params) => {
- return new ZodBoolean({
- typeName: ZodFirstPartyTypeKind.ZodBoolean,
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
- ...processCreateParams(params),
- });
- };
- class ZodDate extends ZodType {
- _parse(input) {
- if (this._def.coerce) {
- input.data = new Date(input.data);
- }
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.date) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.date,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- if (isNaN(input.data.getTime())) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_date,
- });
- return parseUtil_1.INVALID;
- }
- const status = new parseUtil_1.ParseStatus();
- let ctx = undefined;
- for (const check of this._def.checks) {
- if (check.kind === "min") {
- if (input.data.getTime() < check.value) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- message: check.message,
- inclusive: true,
- exact: false,
- minimum: check.value,
- type: "date",
- });
- status.dirty();
- }
- }
- else if (check.kind === "max") {
- if (input.data.getTime() > check.value) {
- ctx = this._getOrReturnCtx(input, ctx);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- message: check.message,
- inclusive: true,
- exact: false,
- maximum: check.value,
- type: "date",
- });
- status.dirty();
- }
- }
- else {
- util_1.util.assertNever(check);
- }
- }
- return {
- status: status.value,
- value: new Date(input.data.getTime()),
- };
- }
- _addCheck(check) {
- return new ZodDate({
- ...this._def,
- checks: [...this._def.checks, check],
- });
- }
- min(minDate, message) {
- return this._addCheck({
- kind: "min",
- value: minDate.getTime(),
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- max(maxDate, message) {
- return this._addCheck({
- kind: "max",
- value: maxDate.getTime(),
- message: errorUtil_1.errorUtil.toString(message),
- });
- }
- get minDate() {
- let min = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "min") {
- if (min === null || ch.value > min)
- min = ch.value;
- }
- }
- return min != null ? new Date(min) : null;
- }
- get maxDate() {
- let max = null;
- for (const ch of this._def.checks) {
- if (ch.kind === "max") {
- if (max === null || ch.value < max)
- max = ch.value;
- }
- }
- return max != null ? new Date(max) : null;
- }
- }
- exports.ZodDate = ZodDate;
- ZodDate.create = (params) => {
- return new ZodDate({
- checks: [],
- coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
- typeName: ZodFirstPartyTypeKind.ZodDate,
- ...processCreateParams(params),
- });
- };
- class ZodSymbol extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.symbol) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.symbol,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodSymbol = ZodSymbol;
- ZodSymbol.create = (params) => {
- return new ZodSymbol({
- typeName: ZodFirstPartyTypeKind.ZodSymbol,
- ...processCreateParams(params),
- });
- };
- class ZodUndefined extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.undefined) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.undefined,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodUndefined = ZodUndefined;
- ZodUndefined.create = (params) => {
- return new ZodUndefined({
- typeName: ZodFirstPartyTypeKind.ZodUndefined,
- ...processCreateParams(params),
- });
- };
- class ZodNull extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.null) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.null,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodNull = ZodNull;
- ZodNull.create = (params) => {
- return new ZodNull({
- typeName: ZodFirstPartyTypeKind.ZodNull,
- ...processCreateParams(params),
- });
- };
- class ZodAny extends ZodType {
- constructor() {
- super(...arguments);
- // to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
- this._any = true;
- }
- _parse(input) {
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodAny = ZodAny;
- ZodAny.create = (params) => {
- return new ZodAny({
- typeName: ZodFirstPartyTypeKind.ZodAny,
- ...processCreateParams(params),
- });
- };
- class ZodUnknown extends ZodType {
- constructor() {
- super(...arguments);
- // required
- this._unknown = true;
- }
- _parse(input) {
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodUnknown = ZodUnknown;
- ZodUnknown.create = (params) => {
- return new ZodUnknown({
- typeName: ZodFirstPartyTypeKind.ZodUnknown,
- ...processCreateParams(params),
- });
- };
- class ZodNever extends ZodType {
- _parse(input) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.never,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- }
- exports.ZodNever = ZodNever;
- ZodNever.create = (params) => {
- return new ZodNever({
- typeName: ZodFirstPartyTypeKind.ZodNever,
- ...processCreateParams(params),
- });
- };
- class ZodVoid extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.undefined) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.void,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- }
- exports.ZodVoid = ZodVoid;
- ZodVoid.create = (params) => {
- return new ZodVoid({
- typeName: ZodFirstPartyTypeKind.ZodVoid,
- ...processCreateParams(params),
- });
- };
- class ZodArray extends ZodType {
- _parse(input) {
- const { ctx, status } = this._processInputParams(input);
- const def = this._def;
- if (ctx.parsedType !== util_1.ZodParsedType.array) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.array,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- if (def.exactLength !== null) {
- const tooBig = ctx.data.length > def.exactLength.value;
- const tooSmall = ctx.data.length < def.exactLength.value;
- if (tooBig || tooSmall) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: tooBig ? ZodError_1.ZodIssueCode.too_big : ZodError_1.ZodIssueCode.too_small,
- minimum: (tooSmall ? def.exactLength.value : undefined),
- maximum: (tooBig ? def.exactLength.value : undefined),
- type: "array",
- inclusive: true,
- exact: true,
- message: def.exactLength.message,
- });
- status.dirty();
- }
- }
- if (def.minLength !== null) {
- if (ctx.data.length < def.minLength.value) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: def.minLength.value,
- type: "array",
- inclusive: true,
- exact: false,
- message: def.minLength.message,
- });
- status.dirty();
- }
- }
- if (def.maxLength !== null) {
- if (ctx.data.length > def.maxLength.value) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: def.maxLength.value,
- type: "array",
- inclusive: true,
- exact: false,
- message: def.maxLength.message,
- });
- status.dirty();
- }
- }
- if (ctx.common.async) {
- return Promise.all([...ctx.data].map((item, i) => {
- return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
- })).then((result) => {
- return parseUtil_1.ParseStatus.mergeArray(status, result);
- });
- }
- const result = [...ctx.data].map((item, i) => {
- return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
- });
- return parseUtil_1.ParseStatus.mergeArray(status, result);
- }
- get element() {
- return this._def.type;
- }
- min(minLength, message) {
- return new ZodArray({
- ...this._def,
- minLength: { value: minLength, message: errorUtil_1.errorUtil.toString(message) },
- });
- }
- max(maxLength, message) {
- return new ZodArray({
- ...this._def,
- maxLength: { value: maxLength, message: errorUtil_1.errorUtil.toString(message) },
- });
- }
- length(len, message) {
- return new ZodArray({
- ...this._def,
- exactLength: { value: len, message: errorUtil_1.errorUtil.toString(message) },
- });
- }
- nonempty(message) {
- return this.min(1, message);
- }
- }
- exports.ZodArray = ZodArray;
- ZodArray.create = (schema, params) => {
- return new ZodArray({
- type: schema,
- minLength: null,
- maxLength: null,
- exactLength: null,
- typeName: ZodFirstPartyTypeKind.ZodArray,
- ...processCreateParams(params),
- });
- };
- function deepPartialify(schema) {
- if (schema instanceof ZodObject) {
- const newShape = {};
- for (const key in schema.shape) {
- const fieldSchema = schema.shape[key];
- newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
- }
- return new ZodObject({
- ...schema._def,
- shape: () => newShape,
- });
- }
- else if (schema instanceof ZodArray) {
- return new ZodArray({
- ...schema._def,
- type: deepPartialify(schema.element),
- });
- }
- else if (schema instanceof ZodOptional) {
- return ZodOptional.create(deepPartialify(schema.unwrap()));
- }
- else if (schema instanceof ZodNullable) {
- return ZodNullable.create(deepPartialify(schema.unwrap()));
- }
- else if (schema instanceof ZodTuple) {
- return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
- }
- else {
- return schema;
- }
- }
- class ZodObject extends ZodType {
- constructor() {
- super(...arguments);
- this._cached = null;
- /**
- * @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
- * If you want to pass through unknown properties, use `.passthrough()` instead.
- */
- this.nonstrict = this.passthrough;
- // extend<
- // Augmentation extends ZodRawShape,
- // NewOutput extends util.flatten<{
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
- // ? Augmentation[k]["_output"]
- // : k extends keyof Output
- // ? Output[k]
- // : never;
- // }>,
- // NewInput extends util.flatten<{
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
- // ? Augmentation[k]["_input"]
- // : k extends keyof Input
- // ? Input[k]
- // : never;
- // }>
- // >(
- // augmentation: Augmentation
- // ): ZodObject<
- // extendShape<T, Augmentation>,
- // UnknownKeys,
- // Catchall,
- // NewOutput,
- // NewInput
- // > {
- // return new ZodObject({
- // ...this._def,
- // shape: () => ({
- // ...this._def.shape(),
- // ...augmentation,
- // }),
- // }) as any;
- // }
- /**
- * @deprecated Use `.extend` instead
- * */
- this.augment = this.extend;
- }
- _getCached() {
- if (this._cached !== null)
- return this._cached;
- const shape = this._def.shape();
- const keys = util_1.util.objectKeys(shape);
- return (this._cached = { shape, keys });
- }
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.object) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.object,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const { status, ctx } = this._processInputParams(input);
- const { shape, keys: shapeKeys } = this._getCached();
- const extraKeys = [];
- if (!(this._def.catchall instanceof ZodNever &&
- this._def.unknownKeys === "strip")) {
- for (const key in ctx.data) {
- if (!shapeKeys.includes(key)) {
- extraKeys.push(key);
- }
- }
- }
- const pairs = [];
- for (const key of shapeKeys) {
- const keyValidator = shape[key];
- const value = ctx.data[key];
- pairs.push({
- key: { status: "valid", value: key },
- value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
- alwaysSet: key in ctx.data,
- });
- }
- if (this._def.catchall instanceof ZodNever) {
- const unknownKeys = this._def.unknownKeys;
- if (unknownKeys === "passthrough") {
- for (const key of extraKeys) {
- pairs.push({
- key: { status: "valid", value: key },
- value: { status: "valid", value: ctx.data[key] },
- });
- }
- }
- else if (unknownKeys === "strict") {
- if (extraKeys.length > 0) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.unrecognized_keys,
- keys: extraKeys,
- });
- status.dirty();
- }
- }
- else if (unknownKeys === "strip") ;
- else {
- throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
- }
- }
- else {
- // run catchall validation
- const catchall = this._def.catchall;
- for (const key of extraKeys) {
- const value = ctx.data[key];
- pairs.push({
- key: { status: "valid", value: key },
- value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
- ),
- alwaysSet: key in ctx.data,
- });
- }
- }
- if (ctx.common.async) {
- return Promise.resolve()
- .then(async () => {
- const syncPairs = [];
- for (const pair of pairs) {
- const key = await pair.key;
- syncPairs.push({
- key,
- value: await pair.value,
- alwaysSet: pair.alwaysSet,
- });
- }
- return syncPairs;
- })
- .then((syncPairs) => {
- return parseUtil_1.ParseStatus.mergeObjectSync(status, syncPairs);
- });
- }
- else {
- return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
- }
- }
- get shape() {
- return this._def.shape();
- }
- strict(message) {
- errorUtil_1.errorUtil.errToObj;
- return new ZodObject({
- ...this._def,
- unknownKeys: "strict",
- ...(message !== undefined
- ? {
- errorMap: (issue, ctx) => {
- var _a, _b, _c, _d;
- const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
- if (issue.code === "unrecognized_keys")
- return {
- message: (_d = errorUtil_1.errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError,
- };
- return {
- message: defaultError,
- };
- },
- }
- : {}),
- });
- }
- strip() {
- return new ZodObject({
- ...this._def,
- unknownKeys: "strip",
- });
- }
- passthrough() {
- return new ZodObject({
- ...this._def,
- unknownKeys: "passthrough",
- });
- }
- // const AugmentFactory =
- // <Def extends ZodObjectDef>(def: Def) =>
- // <Augmentation extends ZodRawShape>(
- // augmentation: Augmentation
- // ): ZodObject<
- // extendShape<ReturnType<Def["shape"]>, Augmentation>,
- // Def["unknownKeys"],
- // Def["catchall"]
- // > => {
- // return new ZodObject({
- // ...def,
- // shape: () => ({
- // ...def.shape(),
- // ...augmentation,
- // }),
- // }) as any;
- // };
- extend(augmentation) {
- return new ZodObject({
- ...this._def,
- shape: () => ({
- ...this._def.shape(),
- ...augmentation,
- }),
- });
- }
- /**
- * Prior to zod@1.0.12 there was a bug in the
- * inferred type of merged objects. Please
- * upgrade if you are experiencing issues.
- */
- merge(merging) {
- const merged = new ZodObject({
- unknownKeys: merging._def.unknownKeys,
- catchall: merging._def.catchall,
- shape: () => ({
- ...this._def.shape(),
- ...merging._def.shape(),
- }),
- typeName: ZodFirstPartyTypeKind.ZodObject,
- });
- return merged;
- }
- // merge<
- // Incoming extends AnyZodObject,
- // Augmentation extends Incoming["shape"],
- // NewOutput extends {
- // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
- // ? Augmentation[k]["_output"]
- // : k extends keyof Output
- // ? Output[k]
- // : never;
- // },
- // NewInput extends {
- // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
- // ? Augmentation[k]["_input"]
- // : k extends keyof Input
- // ? Input[k]
- // : never;
- // }
- // >(
- // merging: Incoming
- // ): ZodObject<
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
- // Incoming["_def"]["unknownKeys"],
- // Incoming["_def"]["catchall"],
- // NewOutput,
- // NewInput
- // > {
- // const merged: any = new ZodObject({
- // unknownKeys: merging._def.unknownKeys,
- // catchall: merging._def.catchall,
- // shape: () =>
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
- // typeName: ZodFirstPartyTypeKind.ZodObject,
- // }) as any;
- // return merged;
- // }
- setKey(key, schema) {
- return this.augment({ [key]: schema });
- }
- // merge<Incoming extends AnyZodObject>(
- // merging: Incoming
- // ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
- // ZodObject<
- // extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
- // Incoming["_def"]["unknownKeys"],
- // Incoming["_def"]["catchall"]
- // > {
- // // const mergedShape = objectUtil.mergeShapes(
- // // this._def.shape(),
- // // merging._def.shape()
- // // );
- // const merged: any = new ZodObject({
- // unknownKeys: merging._def.unknownKeys,
- // catchall: merging._def.catchall,
- // shape: () =>
- // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
- // typeName: ZodFirstPartyTypeKind.ZodObject,
- // }) as any;
- // return merged;
- // }
- catchall(index) {
- return new ZodObject({
- ...this._def,
- catchall: index,
- });
- }
- pick(mask) {
- const shape = {};
- util_1.util.objectKeys(mask).forEach((key) => {
- if (mask[key] && this.shape[key]) {
- shape[key] = this.shape[key];
- }
- });
- return new ZodObject({
- ...this._def,
- shape: () => shape,
- });
- }
- omit(mask) {
- const shape = {};
- util_1.util.objectKeys(this.shape).forEach((key) => {
- if (!mask[key]) {
- shape[key] = this.shape[key];
- }
- });
- return new ZodObject({
- ...this._def,
- shape: () => shape,
- });
- }
- /**
- * @deprecated
- */
- deepPartial() {
- return deepPartialify(this);
- }
- partial(mask) {
- const newShape = {};
- util_1.util.objectKeys(this.shape).forEach((key) => {
- const fieldSchema = this.shape[key];
- if (mask && !mask[key]) {
- newShape[key] = fieldSchema;
- }
- else {
- newShape[key] = fieldSchema.optional();
- }
- });
- return new ZodObject({
- ...this._def,
- shape: () => newShape,
- });
- }
- required(mask) {
- const newShape = {};
- util_1.util.objectKeys(this.shape).forEach((key) => {
- if (mask && !mask[key]) {
- newShape[key] = this.shape[key];
- }
- else {
- const fieldSchema = this.shape[key];
- let newField = fieldSchema;
- while (newField instanceof ZodOptional) {
- newField = newField._def.innerType;
- }
- newShape[key] = newField;
- }
- });
- return new ZodObject({
- ...this._def,
- shape: () => newShape,
- });
- }
- keyof() {
- return createZodEnum(util_1.util.objectKeys(this.shape));
- }
- }
- exports.ZodObject = ZodObject;
- ZodObject.create = (shape, params) => {
- return new ZodObject({
- shape: () => shape,
- unknownKeys: "strip",
- catchall: ZodNever.create(),
- typeName: ZodFirstPartyTypeKind.ZodObject,
- ...processCreateParams(params),
- });
- };
- ZodObject.strictCreate = (shape, params) => {
- return new ZodObject({
- shape: () => shape,
- unknownKeys: "strict",
- catchall: ZodNever.create(),
- typeName: ZodFirstPartyTypeKind.ZodObject,
- ...processCreateParams(params),
- });
- };
- ZodObject.lazycreate = (shape, params) => {
- return new ZodObject({
- shape,
- unknownKeys: "strip",
- catchall: ZodNever.create(),
- typeName: ZodFirstPartyTypeKind.ZodObject,
- ...processCreateParams(params),
- });
- };
- class ZodUnion extends ZodType {
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- const options = this._def.options;
- function handleResults(results) {
- // return first issue-free validation if it exists
- for (const result of results) {
- if (result.result.status === "valid") {
- return result.result;
- }
- }
- for (const result of results) {
- if (result.result.status === "dirty") {
- // add issues from dirty option
- ctx.common.issues.push(...result.ctx.common.issues);
- return result.result;
- }
- }
- // return invalid
- const unionErrors = results.map((result) => new ZodError_1.ZodError(result.ctx.common.issues));
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_union,
- unionErrors,
- });
- return parseUtil_1.INVALID;
- }
- if (ctx.common.async) {
- return Promise.all(options.map(async (option) => {
- const childCtx = {
- ...ctx,
- common: {
- ...ctx.common,
- issues: [],
- },
- parent: null,
- };
- return {
- result: await option._parseAsync({
- data: ctx.data,
- path: ctx.path,
- parent: childCtx,
- }),
- ctx: childCtx,
- };
- })).then(handleResults);
- }
- else {
- let dirty = undefined;
- const issues = [];
- for (const option of options) {
- const childCtx = {
- ...ctx,
- common: {
- ...ctx.common,
- issues: [],
- },
- parent: null,
- };
- const result = option._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: childCtx,
- });
- if (result.status === "valid") {
- return result;
- }
- else if (result.status === "dirty" && !dirty) {
- dirty = { result, ctx: childCtx };
- }
- if (childCtx.common.issues.length) {
- issues.push(childCtx.common.issues);
- }
- }
- if (dirty) {
- ctx.common.issues.push(...dirty.ctx.common.issues);
- return dirty.result;
- }
- const unionErrors = issues.map((issues) => new ZodError_1.ZodError(issues));
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_union,
- unionErrors,
- });
- return parseUtil_1.INVALID;
- }
- }
- get options() {
- return this._def.options;
- }
- }
- exports.ZodUnion = ZodUnion;
- ZodUnion.create = (types, params) => {
- return new ZodUnion({
- options: types,
- typeName: ZodFirstPartyTypeKind.ZodUnion,
- ...processCreateParams(params),
- });
- };
- /////////////////////////////////////////////////////
- /////////////////////////////////////////////////////
- ////////// //////////
- ////////// ZodDiscriminatedUnion //////////
- ////////// //////////
- /////////////////////////////////////////////////////
- /////////////////////////////////////////////////////
- const getDiscriminator = (type) => {
- if (type instanceof ZodLazy) {
- return getDiscriminator(type.schema);
- }
- else if (type instanceof ZodEffects) {
- return getDiscriminator(type.innerType());
- }
- else if (type instanceof ZodLiteral) {
- return [type.value];
- }
- else if (type instanceof ZodEnum) {
- return type.options;
- }
- else if (type instanceof ZodNativeEnum) {
- // eslint-disable-next-line ban/ban
- return Object.keys(type.enum);
- }
- else if (type instanceof ZodDefault) {
- return getDiscriminator(type._def.innerType);
- }
- else if (type instanceof ZodUndefined) {
- return [undefined];
- }
- else if (type instanceof ZodNull) {
- return [null];
- }
- else {
- return null;
- }
- };
- class ZodDiscriminatedUnion extends ZodType {
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.object) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.object,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const discriminator = this.discriminator;
- const discriminatorValue = ctx.data[discriminator];
- const option = this.optionsMap.get(discriminatorValue);
- if (!option) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_union_discriminator,
- options: Array.from(this.optionsMap.keys()),
- path: [discriminator],
- });
- return parseUtil_1.INVALID;
- }
- if (ctx.common.async) {
- return option._parseAsync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- }
- else {
- return option._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- }
- }
- get discriminator() {
- return this._def.discriminator;
- }
- get options() {
- return this._def.options;
- }
- get optionsMap() {
- return this._def.optionsMap;
- }
- /**
- * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
- * However, it only allows a union of objects, all of which need to share a discriminator property. This property must
- * have a different value for each object in the union.
- * @param discriminator the name of the discriminator property
- * @param types an array of object schemas
- * @param params
- */
- static create(discriminator, options, params) {
- // Get all the valid discriminator values
- const optionsMap = new Map();
- // try {
- for (const type of options) {
- const discriminatorValues = getDiscriminator(type.shape[discriminator]);
- if (!discriminatorValues) {
- throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
- }
- for (const value of discriminatorValues) {
- if (optionsMap.has(value)) {
- throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
- }
- optionsMap.set(value, type);
- }
- }
- return new ZodDiscriminatedUnion({
- typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
- discriminator,
- options,
- optionsMap,
- ...processCreateParams(params),
- });
- }
- }
- exports.ZodDiscriminatedUnion = ZodDiscriminatedUnion;
- function mergeValues(a, b) {
- const aType = (0, util_1.getParsedType)(a);
- const bType = (0, util_1.getParsedType)(b);
- if (a === b) {
- return { valid: true, data: a };
- }
- else if (aType === util_1.ZodParsedType.object && bType === util_1.ZodParsedType.object) {
- const bKeys = util_1.util.objectKeys(b);
- const sharedKeys = util_1.util
- .objectKeys(a)
- .filter((key) => bKeys.indexOf(key) !== -1);
- const newObj = { ...a, ...b };
- for (const key of sharedKeys) {
- const sharedValue = mergeValues(a[key], b[key]);
- if (!sharedValue.valid) {
- return { valid: false };
- }
- newObj[key] = sharedValue.data;
- }
- return { valid: true, data: newObj };
- }
- else if (aType === util_1.ZodParsedType.array && bType === util_1.ZodParsedType.array) {
- if (a.length !== b.length) {
- return { valid: false };
- }
- const newArray = [];
- for (let index = 0; index < a.length; index++) {
- const itemA = a[index];
- const itemB = b[index];
- const sharedValue = mergeValues(itemA, itemB);
- if (!sharedValue.valid) {
- return { valid: false };
- }
- newArray.push(sharedValue.data);
- }
- return { valid: true, data: newArray };
- }
- else if (aType === util_1.ZodParsedType.date &&
- bType === util_1.ZodParsedType.date &&
- +a === +b) {
- return { valid: true, data: a };
- }
- else {
- return { valid: false };
- }
- }
- class ZodIntersection extends ZodType {
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- const handleParsed = (parsedLeft, parsedRight) => {
- if ((0, parseUtil_1.isAborted)(parsedLeft) || (0, parseUtil_1.isAborted)(parsedRight)) {
- return parseUtil_1.INVALID;
- }
- const merged = mergeValues(parsedLeft.value, parsedRight.value);
- if (!merged.valid) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_intersection_types,
- });
- return parseUtil_1.INVALID;
- }
- if ((0, parseUtil_1.isDirty)(parsedLeft) || (0, parseUtil_1.isDirty)(parsedRight)) {
- status.dirty();
- }
- return { status: status.value, value: merged.data };
- };
- if (ctx.common.async) {
- return Promise.all([
- this._def.left._parseAsync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- }),
- this._def.right._parseAsync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- }),
- ]).then(([left, right]) => handleParsed(left, right));
- }
- else {
- return handleParsed(this._def.left._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- }), this._def.right._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- }));
- }
- }
- }
- exports.ZodIntersection = ZodIntersection;
- ZodIntersection.create = (left, right, params) => {
- return new ZodIntersection({
- left: left,
- right: right,
- typeName: ZodFirstPartyTypeKind.ZodIntersection,
- ...processCreateParams(params),
- });
- };
- class ZodTuple extends ZodType {
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.array) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.array,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- if (ctx.data.length < this._def.items.length) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: this._def.items.length,
- inclusive: true,
- exact: false,
- type: "array",
- });
- return parseUtil_1.INVALID;
- }
- const rest = this._def.rest;
- if (!rest && ctx.data.length > this._def.items.length) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: this._def.items.length,
- inclusive: true,
- exact: false,
- type: "array",
- });
- status.dirty();
- }
- const items = [...ctx.data]
- .map((item, itemIndex) => {
- const schema = this._def.items[itemIndex] || this._def.rest;
- if (!schema)
- return null;
- return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
- })
- .filter((x) => !!x); // filter nulls
- if (ctx.common.async) {
- return Promise.all(items).then((results) => {
- return parseUtil_1.ParseStatus.mergeArray(status, results);
- });
- }
- else {
- return parseUtil_1.ParseStatus.mergeArray(status, items);
- }
- }
- get items() {
- return this._def.items;
- }
- rest(rest) {
- return new ZodTuple({
- ...this._def,
- rest,
- });
- }
- }
- exports.ZodTuple = ZodTuple;
- ZodTuple.create = (schemas, params) => {
- if (!Array.isArray(schemas)) {
- throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
- }
- return new ZodTuple({
- items: schemas,
- typeName: ZodFirstPartyTypeKind.ZodTuple,
- rest: null,
- ...processCreateParams(params),
- });
- };
- class ZodRecord extends ZodType {
- get keySchema() {
- return this._def.keyType;
- }
- get valueSchema() {
- return this._def.valueType;
- }
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.object) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.object,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const pairs = [];
- const keyType = this._def.keyType;
- const valueType = this._def.valueType;
- for (const key in ctx.data) {
- pairs.push({
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
- value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
- });
- }
- if (ctx.common.async) {
- return parseUtil_1.ParseStatus.mergeObjectAsync(status, pairs);
- }
- else {
- return parseUtil_1.ParseStatus.mergeObjectSync(status, pairs);
- }
- }
- get element() {
- return this._def.valueType;
- }
- static create(first, second, third) {
- if (second instanceof ZodType) {
- return new ZodRecord({
- keyType: first,
- valueType: second,
- typeName: ZodFirstPartyTypeKind.ZodRecord,
- ...processCreateParams(third),
- });
- }
- return new ZodRecord({
- keyType: ZodString.create(),
- valueType: first,
- typeName: ZodFirstPartyTypeKind.ZodRecord,
- ...processCreateParams(second),
- });
- }
- }
- exports.ZodRecord = ZodRecord;
- class ZodMap extends ZodType {
- get keySchema() {
- return this._def.keyType;
- }
- get valueSchema() {
- return this._def.valueType;
- }
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.map) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.map,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const keyType = this._def.keyType;
- const valueType = this._def.valueType;
- const pairs = [...ctx.data.entries()].map(([key, value], index) => {
- return {
- key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
- value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"])),
- };
- });
- if (ctx.common.async) {
- const finalMap = new Map();
- return Promise.resolve().then(async () => {
- for (const pair of pairs) {
- const key = await pair.key;
- const value = await pair.value;
- if (key.status === "aborted" || value.status === "aborted") {
- return parseUtil_1.INVALID;
- }
- if (key.status === "dirty" || value.status === "dirty") {
- status.dirty();
- }
- finalMap.set(key.value, value.value);
- }
- return { status: status.value, value: finalMap };
- });
- }
- else {
- const finalMap = new Map();
- for (const pair of pairs) {
- const key = pair.key;
- const value = pair.value;
- if (key.status === "aborted" || value.status === "aborted") {
- return parseUtil_1.INVALID;
- }
- if (key.status === "dirty" || value.status === "dirty") {
- status.dirty();
- }
- finalMap.set(key.value, value.value);
- }
- return { status: status.value, value: finalMap };
- }
- }
- }
- exports.ZodMap = ZodMap;
- ZodMap.create = (keyType, valueType, params) => {
- return new ZodMap({
- valueType,
- keyType,
- typeName: ZodFirstPartyTypeKind.ZodMap,
- ...processCreateParams(params),
- });
- };
- class ZodSet extends ZodType {
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.set) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.set,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const def = this._def;
- if (def.minSize !== null) {
- if (ctx.data.size < def.minSize.value) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_small,
- minimum: def.minSize.value,
- type: "set",
- inclusive: true,
- exact: false,
- message: def.minSize.message,
- });
- status.dirty();
- }
- }
- if (def.maxSize !== null) {
- if (ctx.data.size > def.maxSize.value) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.too_big,
- maximum: def.maxSize.value,
- type: "set",
- inclusive: true,
- exact: false,
- message: def.maxSize.message,
- });
- status.dirty();
- }
- }
- const valueType = this._def.valueType;
- function finalizeSet(elements) {
- const parsedSet = new Set();
- for (const element of elements) {
- if (element.status === "aborted")
- return parseUtil_1.INVALID;
- if (element.status === "dirty")
- status.dirty();
- parsedSet.add(element.value);
- }
- return { status: status.value, value: parsedSet };
- }
- const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
- if (ctx.common.async) {
- return Promise.all(elements).then((elements) => finalizeSet(elements));
- }
- else {
- return finalizeSet(elements);
- }
- }
- min(minSize, message) {
- return new ZodSet({
- ...this._def,
- minSize: { value: minSize, message: errorUtil_1.errorUtil.toString(message) },
- });
- }
- max(maxSize, message) {
- return new ZodSet({
- ...this._def,
- maxSize: { value: maxSize, message: errorUtil_1.errorUtil.toString(message) },
- });
- }
- size(size, message) {
- return this.min(size, message).max(size, message);
- }
- nonempty(message) {
- return this.min(1, message);
- }
- }
- exports.ZodSet = ZodSet;
- ZodSet.create = (valueType, params) => {
- return new ZodSet({
- valueType,
- minSize: null,
- maxSize: null,
- typeName: ZodFirstPartyTypeKind.ZodSet,
- ...processCreateParams(params),
- });
- };
- class ZodFunction extends ZodType {
- constructor() {
- super(...arguments);
- this.validate = this.implement;
- }
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.function) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.function,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- function makeArgsIssue(args, error) {
- return (0, parseUtil_1.makeIssue)({
- data: args,
- path: ctx.path,
- errorMaps: [
- ctx.common.contextualErrorMap,
- ctx.schemaErrorMap,
- (0, errors_1.getErrorMap)(),
- errors_1.defaultErrorMap,
- ].filter((x) => !!x),
- issueData: {
- code: ZodError_1.ZodIssueCode.invalid_arguments,
- argumentsError: error,
- },
- });
- }
- function makeReturnsIssue(returns, error) {
- return (0, parseUtil_1.makeIssue)({
- data: returns,
- path: ctx.path,
- errorMaps: [
- ctx.common.contextualErrorMap,
- ctx.schemaErrorMap,
- (0, errors_1.getErrorMap)(),
- errors_1.defaultErrorMap,
- ].filter((x) => !!x),
- issueData: {
- code: ZodError_1.ZodIssueCode.invalid_return_type,
- returnTypeError: error,
- },
- });
- }
- const params = { errorMap: ctx.common.contextualErrorMap };
- const fn = ctx.data;
- if (this._def.returns instanceof ZodPromise) {
- // Would love a way to avoid disabling this rule, but we need
- // an alias (using an arrow function was what caused 2651).
- // eslint-disable-next-line @typescript-eslint/no-this-alias
- const me = this;
- return (0, parseUtil_1.OK)(async function (...args) {
- const error = new ZodError_1.ZodError([]);
- const parsedArgs = await me._def.args
- .parseAsync(args, params)
- .catch((e) => {
- error.addIssue(makeArgsIssue(args, e));
- throw error;
- });
- const result = await Reflect.apply(fn, this, parsedArgs);
- const parsedReturns = await me._def.returns._def.type
- .parseAsync(result, params)
- .catch((e) => {
- error.addIssue(makeReturnsIssue(result, e));
- throw error;
- });
- return parsedReturns;
- });
- }
- else {
- // Would love a way to avoid disabling this rule, but we need
- // an alias (using an arrow function was what caused 2651).
- // eslint-disable-next-line @typescript-eslint/no-this-alias
- const me = this;
- return (0, parseUtil_1.OK)(function (...args) {
- const parsedArgs = me._def.args.safeParse(args, params);
- if (!parsedArgs.success) {
- throw new ZodError_1.ZodError([makeArgsIssue(args, parsedArgs.error)]);
- }
- const result = Reflect.apply(fn, this, parsedArgs.data);
- const parsedReturns = me._def.returns.safeParse(result, params);
- if (!parsedReturns.success) {
- throw new ZodError_1.ZodError([makeReturnsIssue(result, parsedReturns.error)]);
- }
- return parsedReturns.data;
- });
- }
- }
- parameters() {
- return this._def.args;
- }
- returnType() {
- return this._def.returns;
- }
- args(...items) {
- return new ZodFunction({
- ...this._def,
- args: ZodTuple.create(items).rest(ZodUnknown.create()),
- });
- }
- returns(returnType) {
- return new ZodFunction({
- ...this._def,
- returns: returnType,
- });
- }
- implement(func) {
- const validatedFunc = this.parse(func);
- return validatedFunc;
- }
- strictImplement(func) {
- const validatedFunc = this.parse(func);
- return validatedFunc;
- }
- static create(args, returns, params) {
- return new ZodFunction({
- args: (args
- ? args
- : ZodTuple.create([]).rest(ZodUnknown.create())),
- returns: returns || ZodUnknown.create(),
- typeName: ZodFirstPartyTypeKind.ZodFunction,
- ...processCreateParams(params),
- });
- }
- }
- exports.ZodFunction = ZodFunction;
- class ZodLazy extends ZodType {
- get schema() {
- return this._def.getter();
- }
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- const lazySchema = this._def.getter();
- return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx });
- }
- }
- exports.ZodLazy = ZodLazy;
- ZodLazy.create = (getter, params) => {
- return new ZodLazy({
- getter: getter,
- typeName: ZodFirstPartyTypeKind.ZodLazy,
- ...processCreateParams(params),
- });
- };
- class ZodLiteral extends ZodType {
- _parse(input) {
- if (input.data !== this._def.value) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- received: ctx.data,
- code: ZodError_1.ZodIssueCode.invalid_literal,
- expected: this._def.value,
- });
- return parseUtil_1.INVALID;
- }
- return { status: "valid", value: input.data };
- }
- get value() {
- return this._def.value;
- }
- }
- exports.ZodLiteral = ZodLiteral;
- ZodLiteral.create = (value, params) => {
- return new ZodLiteral({
- value: value,
- typeName: ZodFirstPartyTypeKind.ZodLiteral,
- ...processCreateParams(params),
- });
- };
- function createZodEnum(values, params) {
- return new ZodEnum({
- values,
- typeName: ZodFirstPartyTypeKind.ZodEnum,
- ...processCreateParams(params),
- });
- }
- class ZodEnum extends ZodType {
- _parse(input) {
- if (typeof input.data !== "string") {
- const ctx = this._getOrReturnCtx(input);
- const expectedValues = this._def.values;
- (0, parseUtil_1.addIssueToContext)(ctx, {
- expected: util_1.util.joinValues(expectedValues),
- received: ctx.parsedType,
- code: ZodError_1.ZodIssueCode.invalid_type,
- });
- return parseUtil_1.INVALID;
- }
- if (this._def.values.indexOf(input.data) === -1) {
- const ctx = this._getOrReturnCtx(input);
- const expectedValues = this._def.values;
- (0, parseUtil_1.addIssueToContext)(ctx, {
- received: ctx.data,
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
- options: expectedValues,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- get options() {
- return this._def.values;
- }
- get enum() {
- const enumValues = {};
- for (const val of this._def.values) {
- enumValues[val] = val;
- }
- return enumValues;
- }
- get Values() {
- const enumValues = {};
- for (const val of this._def.values) {
- enumValues[val] = val;
- }
- return enumValues;
- }
- get Enum() {
- const enumValues = {};
- for (const val of this._def.values) {
- enumValues[val] = val;
- }
- return enumValues;
- }
- extract(values) {
- return ZodEnum.create(values);
- }
- exclude(values) {
- return ZodEnum.create(this.options.filter((opt) => !values.includes(opt)));
- }
- }
- exports.ZodEnum = ZodEnum;
- ZodEnum.create = createZodEnum;
- class ZodNativeEnum extends ZodType {
- _parse(input) {
- const nativeEnumValues = util_1.util.getValidEnumValues(this._def.values);
- const ctx = this._getOrReturnCtx(input);
- if (ctx.parsedType !== util_1.ZodParsedType.string &&
- ctx.parsedType !== util_1.ZodParsedType.number) {
- const expectedValues = util_1.util.objectValues(nativeEnumValues);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- expected: util_1.util.joinValues(expectedValues),
- received: ctx.parsedType,
- code: ZodError_1.ZodIssueCode.invalid_type,
- });
- return parseUtil_1.INVALID;
- }
- if (nativeEnumValues.indexOf(input.data) === -1) {
- const expectedValues = util_1.util.objectValues(nativeEnumValues);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- received: ctx.data,
- code: ZodError_1.ZodIssueCode.invalid_enum_value,
- options: expectedValues,
- });
- return parseUtil_1.INVALID;
- }
- return (0, parseUtil_1.OK)(input.data);
- }
- get enum() {
- return this._def.values;
- }
- }
- exports.ZodNativeEnum = ZodNativeEnum;
- ZodNativeEnum.create = (values, params) => {
- return new ZodNativeEnum({
- values: values,
- typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
- ...processCreateParams(params),
- });
- };
- class ZodPromise extends ZodType {
- unwrap() {
- return this._def.type;
- }
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- if (ctx.parsedType !== util_1.ZodParsedType.promise &&
- ctx.common.async === false) {
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.promise,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- const promisified = ctx.parsedType === util_1.ZodParsedType.promise
- ? ctx.data
- : Promise.resolve(ctx.data);
- return (0, parseUtil_1.OK)(promisified.then((data) => {
- return this._def.type.parseAsync(data, {
- path: ctx.path,
- errorMap: ctx.common.contextualErrorMap,
- });
- }));
- }
- }
- exports.ZodPromise = ZodPromise;
- ZodPromise.create = (schema, params) => {
- return new ZodPromise({
- type: schema,
- typeName: ZodFirstPartyTypeKind.ZodPromise,
- ...processCreateParams(params),
- });
- };
- class ZodEffects extends ZodType {
- innerType() {
- return this._def.schema;
- }
- sourceType() {
- return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects
- ? this._def.schema.sourceType()
- : this._def.schema;
- }
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- const effect = this._def.effect || null;
- const checkCtx = {
- addIssue: (arg) => {
- (0, parseUtil_1.addIssueToContext)(ctx, arg);
- if (arg.fatal) {
- status.abort();
- }
- else {
- status.dirty();
- }
- },
- get path() {
- return ctx.path;
- },
- };
- checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
- if (effect.type === "preprocess") {
- const processed = effect.transform(ctx.data, checkCtx);
- if (ctx.common.issues.length) {
- return {
- status: "dirty",
- value: ctx.data,
- };
- }
- if (ctx.common.async) {
- return Promise.resolve(processed).then((processed) => {
- return this._def.schema._parseAsync({
- data: processed,
- path: ctx.path,
- parent: ctx,
- });
- });
- }
- else {
- return this._def.schema._parseSync({
- data: processed,
- path: ctx.path,
- parent: ctx,
- });
- }
- }
- if (effect.type === "refinement") {
- const executeRefinement = (acc
- // effect: RefinementEffect<any>
- ) => {
- const result = effect.refinement(acc, checkCtx);
- if (ctx.common.async) {
- return Promise.resolve(result);
- }
- if (result instanceof Promise) {
- throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
- }
- return acc;
- };
- if (ctx.common.async === false) {
- const inner = this._def.schema._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- if (inner.status === "aborted")
- return parseUtil_1.INVALID;
- if (inner.status === "dirty")
- status.dirty();
- // return value is ignored
- executeRefinement(inner.value);
- return { status: status.value, value: inner.value };
- }
- else {
- return this._def.schema
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
- .then((inner) => {
- if (inner.status === "aborted")
- return parseUtil_1.INVALID;
- if (inner.status === "dirty")
- status.dirty();
- return executeRefinement(inner.value).then(() => {
- return { status: status.value, value: inner.value };
- });
- });
- }
- }
- if (effect.type === "transform") {
- if (ctx.common.async === false) {
- const base = this._def.schema._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- if (!(0, parseUtil_1.isValid)(base))
- return base;
- const result = effect.transform(base.value, checkCtx);
- if (result instanceof Promise) {
- throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
- }
- return { status: status.value, value: result };
- }
- else {
- return this._def.schema
- ._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx })
- .then((base) => {
- if (!(0, parseUtil_1.isValid)(base))
- return base;
- return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result }));
- });
- }
- }
- util_1.util.assertNever(effect);
- }
- }
- exports.ZodEffects = ZodEffects;
- exports.ZodTransformer = ZodEffects;
- ZodEffects.create = (schema, effect, params) => {
- return new ZodEffects({
- schema,
- typeName: ZodFirstPartyTypeKind.ZodEffects,
- effect,
- ...processCreateParams(params),
- });
- };
- ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
- return new ZodEffects({
- schema,
- effect: { type: "preprocess", transform: preprocess },
- typeName: ZodFirstPartyTypeKind.ZodEffects,
- ...processCreateParams(params),
- });
- };
- class ZodOptional extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType === util_1.ZodParsedType.undefined) {
- return (0, parseUtil_1.OK)(undefined);
- }
- return this._def.innerType._parse(input);
- }
- unwrap() {
- return this._def.innerType;
- }
- }
- exports.ZodOptional = ZodOptional;
- ZodOptional.create = (type, params) => {
- return new ZodOptional({
- innerType: type,
- typeName: ZodFirstPartyTypeKind.ZodOptional,
- ...processCreateParams(params),
- });
- };
- class ZodNullable extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType === util_1.ZodParsedType.null) {
- return (0, parseUtil_1.OK)(null);
- }
- return this._def.innerType._parse(input);
- }
- unwrap() {
- return this._def.innerType;
- }
- }
- exports.ZodNullable = ZodNullable;
- ZodNullable.create = (type, params) => {
- return new ZodNullable({
- innerType: type,
- typeName: ZodFirstPartyTypeKind.ZodNullable,
- ...processCreateParams(params),
- });
- };
- class ZodDefault extends ZodType {
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- let data = ctx.data;
- if (ctx.parsedType === util_1.ZodParsedType.undefined) {
- data = this._def.defaultValue();
- }
- return this._def.innerType._parse({
- data,
- path: ctx.path,
- parent: ctx,
- });
- }
- removeDefault() {
- return this._def.innerType;
- }
- }
- exports.ZodDefault = ZodDefault;
- ZodDefault.create = (type, params) => {
- return new ZodDefault({
- innerType: type,
- typeName: ZodFirstPartyTypeKind.ZodDefault,
- defaultValue: typeof params.default === "function"
- ? params.default
- : () => params.default,
- ...processCreateParams(params),
- });
- };
- class ZodCatch extends ZodType {
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- // newCtx is used to not collect issues from inner types in ctx
- const newCtx = {
- ...ctx,
- common: {
- ...ctx.common,
- issues: [],
- },
- };
- const result = this._def.innerType._parse({
- data: newCtx.data,
- path: newCtx.path,
- parent: {
- ...newCtx,
- },
- });
- if ((0, parseUtil_1.isAsync)(result)) {
- return result.then((result) => {
- return {
- status: "valid",
- value: result.status === "valid"
- ? result.value
- : this._def.catchValue({
- get error() {
- return new ZodError_1.ZodError(newCtx.common.issues);
- },
- input: newCtx.data,
- }),
- };
- });
- }
- else {
- return {
- status: "valid",
- value: result.status === "valid"
- ? result.value
- : this._def.catchValue({
- get error() {
- return new ZodError_1.ZodError(newCtx.common.issues);
- },
- input: newCtx.data,
- }),
- };
- }
- }
- removeCatch() {
- return this._def.innerType;
- }
- }
- exports.ZodCatch = ZodCatch;
- ZodCatch.create = (type, params) => {
- return new ZodCatch({
- innerType: type,
- typeName: ZodFirstPartyTypeKind.ZodCatch,
- catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
- ...processCreateParams(params),
- });
- };
- class ZodNaN extends ZodType {
- _parse(input) {
- const parsedType = this._getType(input);
- if (parsedType !== util_1.ZodParsedType.nan) {
- const ctx = this._getOrReturnCtx(input);
- (0, parseUtil_1.addIssueToContext)(ctx, {
- code: ZodError_1.ZodIssueCode.invalid_type,
- expected: util_1.ZodParsedType.nan,
- received: ctx.parsedType,
- });
- return parseUtil_1.INVALID;
- }
- return { status: "valid", value: input.data };
- }
- }
- exports.ZodNaN = ZodNaN;
- ZodNaN.create = (params) => {
- return new ZodNaN({
- typeName: ZodFirstPartyTypeKind.ZodNaN,
- ...processCreateParams(params),
- });
- };
- exports.BRAND = Symbol("zod_brand");
- class ZodBranded extends ZodType {
- _parse(input) {
- const { ctx } = this._processInputParams(input);
- const data = ctx.data;
- return this._def.type._parse({
- data,
- path: ctx.path,
- parent: ctx,
- });
- }
- unwrap() {
- return this._def.type;
- }
- }
- exports.ZodBranded = ZodBranded;
- class ZodPipeline extends ZodType {
- _parse(input) {
- const { status, ctx } = this._processInputParams(input);
- if (ctx.common.async) {
- const handleAsync = async () => {
- const inResult = await this._def.in._parseAsync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- if (inResult.status === "aborted")
- return parseUtil_1.INVALID;
- if (inResult.status === "dirty") {
- status.dirty();
- return (0, parseUtil_1.DIRTY)(inResult.value);
- }
- else {
- return this._def.out._parseAsync({
- data: inResult.value,
- path: ctx.path,
- parent: ctx,
- });
- }
- };
- return handleAsync();
- }
- else {
- const inResult = this._def.in._parseSync({
- data: ctx.data,
- path: ctx.path,
- parent: ctx,
- });
- if (inResult.status === "aborted")
- return parseUtil_1.INVALID;
- if (inResult.status === "dirty") {
- status.dirty();
- return {
- status: "dirty",
- value: inResult.value,
- };
- }
- else {
- return this._def.out._parseSync({
- data: inResult.value,
- path: ctx.path,
- parent: ctx,
- });
- }
- }
- }
- static create(a, b) {
- return new ZodPipeline({
- in: a,
- out: b,
- typeName: ZodFirstPartyTypeKind.ZodPipeline,
- });
- }
- }
- exports.ZodPipeline = ZodPipeline;
- class ZodReadonly extends ZodType {
- _parse(input) {
- const result = this._def.innerType._parse(input);
- if ((0, parseUtil_1.isValid)(result)) {
- result.value = Object.freeze(result.value);
- }
- return result;
- }
- }
- exports.ZodReadonly = ZodReadonly;
- ZodReadonly.create = (type, params) => {
- return new ZodReadonly({
- innerType: type,
- typeName: ZodFirstPartyTypeKind.ZodReadonly,
- ...processCreateParams(params),
- });
- };
- const custom = (check, params = {},
- /**
- * @deprecated
- *
- * Pass `fatal` into the params object instead:
- *
- * ```ts
- * z.string().custom((val) => val.length > 5, { fatal: false })
- * ```
- *
- */
- fatal) => {
- if (check)
- return ZodAny.create().superRefine((data, ctx) => {
- var _a, _b;
- if (!check(data)) {
- const p = typeof params === "function"
- ? params(data)
- : typeof params === "string"
- ? { message: params }
- : params;
- const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
- const p2 = typeof p === "string" ? { message: p } : p;
- ctx.addIssue({ code: "custom", ...p2, fatal: _fatal });
- }
- });
- return ZodAny.create();
- };
- exports.custom = custom;
- exports.late = {
- object: ZodObject.lazycreate,
- };
- var ZodFirstPartyTypeKind;
- (function (ZodFirstPartyTypeKind) {
- ZodFirstPartyTypeKind["ZodString"] = "ZodString";
- ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
- ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
- ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
- ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
- ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
- ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
- ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
- ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
- ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
- ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
- ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
- ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
- ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
- ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
- ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
- ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
- ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
- ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
- ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
- ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
- ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
- ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
- ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
- ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
- ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
- ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
- ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
- ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
- ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
- ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
- ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
- ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
- ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
- ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
- ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
- })(ZodFirstPartyTypeKind = exports.ZodFirstPartyTypeKind || (exports.ZodFirstPartyTypeKind = {}));
- const instanceOfType = (
- // const instanceOfType = <T extends new (...args: any[]) => any>(
- cls, params = {
- message: `Input not instance of ${cls.name}`,
- }) => (0, exports.custom)((data) => data instanceof cls, params);
- exports.instanceof = instanceOfType;
- const stringType = ZodString.create;
- exports.string = stringType;
- const numberType = ZodNumber.create;
- exports.number = numberType;
- const nanType = ZodNaN.create;
- exports.nan = nanType;
- const bigIntType = ZodBigInt.create;
- exports.bigint = bigIntType;
- const booleanType = ZodBoolean.create;
- exports.boolean = booleanType;
- const dateType = ZodDate.create;
- exports.date = dateType;
- const symbolType = ZodSymbol.create;
- exports.symbol = symbolType;
- const undefinedType = ZodUndefined.create;
- exports.undefined = undefinedType;
- const nullType = ZodNull.create;
- exports.null = nullType;
- const anyType = ZodAny.create;
- exports.any = anyType;
- const unknownType = ZodUnknown.create;
- exports.unknown = unknownType;
- const neverType = ZodNever.create;
- exports.never = neverType;
- const voidType = ZodVoid.create;
- exports.void = voidType;
- const arrayType = ZodArray.create;
- exports.array = arrayType;
- const objectType = ZodObject.create;
- exports.object = objectType;
- const strictObjectType = ZodObject.strictCreate;
- exports.strictObject = strictObjectType;
- const unionType = ZodUnion.create;
- exports.union = unionType;
- const discriminatedUnionType = ZodDiscriminatedUnion.create;
- exports.discriminatedUnion = discriminatedUnionType;
- const intersectionType = ZodIntersection.create;
- exports.intersection = intersectionType;
- const tupleType = ZodTuple.create;
- exports.tuple = tupleType;
- const recordType = ZodRecord.create;
- exports.record = recordType;
- const mapType = ZodMap.create;
- exports.map = mapType;
- const setType = ZodSet.create;
- exports.set = setType;
- const functionType = ZodFunction.create;
- exports.function = functionType;
- const lazyType = ZodLazy.create;
- exports.lazy = lazyType;
- const literalType = ZodLiteral.create;
- exports.literal = literalType;
- const enumType = ZodEnum.create;
- exports.enum = enumType;
- const nativeEnumType = ZodNativeEnum.create;
- exports.nativeEnum = nativeEnumType;
- const promiseType = ZodPromise.create;
- exports.promise = promiseType;
- const effectsType = ZodEffects.create;
- exports.effect = effectsType;
- exports.transformer = effectsType;
- const optionalType = ZodOptional.create;
- exports.optional = optionalType;
- const nullableType = ZodNullable.create;
- exports.nullable = nullableType;
- const preprocessType = ZodEffects.createWithPreprocess;
- exports.preprocess = preprocessType;
- const pipelineType = ZodPipeline.create;
- exports.pipeline = pipelineType;
- const ostring = () => stringType().optional();
- exports.ostring = ostring;
- const onumber = () => numberType().optional();
- exports.onumber = onumber;
- const oboolean = () => booleanType().optional();
- exports.oboolean = oboolean;
- exports.coerce = {
- string: ((arg) => ZodString.create({ ...arg, coerce: true })),
- number: ((arg) => ZodNumber.create({ ...arg, coerce: true })),
- boolean: ((arg) => ZodBoolean.create({
- ...arg,
- coerce: true,
- })),
- bigint: ((arg) => ZodBigInt.create({ ...arg, coerce: true })),
- date: ((arg) => ZodDate.create({ ...arg, coerce: true })),
- };
- exports.NEVER = parseUtil_1.INVALID;
- } (types));
- (function (exports) {
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- __exportStar(errors, exports);
- __exportStar(parseUtil, exports);
- __exportStar(typeAliases, exports);
- __exportStar(util, exports);
- __exportStar(types, exports);
- __exportStar(ZodError$1, exports);
- } (external));
- (function (exports) {
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- var __exportStar = (commonjsGlobal && commonjsGlobal.__exportStar) || function(m, exports) {
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.z = void 0;
- const z = __importStar(external);
- exports.z = z;
- __exportStar(external, exports);
- exports.default = z;
- } (lib));
- var webdriverBidiPermissions = {};
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(webdriverBidiPermissions, "__esModule", { value: true });
- webdriverBidiPermissions.Permissions = webdriverBidiPermissions.PermissionsCommandSchema = void 0;
- /**
- * THIS FILE IS AUTOGENERATED by cddlconv 0.1.5.
- * Run `node tools/generate-bidi-types.mjs` to regenerate.
- * @see https://github.com/w3c/webdriver-bidi/blob/master/index.bs
- */
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-nocheck Some types may be circular.
- const zod_1$1 = __importDefault(lib);
- webdriverBidiPermissions.PermissionsCommandSchema = zod_1$1.default.lazy(() => Permissions$1.SetPermissionSchema);
- var Permissions$1;
- (function (Permissions) {
- Permissions.PermissionDescriptorSchema = zod_1$1.default.lazy(() => zod_1$1.default.object({
- name: zod_1$1.default.string(),
- }));
- })(Permissions$1 || (webdriverBidiPermissions.Permissions = Permissions$1 = {}));
- (function (Permissions) {
- Permissions.PermissionStateSchema = zod_1$1.default.lazy(() => zod_1$1.default.enum(['granted', 'denied', 'prompt']));
- })(Permissions$1 || (webdriverBidiPermissions.Permissions = Permissions$1 = {}));
- (function (Permissions) {
- Permissions.SetPermissionSchema = zod_1$1.default.lazy(() => zod_1$1.default.object({
- method: zod_1$1.default.literal('permissions.setPermission'),
- params: Permissions.SetPermissionParametersSchema,
- }));
- })(Permissions$1 || (webdriverBidiPermissions.Permissions = Permissions$1 = {}));
- (function (Permissions) {
- Permissions.SetPermissionParametersSchema = zod_1$1.default.lazy(() => zod_1$1.default.object({
- descriptor: Permissions.PermissionDescriptorSchema,
- state: Permissions.PermissionStateSchema,
- origin: zod_1$1.default.string(),
- userContext: zod_1$1.default.string().optional(),
- }));
- })(Permissions$1 || (webdriverBidiPermissions.Permissions = Permissions$1 = {}));
- var webdriverBidi = {};
- (function (exports) {
- /**
- * Copyright 2024 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var __importDefault = (commonjsGlobal && commonjsGlobal.__importDefault) || function (mod) {
- return (mod && mod.__esModule) ? mod : { "default": mod };
- };
- Object.defineProperty(exports, "__esModule", { value: true });
- exports.Input = exports.InputCommandSchema = exports.Log = exports.LogEventSchema = exports.Storage = exports.StorageResultSchema = exports.StorageCommandSchema = exports.Script = exports.ScriptResultSchema = exports.ScriptCommandSchema = exports.ScriptEventSchema = exports.Network = exports.NetworkResultSchema = exports.NetworkEventSchema = exports.NetworkCommandSchema = exports.BrowsingContext = exports.BrowsingContextResultSchema = exports.BrowsingContextEventSchema = exports.BrowsingContextCommandSchema = exports.Browser = exports.BrowserResultSchema = exports.BrowserCommandSchema = exports.SessionResultSchema = exports.Session = exports.SessionCommandSchema = exports.ErrorCodeSchema = exports.JsUintSchema = exports.JsIntSchema = exports.ExtensibleSchema = exports.EmptyResultSchema = exports.ErrorResponseSchema = exports.MessageSchema = exports.EmptyParamsSchema = exports.ResultDataSchema = exports.CommandDataSchema = exports.EventDataSchema = exports.CommandResponseSchema = exports.CommandSchema = exports.EventSchema = void 0;
- /**
- * THIS FILE IS AUTOGENERATED by cddlconv 0.1.5.
- * Run `node tools/generate-bidi-types.mjs` to regenerate.
- * @see https://github.com/w3c/webdriver-bidi/blob/master/index.bs
- */
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-nocheck Some types may be circular.
- const zod_1 = __importDefault(lib);
- exports.EventSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('event'),
- })
- .and(exports.EventDataSchema)
- .and(exports.ExtensibleSchema));
- exports.CommandSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- id: exports.JsUintSchema,
- })
- .and(exports.CommandDataSchema)
- .and(exports.ExtensibleSchema));
- exports.CommandResponseSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('success'),
- id: exports.JsUintSchema,
- result: exports.ResultDataSchema,
- })
- .and(exports.ExtensibleSchema));
- exports.EventDataSchema = zod_1.default.lazy(() => zod_1.default.union([
- exports.BrowsingContextEventSchema,
- exports.LogEventSchema,
- exports.NetworkEventSchema,
- exports.ScriptEventSchema,
- ]));
- exports.CommandDataSchema = zod_1.default.lazy(() => zod_1.default.union([
- exports.BrowserCommandSchema,
- exports.BrowsingContextCommandSchema,
- exports.InputCommandSchema,
- exports.NetworkCommandSchema,
- exports.ScriptCommandSchema,
- exports.SessionCommandSchema,
- exports.StorageCommandSchema,
- ]));
- exports.ResultDataSchema = zod_1.default.lazy(() => zod_1.default.union([
- exports.BrowsingContextResultSchema,
- exports.EmptyResultSchema,
- exports.NetworkResultSchema,
- exports.ScriptResultSchema,
- exports.SessionResultSchema,
- exports.StorageResultSchema,
- ]));
- exports.EmptyParamsSchema = zod_1.default.lazy(() => exports.ExtensibleSchema);
- exports.MessageSchema = zod_1.default.lazy(() => zod_1.default.union([exports.CommandResponseSchema, exports.ErrorResponseSchema, exports.EventSchema]));
- exports.ErrorResponseSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('error'),
- id: zod_1.default.union([exports.JsUintSchema, zod_1.default.null()]),
- error: exports.ErrorCodeSchema,
- message: zod_1.default.string(),
- stacktrace: zod_1.default.string().optional(),
- })
- .and(exports.ExtensibleSchema));
- exports.EmptyResultSchema = zod_1.default.lazy(() => exports.ExtensibleSchema);
- exports.ExtensibleSchema = zod_1.default.lazy(() => zod_1.default.record(zod_1.default.string(), zod_1.default.any()));
- exports.JsIntSchema = zod_1.default
- .number()
- .int()
- .gte(-9007199254740991)
- .lte(9007199254740991);
- exports.JsUintSchema = zod_1.default
- .number()
- .int()
- .nonnegative()
- .gte(0)
- .lte(9007199254740991);
- exports.ErrorCodeSchema = zod_1.default.lazy(() => zod_1.default.enum([
- 'invalid argument',
- 'invalid selector',
- 'invalid session id',
- 'move target out of bounds',
- 'no such alert',
- 'no such element',
- 'no such frame',
- 'no such handle',
- 'no such history entry',
- 'no such intercept',
- 'no such node',
- 'no such request',
- 'no such script',
- 'no such storage partition',
- 'no such user context',
- 'session not created',
- 'unable to capture screen',
- 'unable to close browser',
- 'unable to set cookie',
- 'unable to set file input',
- 'underspecified storage partition',
- 'unknown command',
- 'unknown error',
- 'unsupported operation',
- ]));
- exports.SessionCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Session.EndSchema,
- Session.NewSchema,
- Session.StatusSchema,
- Session.SubscribeSchema,
- Session.UnsubscribeSchema,
- ]));
- var Session;
- (function (Session) {
- Session.ProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default.union([
- Session.AutodetectProxyConfigurationSchema,
- Session.DirectProxyConfigurationSchema,
- Session.ManualProxyConfigurationSchema,
- Session.PacProxyConfigurationSchema,
- Session.SystemProxyConfigurationSchema,
- zod_1.default.object({}),
- ]));
- })(Session || (exports.Session = Session = {}));
- exports.SessionResultSchema = zod_1.default.lazy(() => zod_1.default.union([Session.NewResultSchema, Session.StatusResultSchema]));
- (function (Session) {
- Session.CapabilitiesRequestSchema = zod_1.default.lazy(() => zod_1.default.object({
- alwaysMatch: Session.CapabilityRequestSchema.optional(),
- firstMatch: zod_1.default.array(Session.CapabilityRequestSchema).optional(),
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.CapabilityRequestSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- acceptInsecureCerts: zod_1.default.boolean().optional(),
- browserName: zod_1.default.string().optional(),
- browserVersion: zod_1.default.string().optional(),
- platformName: zod_1.default.string().optional(),
- proxy: Session.ProxyConfigurationSchema.optional(),
- webSocketUrl: zod_1.default.boolean().optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.AutodetectProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- proxyType: zod_1.default.literal('autodetect'),
- })
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.DirectProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- proxyType: zod_1.default.literal('direct'),
- })
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.ManualProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- proxyType: zod_1.default.literal('manual'),
- ftpProxy: zod_1.default.string().optional(),
- httpProxy: zod_1.default.string().optional(),
- sslProxy: zod_1.default.string().optional(),
- })
- .and(Session.SocksProxyConfigurationSchema.or(zod_1.default.object({})))
- .and(zod_1.default.object({
- noProxy: zod_1.default.array(zod_1.default.string()).optional(),
- }))
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.SocksProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default.object({
- socksProxy: zod_1.default.string(),
- socksVersion: zod_1.default.number().int().nonnegative().gte(0).lte(255),
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.PacProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- proxyType: zod_1.default.literal('pac'),
- proxyAutoconfigUrl: zod_1.default.string(),
- })
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.SystemProxyConfigurationSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- proxyType: zod_1.default.literal('system'),
- })
- .and(exports.ExtensibleSchema));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.SubscriptionRequestSchema = zod_1.default.lazy(() => zod_1.default.object({
- events: zod_1.default.array(zod_1.default.string()).min(1),
- contexts: zod_1.default
- .array(BrowsingContext.BrowsingContextSchema)
- .min(1)
- .optional(),
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.StatusSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('session.status'),
- params: exports.EmptyParamsSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.StatusResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- ready: zod_1.default.boolean(),
- message: zod_1.default.string(),
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.NewSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('session.new'),
- params: Session.NewParametersSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.NewParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- capabilities: Session.CapabilitiesRequestSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.NewResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- sessionId: zod_1.default.string(),
- capabilities: zod_1.default
- .object({
- acceptInsecureCerts: zod_1.default.boolean(),
- browserName: zod_1.default.string(),
- browserVersion: zod_1.default.string(),
- platformName: zod_1.default.string(),
- setWindowRect: zod_1.default.boolean(),
- userAgent: zod_1.default.string(),
- proxy: Session.ProxyConfigurationSchema.optional(),
- webSocketUrl: zod_1.default.string().optional(),
- })
- .and(exports.ExtensibleSchema),
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.EndSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('session.end'),
- params: exports.EmptyParamsSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.SubscribeSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('session.subscribe'),
- params: Session.SubscriptionRequestSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- (function (Session) {
- Session.UnsubscribeSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('session.unsubscribe'),
- params: Session.SubscriptionRequestSchema,
- }));
- })(Session || (exports.Session = Session = {}));
- exports.BrowserCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Browser.CloseSchema,
- Browser.CreateUserContextSchema,
- Browser.GetUserContextsSchema,
- Browser.RemoveUserContextSchema,
- ]));
- exports.BrowserResultSchema = zod_1.default.lazy(() => zod_1.default.union([
- Browser.CreateUserContextResultSchema,
- Browser.GetUserContextsResultSchema,
- ]));
- var Browser;
- (function (Browser) {
- Browser.UserContextSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.UserContextInfoSchema = zod_1.default.lazy(() => zod_1.default.object({
- userContext: Browser.UserContextSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.CloseSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browser.close'),
- params: exports.EmptyParamsSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.CreateUserContextSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browser.createUserContext'),
- params: exports.EmptyParamsSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.CreateUserContextResultSchema = zod_1.default.lazy(() => Browser.UserContextInfoSchema);
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.GetUserContextsSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browser.getUserContexts'),
- params: exports.EmptyParamsSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.GetUserContextsResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- userContexts: zod_1.default.array(Browser.UserContextInfoSchema).min(1),
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.RemoveUserContextSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browser.removeUserContext'),
- params: Browser.RemoveUserContextParametersSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- (function (Browser) {
- Browser.RemoveUserContextParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- userContext: Browser.UserContextSchema,
- }));
- })(Browser || (exports.Browser = Browser = {}));
- exports.BrowsingContextCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- BrowsingContext.ActivateSchema,
- BrowsingContext.CaptureScreenshotSchema,
- BrowsingContext.CloseSchema,
- BrowsingContext.CreateSchema,
- BrowsingContext.GetTreeSchema,
- BrowsingContext.HandleUserPromptSchema,
- BrowsingContext.LocateNodesSchema,
- BrowsingContext.NavigateSchema,
- BrowsingContext.PrintSchema,
- BrowsingContext.ReloadSchema,
- BrowsingContext.SetViewportSchema,
- BrowsingContext.TraverseHistorySchema,
- ]));
- exports.BrowsingContextEventSchema = zod_1.default.lazy(() => zod_1.default.union([
- BrowsingContext.ContextCreatedSchema,
- BrowsingContext.ContextDestroyedSchema,
- BrowsingContext.DomContentLoadedSchema,
- BrowsingContext.DownloadWillBeginSchema,
- BrowsingContext.FragmentNavigatedSchema,
- BrowsingContext.LoadSchema,
- BrowsingContext.NavigationAbortedSchema,
- BrowsingContext.NavigationFailedSchema,
- BrowsingContext.NavigationStartedSchema,
- BrowsingContext.UserPromptClosedSchema,
- BrowsingContext.UserPromptOpenedSchema,
- ]));
- exports.BrowsingContextResultSchema = zod_1.default.lazy(() => zod_1.default.union([
- BrowsingContext.CaptureScreenshotResultSchema,
- BrowsingContext.CreateResultSchema,
- BrowsingContext.GetTreeResultSchema,
- BrowsingContext.LocateNodesResultSchema,
- BrowsingContext.NavigateResultSchema,
- BrowsingContext.PrintResultSchema,
- BrowsingContext.TraverseHistoryResultSchema,
- ]));
- var BrowsingContext;
- (function (BrowsingContext) {
- BrowsingContext.BrowsingContextSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.InfoListSchema = zod_1.default.lazy(() => zod_1.default.array(BrowsingContext.InfoSchema));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.InfoSchema = zod_1.default.lazy(() => zod_1.default.object({
- children: zod_1.default.union([BrowsingContext.InfoListSchema, zod_1.default.null()]),
- context: BrowsingContext.BrowsingContextSchema,
- url: zod_1.default.string(),
- userContext: Browser.UserContextSchema,
- parent: zod_1.default
- .union([BrowsingContext.BrowsingContextSchema, zod_1.default.null()])
- .optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.LocatorSchema = zod_1.default.lazy(() => zod_1.default.union([
- BrowsingContext.CssLocatorSchema,
- BrowsingContext.InnerTextLocatorSchema,
- BrowsingContext.XPathLocatorSchema,
- ]));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CssLocatorSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('css'),
- value: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.InnerTextLocatorSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('innerText'),
- value: zod_1.default.string(),
- ignoreCase: zod_1.default.boolean().optional(),
- matchType: zod_1.default.enum(['full', 'partial']).optional(),
- maxDepth: exports.JsUintSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.XPathLocatorSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('xpath'),
- value: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigationSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigationInfoSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- navigation: zod_1.default.union([BrowsingContext.NavigationSchema, zod_1.default.null()]),
- timestamp: exports.JsUintSchema,
- url: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ReadinessStateSchema = zod_1.default.lazy(() => zod_1.default.enum(['none', 'interactive', 'complete']));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ActivateSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.activate'),
- params: BrowsingContext.ActivateParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ActivateParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CaptureScreenshotParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- origin: zod_1.default.enum(['viewport', 'document']).default('viewport').optional(),
- format: BrowsingContext.ImageFormatSchema.optional(),
- clip: BrowsingContext.ClipRectangleSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CaptureScreenshotSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.captureScreenshot'),
- params: BrowsingContext.CaptureScreenshotParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ImageFormatSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.string(),
- quality: zod_1.default.number().gte(0).lte(1).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ClipRectangleSchema = zod_1.default.lazy(() => zod_1.default.union([
- BrowsingContext.BoxClipRectangleSchema,
- BrowsingContext.ElementClipRectangleSchema,
- ]));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ElementClipRectangleSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('element'),
- element: Script.SharedReferenceSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.BoxClipRectangleSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('box'),
- x: zod_1.default.number(),
- y: zod_1.default.number(),
- width: zod_1.default.number(),
- height: zod_1.default.number(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CaptureScreenshotResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- data: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CloseSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.close'),
- params: BrowsingContext.CloseParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CloseParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- promptUnload: zod_1.default.boolean().default(false).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CreateSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.create'),
- params: BrowsingContext.CreateParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CreateTypeSchema = zod_1.default.lazy(() => zod_1.default.enum(['tab', 'window']));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CreateParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: BrowsingContext.CreateTypeSchema,
- referenceContext: BrowsingContext.BrowsingContextSchema.optional(),
- background: zod_1.default.boolean().default(false).optional(),
- userContext: Browser.UserContextSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.CreateResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.GetTreeSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.getTree'),
- params: BrowsingContext.GetTreeParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.GetTreeParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- maxDepth: exports.JsUintSchema.optional(),
- root: BrowsingContext.BrowsingContextSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.GetTreeResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- contexts: BrowsingContext.InfoListSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.HandleUserPromptSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.handleUserPrompt'),
- params: BrowsingContext.HandleUserPromptParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.HandleUserPromptParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- accept: zod_1.default.boolean().optional(),
- userText: zod_1.default.string().optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.LocateNodesParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- locator: BrowsingContext.LocatorSchema,
- maxNodeCount: exports.JsUintSchema.gte(1).optional(),
- serializationOptions: Script.SerializationOptionsSchema.optional(),
- startNodes: zod_1.default.array(Script.SharedReferenceSchema).min(1).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.LocateNodesSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.locateNodes'),
- params: BrowsingContext.LocateNodesParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.LocateNodesResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- nodes: zod_1.default.array(Script.NodeRemoteValueSchema),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigateSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.navigate'),
- params: BrowsingContext.NavigateParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigateParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- url: zod_1.default.string(),
- wait: BrowsingContext.ReadinessStateSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigateResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- navigation: zod_1.default.union([BrowsingContext.NavigationSchema, zod_1.default.null()]),
- url: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.PrintSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.print'),
- params: BrowsingContext.PrintParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.PrintParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- background: zod_1.default.boolean().default(false).optional(),
- margin: BrowsingContext.PrintMarginParametersSchema.optional(),
- orientation: zod_1.default
- .enum(['portrait', 'landscape'])
- .default('portrait')
- .optional(),
- page: BrowsingContext.PrintPageParametersSchema.optional(),
- pageRanges: zod_1.default.array(zod_1.default.union([exports.JsUintSchema, zod_1.default.string()])).optional(),
- scale: zod_1.default.number().gte(0.1).lte(2).default(1).optional(),
- shrinkToFit: zod_1.default.boolean().default(true).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.PrintMarginParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- bottom: zod_1.default.number().gte(0).default(1).optional(),
- left: zod_1.default.number().gte(0).default(1).optional(),
- right: zod_1.default.number().gte(0).default(1).optional(),
- top: zod_1.default.number().gte(0).default(1).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.PrintPageParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- height: zod_1.default.number().gte(0.0352).default(27.94).optional(),
- width: zod_1.default.number().gte(0.0352).default(21.59).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.PrintResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- data: zod_1.default.string(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ReloadSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.reload'),
- params: BrowsingContext.ReloadParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ReloadParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- ignoreCache: zod_1.default.boolean().optional(),
- wait: BrowsingContext.ReadinessStateSchema.optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.SetViewportSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.setViewport'),
- params: BrowsingContext.SetViewportParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.SetViewportParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- viewport: zod_1.default.union([BrowsingContext.ViewportSchema, zod_1.default.null()]).optional(),
- devicePixelRatio: zod_1.default.union([zod_1.default.number().gt(0), zod_1.default.null()]).optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ViewportSchema = zod_1.default.lazy(() => zod_1.default.object({
- width: exports.JsUintSchema,
- height: exports.JsUintSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.TraverseHistorySchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.traverseHistory'),
- params: BrowsingContext.TraverseHistoryParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.TraverseHistoryParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- delta: exports.JsIntSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.TraverseHistoryResultSchema = zod_1.default.lazy(() => zod_1.default.object({}));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ContextCreatedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.contextCreated'),
- params: BrowsingContext.InfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.ContextDestroyedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.contextDestroyed'),
- params: BrowsingContext.InfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigationStartedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.navigationStarted'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.FragmentNavigatedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.fragmentNavigated'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.DomContentLoadedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.domContentLoaded'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.LoadSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.load'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.DownloadWillBeginSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.downloadWillBegin'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigationAbortedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.navigationAborted'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.NavigationFailedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.navigationFailed'),
- params: BrowsingContext.NavigationInfoSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.UserPromptClosedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.userPromptClosed'),
- params: BrowsingContext.UserPromptClosedParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.UserPromptClosedParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- accepted: zod_1.default.boolean(),
- userText: zod_1.default.string().optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.UserPromptOpenedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('browsingContext.userPromptOpened'),
- params: BrowsingContext.UserPromptOpenedParametersSchema,
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- (function (BrowsingContext) {
- BrowsingContext.UserPromptOpenedParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- type: zod_1.default.enum(['alert', 'confirm', 'prompt', 'beforeunload']),
- message: zod_1.default.string(),
- defaultValue: zod_1.default.string().optional(),
- }));
- })(BrowsingContext || (exports.BrowsingContext = BrowsingContext = {}));
- exports.NetworkCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Network.AddInterceptSchema,
- Network.ContinueRequestSchema,
- Network.ContinueResponseSchema,
- Network.ContinueWithAuthSchema,
- Network.FailRequestSchema,
- Network.ProvideResponseSchema,
- Network.RemoveInterceptSchema,
- ]));
- exports.NetworkEventSchema = zod_1.default.lazy(() => zod_1.default.union([
- Network.AuthRequiredSchema,
- Network.BeforeRequestSentSchema,
- Network.FetchErrorSchema,
- Network.ResponseCompletedSchema,
- Network.ResponseStartedSchema,
- ]));
- exports.NetworkResultSchema = zod_1.default.lazy(() => Network.AddInterceptResultSchema);
- var Network;
- (function (Network) {
- Network.AuthChallengeSchema = zod_1.default.lazy(() => zod_1.default.object({
- scheme: zod_1.default.string(),
- realm: zod_1.default.string(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.AuthCredentialsSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('password'),
- username: zod_1.default.string(),
- password: zod_1.default.string(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.BaseParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: zod_1.default.union([BrowsingContext.BrowsingContextSchema, zod_1.default.null()]),
- isBlocked: zod_1.default.boolean(),
- navigation: zod_1.default.union([BrowsingContext.NavigationSchema, zod_1.default.null()]),
- redirectCount: exports.JsUintSchema,
- request: Network.RequestDataSchema,
- timestamp: exports.JsUintSchema,
- intercepts: zod_1.default.array(Network.InterceptSchema).min(1).optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.BytesValueSchema = zod_1.default.lazy(() => zod_1.default.union([Network.StringValueSchema, Network.Base64ValueSchema]));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.StringValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('string'),
- value: zod_1.default.string(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.Base64ValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('base64'),
- value: zod_1.default.string(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.SameSiteSchema = zod_1.default.lazy(() => zod_1.default.enum(['strict', 'lax', 'none']));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.CookieSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- name: zod_1.default.string(),
- value: Network.BytesValueSchema,
- domain: zod_1.default.string(),
- path: zod_1.default.string(),
- size: exports.JsUintSchema,
- httpOnly: zod_1.default.boolean(),
- secure: zod_1.default.boolean(),
- sameSite: Network.SameSiteSchema,
- expiry: exports.JsUintSchema.optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.CookieHeaderSchema = zod_1.default.lazy(() => zod_1.default.object({
- name: zod_1.default.string(),
- value: Network.BytesValueSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.FetchTimingInfoSchema = zod_1.default.lazy(() => zod_1.default.object({
- timeOrigin: zod_1.default.number(),
- requestTime: zod_1.default.number(),
- redirectStart: zod_1.default.number(),
- redirectEnd: zod_1.default.number(),
- fetchStart: zod_1.default.number(),
- dnsStart: zod_1.default.number(),
- dnsEnd: zod_1.default.number(),
- connectStart: zod_1.default.number(),
- connectEnd: zod_1.default.number(),
- tlsStart: zod_1.default.number(),
- requestStart: zod_1.default.number(),
- responseStart: zod_1.default.number(),
- responseEnd: zod_1.default.number(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.HeaderSchema = zod_1.default.lazy(() => zod_1.default.object({
- name: zod_1.default.string(),
- value: Network.BytesValueSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.InitiatorSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.enum(['parser', 'script', 'preflight', 'other']),
- columnNumber: exports.JsUintSchema.optional(),
- lineNumber: exports.JsUintSchema.optional(),
- stackTrace: Script.StackTraceSchema.optional(),
- request: Network.RequestSchema.optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.InterceptSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.RequestSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.RequestDataSchema = zod_1.default.lazy(() => zod_1.default.object({
- request: Network.RequestSchema,
- url: zod_1.default.string(),
- method: zod_1.default.string(),
- headers: zod_1.default.array(Network.HeaderSchema),
- cookies: zod_1.default.array(Network.CookieSchema),
- headersSize: exports.JsUintSchema,
- bodySize: zod_1.default.union([exports.JsUintSchema, zod_1.default.null()]),
- timings: Network.FetchTimingInfoSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseContentSchema = zod_1.default.lazy(() => zod_1.default.object({
- size: exports.JsUintSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseDataSchema = zod_1.default.lazy(() => zod_1.default.object({
- url: zod_1.default.string(),
- protocol: zod_1.default.string(),
- status: exports.JsUintSchema,
- statusText: zod_1.default.string(),
- fromCache: zod_1.default.boolean(),
- headers: zod_1.default.array(Network.HeaderSchema),
- mimeType: zod_1.default.string(),
- bytesReceived: exports.JsUintSchema,
- headersSize: zod_1.default.union([exports.JsUintSchema, zod_1.default.null()]),
- bodySize: zod_1.default.union([exports.JsUintSchema, zod_1.default.null()]),
- content: Network.ResponseContentSchema,
- authChallenges: zod_1.default.array(Network.AuthChallengeSchema).optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.SetCookieHeaderSchema = zod_1.default.lazy(() => zod_1.default.object({
- name: zod_1.default.string(),
- value: Network.BytesValueSchema,
- domain: zod_1.default.string().optional(),
- httpOnly: zod_1.default.boolean().optional(),
- expiry: zod_1.default.string().optional(),
- maxAge: exports.JsIntSchema.optional(),
- path: zod_1.default.string().optional(),
- sameSite: Network.SameSiteSchema.optional(),
- secure: zod_1.default.boolean().optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.UrlPatternSchema = zod_1.default.lazy(() => zod_1.default.union([Network.UrlPatternPatternSchema, Network.UrlPatternStringSchema]));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.UrlPatternPatternSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('pattern'),
- protocol: zod_1.default.string().optional(),
- hostname: zod_1.default.string().optional(),
- port: zod_1.default.string().optional(),
- pathname: zod_1.default.string().optional(),
- search: zod_1.default.string().optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.UrlPatternStringSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('string'),
- pattern: zod_1.default.string(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.AddInterceptParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- phases: zod_1.default.array(Network.InterceptPhaseSchema).min(1),
- contexts: zod_1.default
- .array(BrowsingContext.BrowsingContextSchema)
- .min(1)
- .optional(),
- urlPatterns: zod_1.default.array(Network.UrlPatternSchema).optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.AddInterceptSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.addIntercept'),
- params: Network.AddInterceptParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.InterceptPhaseSchema = zod_1.default.lazy(() => zod_1.default.enum(['beforeRequestSent', 'responseStarted', 'authRequired']));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.AddInterceptResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- intercept: Network.InterceptSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueRequestSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.continueRequest'),
- params: Network.ContinueRequestParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueRequestParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- request: Network.RequestSchema,
- body: Network.BytesValueSchema.optional(),
- cookies: zod_1.default.array(Network.CookieHeaderSchema).optional(),
- headers: zod_1.default.array(Network.HeaderSchema).optional(),
- method: zod_1.default.string().optional(),
- url: zod_1.default.string().optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueResponseSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.continueResponse'),
- params: Network.ContinueResponseParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueResponseParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- request: Network.RequestSchema,
- cookies: zod_1.default.array(Network.SetCookieHeaderSchema).optional(),
- credentials: Network.AuthCredentialsSchema.optional(),
- headers: zod_1.default.array(Network.HeaderSchema).optional(),
- reasonPhrase: zod_1.default.string().optional(),
- statusCode: exports.JsUintSchema.optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueWithAuthSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.continueWithAuth'),
- params: Network.ContinueWithAuthParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueWithAuthParametersSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- request: Network.RequestSchema,
- })
- .and(zod_1.default.union([
- Network.ContinueWithAuthCredentialsSchema,
- Network.ContinueWithAuthNoCredentialsSchema,
- ])));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueWithAuthCredentialsSchema = zod_1.default.lazy(() => zod_1.default.object({
- action: zod_1.default.literal('provideCredentials'),
- credentials: Network.AuthCredentialsSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ContinueWithAuthNoCredentialsSchema = zod_1.default.lazy(() => zod_1.default.object({
- action: zod_1.default.enum(['default', 'cancel']),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.FailRequestSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.failRequest'),
- params: Network.FailRequestParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.FailRequestParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- request: Network.RequestSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ProvideResponseSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.provideResponse'),
- params: Network.ProvideResponseParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ProvideResponseParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- request: Network.RequestSchema,
- body: Network.BytesValueSchema.optional(),
- cookies: zod_1.default.array(Network.SetCookieHeaderSchema).optional(),
- headers: zod_1.default.array(Network.HeaderSchema).optional(),
- reasonPhrase: zod_1.default.string().optional(),
- statusCode: exports.JsUintSchema.optional(),
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.RemoveInterceptSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.removeIntercept'),
- params: Network.RemoveInterceptParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.RemoveInterceptParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- intercept: Network.InterceptSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- exports.ScriptEventSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.MessageSchema,
- Script.RealmCreatedSchema,
- Script.RealmDestroyedSchema,
- ]));
- (function (Network) {
- Network.AuthRequiredParametersSchema = zod_1.default.lazy(() => Network.BaseParametersSchema.and(zod_1.default.object({
- response: Network.ResponseDataSchema,
- })));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.BeforeRequestSentParametersSchema = zod_1.default.lazy(() => Network.BaseParametersSchema.and(zod_1.default.object({
- initiator: Network.InitiatorSchema,
- })));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.FetchErrorParametersSchema = zod_1.default.lazy(() => Network.BaseParametersSchema.and(zod_1.default.object({
- errorText: zod_1.default.string(),
- })));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseCompletedParametersSchema = zod_1.default.lazy(() => Network.BaseParametersSchema.and(zod_1.default.object({
- response: Network.ResponseDataSchema,
- })));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseStartedParametersSchema = zod_1.default.lazy(() => Network.BaseParametersSchema.and(zod_1.default.object({
- response: Network.ResponseDataSchema,
- })));
- })(Network || (exports.Network = Network = {}));
- exports.ScriptCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.AddPreloadScriptSchema,
- Script.CallFunctionSchema,
- Script.DisownSchema,
- Script.EvaluateSchema,
- Script.GetRealmsSchema,
- Script.RemovePreloadScriptSchema,
- ]));
- exports.ScriptResultSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.AddPreloadScriptResultSchema,
- Script.EvaluateResultSchema,
- Script.GetRealmsResultSchema,
- ]));
- (function (Network) {
- Network.AuthRequiredSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.authRequired'),
- params: Network.AuthRequiredParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.BeforeRequestSentSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.beforeRequestSent'),
- params: Network.BeforeRequestSentParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.FetchErrorSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.fetchError'),
- params: Network.FetchErrorParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseCompletedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.responseCompleted'),
- params: Network.ResponseCompletedParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- (function (Network) {
- Network.ResponseStartedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('network.responseStarted'),
- params: Network.ResponseStartedParametersSchema,
- }));
- })(Network || (exports.Network = Network = {}));
- var Script;
- (function (Script) {
- Script.ChannelSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.EvaluateResultSuccessSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('success'),
- result: Script.RemoteValueSchema,
- realm: Script.RealmSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ExceptionDetailsSchema = zod_1.default.lazy(() => zod_1.default.object({
- columnNumber: exports.JsUintSchema,
- exception: Script.RemoteValueSchema,
- lineNumber: exports.JsUintSchema,
- stackTrace: Script.StackTraceSchema,
- text: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ChannelValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('channel'),
- value: Script.ChannelPropertiesSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ChannelPropertiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- channel: Script.ChannelSchema,
- serializationOptions: Script.SerializationOptionsSchema.optional(),
- ownership: Script.ResultOwnershipSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.EvaluateResultSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.EvaluateResultSuccessSchema,
- Script.EvaluateResultExceptionSchema,
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.EvaluateResultExceptionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('exception'),
- exceptionDetails: Script.ExceptionDetailsSchema,
- realm: Script.RealmSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.HandleSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.InternalIdSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ListLocalValueSchema = zod_1.default.lazy(() => zod_1.default.array(Script.LocalValueSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.LocalValueSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.RemoteReferenceSchema,
- Script.PrimitiveProtocolValueSchema,
- Script.ChannelValueSchema,
- Script.ArrayLocalValueSchema,
- Script.DateLocalValueSchema,
- Script.MapLocalValueSchema,
- Script.ObjectLocalValueSchema,
- Script.RegExpLocalValueSchema,
- Script.SetLocalValueSchema,
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ArrayLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('array'),
- value: Script.ListLocalValueSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.DateLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('date'),
- value: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MappingLocalValueSchema = zod_1.default.lazy(() => zod_1.default.array(zod_1.default.tuple([
- zod_1.default.union([Script.LocalValueSchema, zod_1.default.string()]),
- Script.LocalValueSchema,
- ])));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MapLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('map'),
- value: Script.MappingLocalValueSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ObjectLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('object'),
- value: Script.MappingLocalValueSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RegExpValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- pattern: zod_1.default.string(),
- flags: zod_1.default.string().optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RegExpLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('regexp'),
- value: Script.RegExpValueSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SetLocalValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('set'),
- value: Script.ListLocalValueSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.PreloadScriptSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.PrimitiveProtocolValueSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.UndefinedValueSchema,
- Script.NullValueSchema,
- Script.StringValueSchema,
- Script.NumberValueSchema,
- Script.BooleanValueSchema,
- Script.BigIntValueSchema,
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.UndefinedValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('undefined'),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.NullValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('null'),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.StringValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('string'),
- value: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SpecialNumberSchema = zod_1.default.lazy(() => zod_1.default.enum(['NaN', '-0', 'Infinity', '-Infinity']));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.NumberValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('number'),
- value: zod_1.default.union([zod_1.default.number(), Script.SpecialNumberSchema]),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.BooleanValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('boolean'),
- value: zod_1.default.boolean(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.BigIntValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('bigint'),
- value: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmInfoSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.WindowRealmInfoSchema,
- Script.DedicatedWorkerRealmInfoSchema,
- Script.SharedWorkerRealmInfoSchema,
- Script.ServiceWorkerRealmInfoSchema,
- Script.WorkerRealmInfoSchema,
- Script.PaintWorkletRealmInfoSchema,
- Script.AudioWorkletRealmInfoSchema,
- Script.WorkletRealmInfoSchema,
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.BaseRealmInfoSchema = zod_1.default.lazy(() => zod_1.default.object({
- realm: Script.RealmSchema,
- origin: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WindowRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('window'),
- context: BrowsingContext.BrowsingContextSchema,
- sandbox: zod_1.default.string().optional(),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.DedicatedWorkerRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('dedicated-worker'),
- owners: zod_1.default.tuple([Script.RealmSchema]),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SharedWorkerRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('shared-worker'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ServiceWorkerRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('service-worker'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WorkerRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('worker'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.PaintWorkletRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('paint-worklet'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.AudioWorkletRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('audio-worklet'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WorkletRealmInfoSchema = zod_1.default.lazy(() => Script.BaseRealmInfoSchema.and(zod_1.default.object({
- type: zod_1.default.literal('worklet'),
- })));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmTypeSchema = zod_1.default.lazy(() => zod_1.default.enum([
- 'window',
- 'dedicated-worker',
- 'shared-worker',
- 'service-worker',
- 'worker',
- 'paint-worklet',
- 'audio-worklet',
- 'worklet',
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ListRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.array(Script.RemoteValueSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MappingRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.array(zod_1.default.tuple([
- zod_1.default.union([Script.RemoteValueSchema, zod_1.default.string()]),
- Script.RemoteValueSchema,
- ])));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RemoteValueSchema = zod_1.default.lazy(() => zod_1.default.union([
- Script.PrimitiveProtocolValueSchema,
- Script.SymbolRemoteValueSchema,
- Script.ArrayRemoteValueSchema,
- Script.ObjectRemoteValueSchema,
- Script.FunctionRemoteValueSchema,
- Script.RegExpRemoteValueSchema,
- Script.DateRemoteValueSchema,
- Script.MapRemoteValueSchema,
- Script.SetRemoteValueSchema,
- Script.WeakMapRemoteValueSchema,
- Script.WeakSetRemoteValueSchema,
- Script.GeneratorRemoteValueSchema,
- Script.ErrorRemoteValueSchema,
- Script.ProxyRemoteValueSchema,
- Script.PromiseRemoteValueSchema,
- Script.TypedArrayRemoteValueSchema,
- Script.ArrayBufferRemoteValueSchema,
- Script.NodeListRemoteValueSchema,
- Script.HtmlCollectionRemoteValueSchema,
- Script.NodeRemoteValueSchema,
- Script.WindowProxyRemoteValueSchema,
- ]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RemoteReferenceSchema = zod_1.default.lazy(() => zod_1.default.union([Script.SharedReferenceSchema, Script.RemoteObjectReferenceSchema]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SharedReferenceSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- sharedId: Script.SharedIdSchema,
- handle: Script.HandleSchema.optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RemoteObjectReferenceSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- handle: Script.HandleSchema,
- sharedId: Script.SharedIdSchema.optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SymbolRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('symbol'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ArrayRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('array'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.ListRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ObjectRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('object'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.MappingRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.FunctionRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('function'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RegExpRemoteValueSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- })
- .and(Script.RegExpLocalValueSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.DateRemoteValueSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- })
- .and(Script.DateLocalValueSchema));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MapRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('map'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.MappingRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SetRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('set'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.ListRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WeakMapRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('weakmap'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WeakSetRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('weakset'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.GeneratorRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('generator'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ErrorRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('error'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ProxyRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('proxy'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.PromiseRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('promise'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.TypedArrayRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('typedarray'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ArrayBufferRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('arraybuffer'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.NodeListRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('nodelist'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.ListRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.HtmlCollectionRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('htmlcollection'),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.ListRemoteValueSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.NodeRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('node'),
- sharedId: Script.SharedIdSchema.optional(),
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- value: Script.NodePropertiesSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.NodePropertiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- nodeType: exports.JsUintSchema,
- childNodeCount: exports.JsUintSchema,
- attributes: zod_1.default.record(zod_1.default.string(), zod_1.default.string()).optional(),
- children: zod_1.default.array(Script.NodeRemoteValueSchema).optional(),
- localName: zod_1.default.string().optional(),
- mode: zod_1.default.enum(['open', 'closed']).optional(),
- namespaceURI: zod_1.default.string().optional(),
- nodeValue: zod_1.default.string().optional(),
- shadowRoot: zod_1.default.union([Script.NodeRemoteValueSchema, zod_1.default.null()]).optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WindowProxyRemoteValueSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('window'),
- value: Script.WindowProxyPropertiesSchema,
- handle: Script.HandleSchema.optional(),
- internalId: Script.InternalIdSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.WindowProxyPropertiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ResultOwnershipSchema = zod_1.default.lazy(() => zod_1.default.enum(['root', 'none']));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SerializationOptionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- maxDomDepth: zod_1.default.union([exports.JsUintSchema, zod_1.default.null()]).default(0).optional(),
- maxObjectDepth: zod_1.default
- .union([exports.JsUintSchema, zod_1.default.null()])
- .default(null)
- .optional(),
- includeShadowTree: zod_1.default
- .enum(['none', 'open', 'all'])
- .default('none')
- .optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SharedIdSchema = zod_1.default.lazy(() => zod_1.default.string());
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.StackFrameSchema = zod_1.default.lazy(() => zod_1.default.object({
- columnNumber: exports.JsUintSchema,
- functionName: zod_1.default.string(),
- lineNumber: exports.JsUintSchema,
- url: zod_1.default.string(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.StackTraceSchema = zod_1.default.lazy(() => zod_1.default.object({
- callFrames: zod_1.default.array(Script.StackFrameSchema),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.SourceSchema = zod_1.default.lazy(() => zod_1.default.object({
- realm: Script.RealmSchema,
- context: BrowsingContext.BrowsingContextSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmTargetSchema = zod_1.default.lazy(() => zod_1.default.object({
- realm: Script.RealmSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.ContextTargetSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- sandbox: zod_1.default.string().optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.TargetSchema = zod_1.default.lazy(() => zod_1.default.union([Script.ContextTargetSchema, Script.RealmTargetSchema]));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.AddPreloadScriptSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.addPreloadScript'),
- params: Script.AddPreloadScriptParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.AddPreloadScriptParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- functionDeclaration: zod_1.default.string(),
- arguments: zod_1.default.array(Script.ChannelValueSchema).optional(),
- contexts: zod_1.default
- .array(BrowsingContext.BrowsingContextSchema)
- .min(1)
- .optional(),
- sandbox: zod_1.default.string().optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.AddPreloadScriptResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- script: Script.PreloadScriptSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.DisownSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.disown'),
- params: Script.DisownParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.DisownParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- handles: zod_1.default.array(Script.HandleSchema),
- target: Script.TargetSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.CallFunctionParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- functionDeclaration: zod_1.default.string(),
- awaitPromise: zod_1.default.boolean(),
- target: Script.TargetSchema,
- arguments: zod_1.default.array(Script.LocalValueSchema).optional(),
- resultOwnership: Script.ResultOwnershipSchema.optional(),
- serializationOptions: Script.SerializationOptionsSchema.optional(),
- this: Script.LocalValueSchema.optional(),
- userActivation: zod_1.default.boolean().default(false).optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.CallFunctionSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.callFunction'),
- params: Script.CallFunctionParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.EvaluateSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.evaluate'),
- params: Script.EvaluateParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.EvaluateParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- expression: zod_1.default.string(),
- target: Script.TargetSchema,
- awaitPromise: zod_1.default.boolean(),
- resultOwnership: Script.ResultOwnershipSchema.optional(),
- serializationOptions: Script.SerializationOptionsSchema.optional(),
- userActivation: zod_1.default.boolean().default(false).optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.GetRealmsSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.getRealms'),
- params: Script.GetRealmsParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.GetRealmsParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema.optional(),
- type: Script.RealmTypeSchema.optional(),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.GetRealmsResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- realms: zod_1.default.array(Script.RealmInfoSchema),
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RemovePreloadScriptSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.removePreloadScript'),
- params: Script.RemovePreloadScriptParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RemovePreloadScriptParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- script: Script.PreloadScriptSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MessageParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- channel: Script.ChannelSchema,
- data: Script.RemoteValueSchema,
- source: Script.SourceSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmCreatedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.realmCreated'),
- params: Script.RealmInfoSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.MessageSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.message'),
- params: Script.MessageParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmDestroyedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('script.realmDestroyed'),
- params: Script.RealmDestroyedParametersSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- (function (Script) {
- Script.RealmDestroyedParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- realm: Script.RealmSchema,
- }));
- })(Script || (exports.Script = Script = {}));
- exports.StorageCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Storage.DeleteCookiesSchema,
- Storage.GetCookiesSchema,
- Storage.SetCookieSchema,
- ]));
- exports.StorageResultSchema = zod_1.default.lazy(() => zod_1.default.union([
- Storage.DeleteCookiesResultSchema,
- Storage.GetCookiesResultSchema,
- Storage.SetCookieResultSchema,
- ]));
- var Storage;
- (function (Storage) {
- Storage.PartitionKeySchema = zod_1.default.lazy(() => zod_1.default
- .object({
- userContext: zod_1.default.string().optional(),
- sourceOrigin: zod_1.default.string().optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.GetCookiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('storage.getCookies'),
- params: Storage.GetCookiesParametersSchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.CookieFilterSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- name: zod_1.default.string().optional(),
- value: Network.BytesValueSchema.optional(),
- domain: zod_1.default.string().optional(),
- path: zod_1.default.string().optional(),
- size: exports.JsUintSchema.optional(),
- httpOnly: zod_1.default.boolean().optional(),
- secure: zod_1.default.boolean().optional(),
- sameSite: Network.SameSiteSchema.optional(),
- expiry: exports.JsUintSchema.optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.BrowsingContextPartitionDescriptorSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('context'),
- context: BrowsingContext.BrowsingContextSchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.StorageKeyPartitionDescriptorSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('storageKey'),
- userContext: zod_1.default.string().optional(),
- sourceOrigin: zod_1.default.string().optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.PartitionDescriptorSchema = zod_1.default.lazy(() => zod_1.default.union([
- Storage.BrowsingContextPartitionDescriptorSchema,
- Storage.StorageKeyPartitionDescriptorSchema,
- ]));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.GetCookiesParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- filter: Storage.CookieFilterSchema.optional(),
- partition: Storage.PartitionDescriptorSchema.optional(),
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.GetCookiesResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- cookies: zod_1.default.array(Network.CookieSchema),
- partitionKey: Storage.PartitionKeySchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.SetCookieSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('storage.setCookie'),
- params: Storage.SetCookieParametersSchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.PartialCookieSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- name: zod_1.default.string(),
- value: Network.BytesValueSchema,
- domain: zod_1.default.string(),
- path: zod_1.default.string().optional(),
- httpOnly: zod_1.default.boolean().optional(),
- secure: zod_1.default.boolean().optional(),
- sameSite: Network.SameSiteSchema.optional(),
- expiry: exports.JsUintSchema.optional(),
- })
- .and(exports.ExtensibleSchema));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.SetCookieParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- cookie: Storage.PartialCookieSchema,
- partition: Storage.PartitionDescriptorSchema.optional(),
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.SetCookieResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- partitionKey: Storage.PartitionKeySchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.DeleteCookiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('storage.deleteCookies'),
- params: Storage.DeleteCookiesParametersSchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.DeleteCookiesParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- filter: Storage.CookieFilterSchema.optional(),
- partition: Storage.PartitionDescriptorSchema.optional(),
- }));
- })(Storage || (exports.Storage = Storage = {}));
- (function (Storage) {
- Storage.DeleteCookiesResultSchema = zod_1.default.lazy(() => zod_1.default.object({
- partitionKey: Storage.PartitionKeySchema,
- }));
- })(Storage || (exports.Storage = Storage = {}));
- exports.LogEventSchema = zod_1.default.lazy(() => Log.EntryAddedSchema);
- var Log;
- (function (Log) {
- Log.LevelSchema = zod_1.default.lazy(() => zod_1.default.enum(['debug', 'info', 'warn', 'error']));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.EntrySchema = zod_1.default.lazy(() => zod_1.default.union([
- Log.GenericLogEntrySchema,
- Log.ConsoleLogEntrySchema,
- Log.JavascriptLogEntrySchema,
- ]));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.BaseLogEntrySchema = zod_1.default.lazy(() => zod_1.default.object({
- level: Log.LevelSchema,
- source: Script.SourceSchema,
- text: zod_1.default.union([zod_1.default.string(), zod_1.default.null()]),
- timestamp: exports.JsUintSchema,
- stackTrace: Script.StackTraceSchema.optional(),
- }));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.GenericLogEntrySchema = zod_1.default.lazy(() => Log.BaseLogEntrySchema.and(zod_1.default.object({
- type: zod_1.default.string(),
- })));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.ConsoleLogEntrySchema = zod_1.default.lazy(() => Log.BaseLogEntrySchema.and(zod_1.default.object({
- type: zod_1.default.literal('console'),
- method: zod_1.default.string(),
- args: zod_1.default.array(Script.RemoteValueSchema),
- })));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.JavascriptLogEntrySchema = zod_1.default.lazy(() => Log.BaseLogEntrySchema.and(zod_1.default.object({
- type: zod_1.default.literal('javascript'),
- })));
- })(Log || (exports.Log = Log = {}));
- (function (Log) {
- Log.EntryAddedSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('log.entryAdded'),
- params: Log.EntrySchema,
- }));
- })(Log || (exports.Log = Log = {}));
- exports.InputCommandSchema = zod_1.default.lazy(() => zod_1.default.union([
- Input.PerformActionsSchema,
- Input.ReleaseActionsSchema,
- Input.SetFilesSchema,
- ]));
- var Input;
- (function (Input) {
- Input.ElementOriginSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('element'),
- element: Script.SharedReferenceSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PerformActionsParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- actions: zod_1.default.array(Input.SourceActionsSchema),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.NoneSourceActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('none'),
- id: zod_1.default.string(),
- actions: zod_1.default.array(Input.NoneSourceActionSchema),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.KeySourceActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('key'),
- id: zod_1.default.string(),
- actions: zod_1.default.array(Input.KeySourceActionSchema),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerSourceActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('pointer'),
- id: zod_1.default.string(),
- parameters: Input.PointerParametersSchema.optional(),
- actions: zod_1.default.array(Input.PointerSourceActionSchema),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PerformActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('input.performActions'),
- params: Input.PerformActionsParametersSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.SourceActionsSchema = zod_1.default.lazy(() => zod_1.default.union([
- Input.NoneSourceActionsSchema,
- Input.KeySourceActionsSchema,
- Input.PointerSourceActionsSchema,
- Input.WheelSourceActionsSchema,
- ]));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.NoneSourceActionSchema = zod_1.default.lazy(() => Input.PauseActionSchema);
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.KeySourceActionSchema = zod_1.default.lazy(() => zod_1.default.union([
- Input.PauseActionSchema,
- Input.KeyDownActionSchema,
- Input.KeyUpActionSchema,
- ]));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerTypeSchema = zod_1.default.lazy(() => zod_1.default.enum(['mouse', 'pen', 'touch']));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- pointerType: Input.PointerTypeSchema.default('mouse').optional(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.WheelSourceActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('wheel'),
- id: zod_1.default.string(),
- actions: zod_1.default.array(Input.WheelSourceActionSchema),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerSourceActionSchema = zod_1.default.lazy(() => zod_1.default.union([
- Input.PauseActionSchema,
- Input.PointerDownActionSchema,
- Input.PointerUpActionSchema,
- Input.PointerMoveActionSchema,
- ]));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.WheelSourceActionSchema = zod_1.default.lazy(() => zod_1.default.union([Input.PauseActionSchema, Input.WheelScrollActionSchema]));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PauseActionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('pause'),
- duration: exports.JsUintSchema.optional(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.KeyDownActionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('keyDown'),
- value: zod_1.default.string(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.KeyUpActionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('keyUp'),
- value: zod_1.default.string(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerUpActionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('pointerUp'),
- button: exports.JsUintSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerDownActionSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('pointerDown'),
- button: exports.JsUintSchema,
- })
- .and(Input.PointerCommonPropertiesSchema));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerMoveActionSchema = zod_1.default.lazy(() => zod_1.default
- .object({
- type: zod_1.default.literal('pointerMove'),
- x: exports.JsIntSchema,
- y: exports.JsIntSchema,
- duration: exports.JsUintSchema.optional(),
- origin: Input.OriginSchema.optional(),
- })
- .and(Input.PointerCommonPropertiesSchema));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.WheelScrollActionSchema = zod_1.default.lazy(() => zod_1.default.object({
- type: zod_1.default.literal('scroll'),
- x: exports.JsIntSchema,
- y: exports.JsIntSchema,
- deltaX: exports.JsIntSchema,
- deltaY: exports.JsIntSchema,
- duration: exports.JsUintSchema.optional(),
- origin: Input.OriginSchema.default('viewport').optional(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.PointerCommonPropertiesSchema = zod_1.default.lazy(() => zod_1.default.object({
- width: exports.JsUintSchema.default(1).optional(),
- height: exports.JsUintSchema.default(1).optional(),
- pressure: zod_1.default.number().default(0).optional(),
- tangentialPressure: zod_1.default.number().default(0).optional(),
- twist: zod_1.default
- .number()
- .int()
- .nonnegative()
- .gte(0)
- .lte(359)
- .default(0)
- .optional(),
- altitudeAngle: zod_1.default
- .number()
- .gte(0)
- .lte(1.5707963267948966)
- .default(0)
- .optional(),
- azimuthAngle: zod_1.default
- .number()
- .gte(0)
- .lte(6.283185307179586)
- .default(0)
- .optional(),
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.OriginSchema = zod_1.default.lazy(() => zod_1.default.union([
- zod_1.default.literal('viewport'),
- zod_1.default.literal('pointer'),
- Input.ElementOriginSchema,
- ]));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.ReleaseActionsSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('input.releaseActions'),
- params: Input.ReleaseActionsParametersSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.ReleaseActionsParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.SetFilesSchema = zod_1.default.lazy(() => zod_1.default.object({
- method: zod_1.default.literal('input.setFiles'),
- params: Input.SetFilesParametersSchema,
- }));
- })(Input || (exports.Input = Input = {}));
- (function (Input) {
- Input.SetFilesParametersSchema = zod_1.default.lazy(() => zod_1.default.object({
- context: BrowsingContext.BrowsingContextSchema,
- element: Script.SharedReferenceSchema,
- files: zod_1.default.array(zod_1.default.string()),
- }));
- })(Input || (exports.Input = Input = {}));
-
- } (webdriverBidi));
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- var __createBinding$1 = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- var desc = Object.getOwnPropertyDescriptor(m, k);
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
- desc = { enumerable: true, get: function() { return m[k]; } };
- }
- Object.defineProperty(o, k2, desc);
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault$1 = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar$1 = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding$1(result, mod, k);
- __setModuleDefault$1(result, mod);
- return result;
- };
- Object.defineProperty(protocolParser, "__esModule", { value: true });
- protocolParser.Permissions = protocolParser.Cdp = protocolParser.Storage = protocolParser.Input = protocolParser.Session = protocolParser.BrowsingContext = protocolParser.Script = protocolParser.Network = protocolParser.Browser = protocolParser.parseObject = void 0;
- /**
- * @fileoverview Provides parsing and validator for WebDriver BiDi protocol.
- * Parser types should match the `../protocol` types.
- */
- const zod_1 = lib;
- const protocol_js_1 = protocol;
- const WebDriverBidiPermissions = __importStar$1(webdriverBidiPermissions);
- const WebDriverBidi = __importStar$1(webdriverBidi);
- function parseObject(obj, schema) {
- const parseResult = schema.safeParse(obj);
- if (parseResult.success) {
- return parseResult.data;
- }
- const errorMessage = parseResult.error.errors
- .map((e) => `${e.message} in ` +
- `${e.path.map((p) => JSON.stringify(p)).join('/')}.`)
- .join(' ');
- throw new protocol_js_1.InvalidArgumentException(errorMessage);
- }
- protocolParser.parseObject = parseObject;
- /** @see https://w3c.github.io/webdriver-bidi/#module-browser */
- var Browser;
- (function (Browser) {
- function parseRemoveUserContextParams(params) {
- return parseObject(params, WebDriverBidi.Browser.RemoveUserContextParametersSchema);
- }
- Browser.parseRemoveUserContextParams = parseRemoveUserContextParams;
- })(Browser || (protocolParser.Browser = Browser = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-network */
- var Network;
- (function (Network) {
- function parseAddInterceptParameters(params) {
- // Work around of `cddlconv` https://github.com/google/cddlconv/issues/19.
- return parseObject(params, WebDriverBidi.Network.AddInterceptParametersSchema);
- }
- Network.parseAddInterceptParameters = parseAddInterceptParameters;
- function parseContinueRequestParameters(params) {
- return parseObject(params, WebDriverBidi.Network.ContinueRequestParametersSchema);
- }
- Network.parseContinueRequestParameters = parseContinueRequestParameters;
- function parseContinueResponseParameters(params) {
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.Network.ContinueResponseParametersSchema);
- }
- Network.parseContinueResponseParameters = parseContinueResponseParameters;
- function parseContinueWithAuthParameters(params) {
- return parseObject(params, WebDriverBidi.Network.ContinueWithAuthParametersSchema);
- }
- Network.parseContinueWithAuthParameters = parseContinueWithAuthParameters;
- function parseFailRequestParameters(params) {
- return parseObject(params, WebDriverBidi.Network.FailRequestParametersSchema);
- }
- Network.parseFailRequestParameters = parseFailRequestParameters;
- function parseProvideResponseParameters(params) {
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.Network.ProvideResponseParametersSchema);
- }
- Network.parseProvideResponseParameters = parseProvideResponseParameters;
- function parseRemoveInterceptParameters(params) {
- return parseObject(params, WebDriverBidi.Network.RemoveInterceptParametersSchema);
- }
- Network.parseRemoveInterceptParameters = parseRemoveInterceptParameters;
- })(Network || (protocolParser.Network = Network = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-script */
- var Script;
- (function (Script) {
- function parseGetRealmsParams(params) {
- return parseObject(params, WebDriverBidi.Script.GetRealmsParametersSchema);
- }
- Script.parseGetRealmsParams = parseGetRealmsParams;
- function parseEvaluateParams(params) {
- return parseObject(params, WebDriverBidi.Script.EvaluateParametersSchema);
- }
- Script.parseEvaluateParams = parseEvaluateParams;
- function parseDisownParams(params) {
- return parseObject(params, WebDriverBidi.Script.DisownParametersSchema);
- }
- Script.parseDisownParams = parseDisownParams;
- function parseAddPreloadScriptParams(params) {
- return parseObject(params, WebDriverBidi.Script.AddPreloadScriptParametersSchema);
- }
- Script.parseAddPreloadScriptParams = parseAddPreloadScriptParams;
- function parseRemovePreloadScriptParams(params) {
- return parseObject(params, WebDriverBidi.Script.RemovePreloadScriptParametersSchema);
- }
- Script.parseRemovePreloadScriptParams = parseRemovePreloadScriptParams;
- function parseCallFunctionParams(params) {
- return parseObject(params, WebDriverBidi.Script.CallFunctionParametersSchema);
- }
- Script.parseCallFunctionParams = parseCallFunctionParams;
- })(Script || (protocolParser.Script = Script = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-browsingContext */
- var BrowsingContext;
- (function (BrowsingContext) {
- function parseActivateParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.ActivateParametersSchema);
- }
- BrowsingContext.parseActivateParams = parseActivateParams;
- function parseGetTreeParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.GetTreeParametersSchema);
- }
- BrowsingContext.parseGetTreeParams = parseGetTreeParams;
- function parseNavigateParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.NavigateParametersSchema);
- }
- BrowsingContext.parseNavigateParams = parseNavigateParams;
- function parseReloadParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.ReloadParametersSchema);
- }
- BrowsingContext.parseReloadParams = parseReloadParams;
- function parseCreateParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.CreateParametersSchema);
- }
- BrowsingContext.parseCreateParams = parseCreateParams;
- function parseCloseParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.CloseParametersSchema);
- }
- BrowsingContext.parseCloseParams = parseCloseParams;
- function parseCaptureScreenshotParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.CaptureScreenshotParametersSchema);
- }
- BrowsingContext.parseCaptureScreenshotParams = parseCaptureScreenshotParams;
- function parsePrintParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.PrintParametersSchema);
- }
- BrowsingContext.parsePrintParams = parsePrintParams;
- function parseSetViewportParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.SetViewportParametersSchema);
- }
- BrowsingContext.parseSetViewportParams = parseSetViewportParams;
- function parseTraverseHistoryParams(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.TraverseHistoryParametersSchema);
- }
- BrowsingContext.parseTraverseHistoryParams = parseTraverseHistoryParams;
- function parseHandleUserPromptParameters(params) {
- return parseObject(params, WebDriverBidi.BrowsingContext.HandleUserPromptParametersSchema);
- }
- BrowsingContext.parseHandleUserPromptParameters = parseHandleUserPromptParameters;
- function parseLocateNodesParams(params) {
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.BrowsingContext.LocateNodesParametersSchema);
- }
- BrowsingContext.parseLocateNodesParams = parseLocateNodesParams;
- })(BrowsingContext || (protocolParser.BrowsingContext = BrowsingContext = {}));
- /** @see https://w3c.github.io/webdriver-bidi/#module-session */
- var Session;
- (function (Session) {
- function parseSubscribeParams(params) {
- return parseObject(params, WebDriverBidi.Session.SubscriptionRequestSchema);
- }
- Session.parseSubscribeParams = parseSubscribeParams;
- })(Session || (protocolParser.Session = Session = {}));
- var Input;
- (function (Input) {
- function parsePerformActionsParams(params) {
- return parseObject(params, WebDriverBidi.Input.PerformActionsParametersSchema);
- }
- Input.parsePerformActionsParams = parsePerformActionsParams;
- function parseReleaseActionsParams(params) {
- return parseObject(params, WebDriverBidi.Input.ReleaseActionsParametersSchema);
- }
- Input.parseReleaseActionsParams = parseReleaseActionsParams;
- function parseSetFilesParams(params) {
- return parseObject(params, WebDriverBidi.Input.SetFilesParametersSchema);
- }
- Input.parseSetFilesParams = parseSetFilesParams;
- })(Input || (protocolParser.Input = Input = {}));
- var Storage;
- (function (Storage) {
- function parseGetCookiesParams(params) {
- // Work around of `cddlconv` https://github.com/google/cddlconv/issues/19.
- // The generated schema `SameSiteSchema` in `src/protocol-parser/webdriver-bidi.ts` is
- // of type `"none" | "strict" | "lax"` which is not assignable to generated enum
- // `SameSite` in `src/protocol/webdriver-bidi.ts`.
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.Storage.GetCookiesParametersSchema);
- }
- Storage.parseGetCookiesParams = parseGetCookiesParams;
- function parseSetCookieParams(params) {
- // Work around of `cddlconv` https://github.com/google/cddlconv/issues/19.
- // The generated schema `SameSiteSchema` in `src/protocol-parser/webdriver-bidi.ts` is
- // of type `"none" | "strict" | "lax"` which is not assignable to generated enum
- // `SameSite` in `src/protocol/webdriver-bidi.ts`.
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.Storage.SetCookieParametersSchema);
- }
- Storage.parseSetCookieParams = parseSetCookieParams;
- function parseDeleteCookiesParams(params) {
- // Work around of `cddlconv` https://github.com/google/cddlconv/issues/19.
- // The generated schema `SameSiteSchema` in `src/protocol-parser/webdriver-bidi.ts` is
- // of type `"none" | "strict" | "lax"` which is not assignable to generated enum
- // `SameSite` in `src/protocol/webdriver-bidi.ts`.
- // TODO: remove cast after https://github.com/google/cddlconv/issues/19 is fixed.
- return parseObject(params, WebDriverBidi.Storage.DeleteCookiesParametersSchema);
- }
- Storage.parseDeleteCookiesParams = parseDeleteCookiesParams;
- })(Storage || (protocolParser.Storage = Storage = {}));
- var Cdp;
- (function (Cdp) {
- const SendCommandRequestSchema = zod_1.z.object({
- // Allowing any cdpMethod, and casting to proper type later on.
- method: zod_1.z.string(),
- // `passthrough` allows object to have any fields.
- // https://github.com/colinhacks/zod#passthrough
- params: zod_1.z.object({}).passthrough().optional(),
- session: zod_1.z.string().optional(),
- });
- const GetSessionRequestSchema = zod_1.z.object({
- context: WebDriverBidi.BrowsingContext.BrowsingContextSchema,
- });
- const ResolveRealmRequestSchema = zod_1.z.object({
- realm: WebDriverBidi.Script.RealmSchema,
- });
- function parseSendCommandRequest(params) {
- return parseObject(params, SendCommandRequestSchema);
- }
- Cdp.parseSendCommandRequest = parseSendCommandRequest;
- function parseGetSessionRequest(params) {
- return parseObject(params, GetSessionRequestSchema);
- }
- Cdp.parseGetSessionRequest = parseGetSessionRequest;
- function parseResolveRealmRequest(params) {
- return parseObject(params, ResolveRealmRequestSchema);
- }
- Cdp.parseResolveRealmRequest = parseResolveRealmRequest;
- })(Cdp || (protocolParser.Cdp = Cdp = {}));
- var Permissions;
- (function (Permissions) {
- function parseSetPermissionsParams(params) {
- return {
- // TODO: remove once "goog:" attributes are not needed.
- ...params,
- ...parseObject(params, WebDriverBidiPermissions.Permissions.SetPermissionParametersSchema),
- };
- }
- Permissions.parseSetPermissionsParams = parseSetPermissionsParams;
- })(Permissions || (protocolParser.Permissions = Permissions = {}));
- var __createBinding = (commonjsGlobal && commonjsGlobal.__createBinding) || (Object.create ? (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- var desc = Object.getOwnPropertyDescriptor(m, k);
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
- desc = { enumerable: true, get: function() { return m[k]; } };
- }
- Object.defineProperty(o, k2, desc);
- }) : (function(o, m, k, k2) {
- if (k2 === undefined) k2 = k;
- o[k2] = m[k];
- }));
- var __setModuleDefault = (commonjsGlobal && commonjsGlobal.__setModuleDefault) || (Object.create ? (function(o, v) {
- Object.defineProperty(o, "default", { enumerable: true, value: v });
- }) : function(o, v) {
- o["default"] = v;
- });
- var __importStar = (commonjsGlobal && commonjsGlobal.__importStar) || function (mod) {
- if (mod && mod.__esModule) return mod;
- var result = {};
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
- __setModuleDefault(result, mod);
- return result;
- };
- Object.defineProperty(BidiParser$1, "__esModule", { value: true });
- BidiParser$1.BidiParser = void 0;
- const Parser = __importStar(protocolParser);
- class BidiParser {
- // Browser domain
- // keep-sorted start block=yes
- parseRemoveUserContextParams(params) {
- return Parser.Browser.parseRemoveUserContextParams(params);
- }
- // keep-sorted end
- // Browsing Context domain
- // keep-sorted start block=yes
- parseActivateParams(params) {
- return Parser.BrowsingContext.parseActivateParams(params);
- }
- parseCaptureScreenshotParams(params) {
- return Parser.BrowsingContext.parseCaptureScreenshotParams(params);
- }
- parseCloseParams(params) {
- return Parser.BrowsingContext.parseCloseParams(params);
- }
- parseCreateParams(params) {
- return Parser.BrowsingContext.parseCreateParams(params);
- }
- parseGetTreeParams(params) {
- return Parser.BrowsingContext.parseGetTreeParams(params);
- }
- parseHandleUserPromptParams(params) {
- return Parser.BrowsingContext.parseHandleUserPromptParameters(params);
- }
- parseLocateNodesParams(params) {
- return Parser.BrowsingContext.parseLocateNodesParams(params);
- }
- parseNavigateParams(params) {
- return Parser.BrowsingContext.parseNavigateParams(params);
- }
- parsePrintParams(params) {
- return Parser.BrowsingContext.parsePrintParams(params);
- }
- parseReloadParams(params) {
- return Parser.BrowsingContext.parseReloadParams(params);
- }
- parseSetViewportParams(params) {
- return Parser.BrowsingContext.parseSetViewportParams(params);
- }
- parseTraverseHistoryParams(params) {
- return Parser.BrowsingContext.parseTraverseHistoryParams(params);
- }
- // keep-sorted end
- // CDP domain
- // keep-sorted start block=yes
- parseGetSessionParams(params) {
- return Parser.Cdp.parseGetSessionRequest(params);
- }
- parseResolveRealmParams(params) {
- return Parser.Cdp.parseResolveRealmRequest(params);
- }
- parseSendCommandParams(params) {
- return Parser.Cdp.parseSendCommandRequest(params);
- }
- // keep-sorted end
- // Input domain
- // keep-sorted start block=yes
- parsePerformActionsParams(params) {
- return Parser.Input.parsePerformActionsParams(params);
- }
- parseReleaseActionsParams(params) {
- return Parser.Input.parseReleaseActionsParams(params);
- }
- parseSetFilesParams(params) {
- return Parser.Input.parseSetFilesParams(params);
- }
- // keep-sorted end
- // Network domain
- // keep-sorted start block=yes
- parseAddInterceptParams(params) {
- return Parser.Network.parseAddInterceptParameters(params);
- }
- parseContinueRequestParams(params) {
- return Parser.Network.parseContinueRequestParameters(params);
- }
- parseContinueResponseParams(params) {
- return Parser.Network.parseContinueResponseParameters(params);
- }
- parseContinueWithAuthParams(params) {
- return Parser.Network.parseContinueWithAuthParameters(params);
- }
- parseFailRequestParams(params) {
- return Parser.Network.parseFailRequestParameters(params);
- }
- parseProvideResponseParams(params) {
- return Parser.Network.parseProvideResponseParameters(params);
- }
- parseRemoveInterceptParams(params) {
- return Parser.Network.parseRemoveInterceptParameters(params);
- }
- // keep-sorted end
- // Permissions domain
- // keep-sorted start block=yes
- parseSetPermissionsParams(params) {
- return Parser.Permissions.parseSetPermissionsParams(params);
- }
- // keep-sorted end
- // Script domain
- // keep-sorted start block=yes
- parseAddPreloadScriptParams(params) {
- return Parser.Script.parseAddPreloadScriptParams(params);
- }
- parseCallFunctionParams(params) {
- return Parser.Script.parseCallFunctionParams(params);
- }
- parseDisownParams(params) {
- return Parser.Script.parseDisownParams(params);
- }
- parseEvaluateParams(params) {
- return Parser.Script.parseEvaluateParams(params);
- }
- parseGetRealmsParams(params) {
- return Parser.Script.parseGetRealmsParams(params);
- }
- parseRemovePreloadScriptParams(params) {
- return Parser.Script.parseRemovePreloadScriptParams(params);
- }
- // keep-sorted end
- // Session domain
- // keep-sorted start block=yes
- parseSubscribeParams(params) {
- return Parser.Session.parseSubscribeParams(params);
- }
- // keep-sorted end
- // Storage domain
- // keep-sorted start block=yes
- parseDeleteCookiesParams(params) {
- return Parser.Storage.parseDeleteCookiesParams(params);
- }
- parseGetCookiesParams(params) {
- return Parser.Storage.parseGetCookiesParams(params);
- }
- parseSetCookieParams(params) {
- return Parser.Storage.parseSetCookieParams(params);
- }
- }
- BidiParser$1.BidiParser = BidiParser;
- var mapperTabPage = {};
- Object.defineProperty(mapperTabPage, "__esModule", { value: true });
- mapperTabPage.log = mapperTabPage.generatePage = void 0;
- /**
- * Copyright 2022 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- const log_js_1$2 = log$1;
- /** HTML source code for the user-facing Mapper tab. */
- const mapperPageSource = '<!DOCTYPE html><title>BiDi-CDP Mapper</title><style>body{font-family: Roboto, serif; font-size: 13px; color: #202124;}.log{padding: 12px; font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace; font-size: 11px; line-height: 180%; background: #f1f3f4; border-radius: 4px;}.pre{overflow-wrap: break-word; padding: 10px;}.card{margin: 60px auto; padding: 2px 0; max-width: 900px; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15), 0 1px 6px rgba(0, 0, 0, 0.2); border-radius: 8px;}.divider{height: 1px; background: #f0f0f0;}.item{padding: 16px 20px;}</style><div class="card"><div class="item"><h1>BiDi-CDP Mapper is controlling this tab</h1><p>Closing or reloading it will stop the BiDi process. <a target="_blank" title="BiDi-CDP Mapper GitHub Repository" href="https://github.com/GoogleChromeLabs/chromium-bidi">Details.</a></p></div><div class="divider"></div><details id="details"><summary class="item">Debug information</summary></details></div>';
- /**
- * The following piece of HTML should be added to the `debug` element:
- *
- * <div class="divider"></div>
- * <div class="item">
- * <h3>${name}</h3>
- * <div id="${name}_log" class="log">
- */
- function findOrCreateTypeLogContainer(logPrefix) {
- const logType = logPrefix.split(':')[0];
- const containerId = `${logType}_log`;
- const existingContainer = document.getElementById(containerId);
- if (existingContainer) {
- return existingContainer;
- }
- const debugElement = document.getElementById('details');
- const divider = document.createElement('div');
- divider.className = 'divider';
- debugElement.appendChild(divider);
- const htmlItem = document.createElement('div');
- htmlItem.className = 'item';
- htmlItem.innerHTML = `<h3>${logType}</h3><div id="${containerId}" class="log"></div>`;
- debugElement.appendChild(htmlItem);
- return document.getElementById(containerId);
- }
- function generatePage() {
- // If run not in browser (e.g. unit test), do nothing.
- if (!globalThis.document.documentElement) {
- return;
- }
- globalThis.document.documentElement.innerHTML = mapperPageSource;
- // Create main log containers in proper order.
- findOrCreateTypeLogContainer(log_js_1$2.LogType.debugInfo);
- findOrCreateTypeLogContainer(log_js_1$2.LogType.bidi);
- findOrCreateTypeLogContainer(log_js_1$2.LogType.cdp);
- }
- mapperTabPage.generatePage = generatePage;
- function stringify(message) {
- if (typeof message === 'object') {
- return JSON.stringify(message, null, 2);
- }
- return message;
- }
- function log(logPrefix, ...messages) {
- // If run not in browser (e.g. unit test), do nothing.
- if (!globalThis.document.documentElement) {
- return;
- }
- // Skip sending BiDi logs as they are logged once by `bidi:server:*`
- if (!logPrefix.startsWith(log_js_1$2.LogType.bidi)) {
- // If `sendDebugMessage` is defined, send the log message there.
- globalThis.window?.sendDebugMessage?.(JSON.stringify({ logType: logPrefix, messages }));
- }
- const typeLogContainer = findOrCreateTypeLogContainer(logPrefix);
- // This piece of HTML should be added:
- // <div class="pre">...log message...</div>
- const lineElement = document.createElement('div');
- lineElement.className = 'pre';
- lineElement.textContent = [logPrefix, ...messages].map(stringify).join(' ');
- typeLogContainer.appendChild(lineElement);
- if (typeLogContainer.childNodes.length > 200) {
- typeLogContainer.removeChild(typeLogContainer.childNodes[0]);
- }
- }
- mapperTabPage.log = log;
- var Transport = {};
- Object.defineProperty(Transport, "__esModule", { value: true });
- Transport.WindowCdpTransport = Transport.WindowBidiTransport = void 0;
- const log_js_1$1 = log$1;
- const mapperTabPage_js_1$1 = mapperTabPage;
- class WindowBidiTransport {
- static LOGGER_PREFIX_RECV = `${log_js_1$1.LogType.bidi}:RECV ◂`;
- static LOGGER_PREFIX_SEND = `${log_js_1$1.LogType.bidi}:SEND ▸`;
- #onMessage = null;
- constructor() {
- window.onBidiMessage = (message) => {
- (0, mapperTabPage_js_1$1.log)(WindowBidiTransport.LOGGER_PREFIX_RECV, message);
- try {
- const command = WindowBidiTransport.#parseBidiMessage(message);
- this.#onMessage?.call(null, command);
- }
- catch (e) {
- const error = e instanceof Error ? e : new Error(e);
- // Transport-level error does not provide channel.
- this.#respondWithError(message, "invalid argument" /* ErrorCode.InvalidArgument */, error, null);
- }
- };
- }
- setOnMessage(onMessage) {
- this.#onMessage = onMessage;
- }
- sendMessage(message) {
- (0, mapperTabPage_js_1$1.log)(WindowBidiTransport.LOGGER_PREFIX_SEND, message);
- const json = JSON.stringify(message);
- window.sendBidiResponse(json);
- }
- close() {
- this.#onMessage = null;
- window.onBidiMessage = null;
- }
- #respondWithError(plainCommandData, errorCode, error, channel) {
- const errorResponse = WindowBidiTransport.#getErrorResponse(plainCommandData, errorCode, error);
- if (channel) {
- this.sendMessage({
- ...errorResponse,
- channel,
- });
- }
- else {
- this.sendMessage(errorResponse);
- }
- }
- static #getJsonType(value) {
- if (value === null) {
- return 'null';
- }
- if (Array.isArray(value)) {
- return 'array';
- }
- return typeof value;
- }
- static #getErrorResponse(message, errorCode, error) {
- // XXX: this is bizarre per spec. We reparse the payload and
- // extract the ID, regardless of what kind of value it was.
- let messageId;
- try {
- const command = JSON.parse(message);
- if (WindowBidiTransport.#getJsonType(command) === 'object' &&
- 'id' in command) {
- messageId = command.id;
- }
- }
- catch { }
- return {
- type: 'error',
- id: messageId,
- error: errorCode,
- message: error.message,
- };
- }
- static #parseBidiMessage(message) {
- let command;
- try {
- command = JSON.parse(message);
- }
- catch {
- throw new Error('Cannot parse data as JSON');
- }
- const type = WindowBidiTransport.#getJsonType(command);
- if (type !== 'object') {
- throw new Error(`Expected JSON object but got ${type}`);
- }
- // Extract and validate id, method and params.
- const { id, method, params } = command;
- const idType = WindowBidiTransport.#getJsonType(id);
- if (idType !== 'number' || !Number.isInteger(id) || id < 0) {
- // TODO: should uint64_t be the upper limit?
- // https://tools.ietf.org/html/rfc7049#section-2.1
- throw new Error(`Expected unsigned integer but got ${idType}`);
- }
- const methodType = WindowBidiTransport.#getJsonType(method);
- if (methodType !== 'string') {
- throw new Error(`Expected string method but got ${methodType}`);
- }
- const paramsType = WindowBidiTransport.#getJsonType(params);
- if (paramsType !== 'object') {
- throw new Error(`Expected object params but got ${paramsType}`);
- }
- let channel = command.channel;
- if (channel !== undefined) {
- const channelType = WindowBidiTransport.#getJsonType(channel);
- if (channelType !== 'string') {
- throw new Error(`Expected string channel but got ${channelType}`);
- }
- // Empty string channel is considered as no channel provided.
- if (channel === '') {
- channel = undefined;
- }
- }
- return { id, method, params, channel };
- }
- }
- Transport.WindowBidiTransport = WindowBidiTransport;
- class WindowCdpTransport {
- #onMessage = null;
- constructor() {
- window.cdp.onmessage = (message) => {
- this.#onMessage?.call(null, message);
- };
- }
- setOnMessage(onMessage) {
- this.#onMessage = onMessage;
- }
- sendMessage(message) {
- window.cdp.send(message);
- }
- close() {
- this.#onMessage = null;
- window.cdp.onmessage = null;
- }
- }
- Transport.WindowCdpTransport = WindowCdpTransport;
- /**
- * Copyright 2021 Google LLC.
- * Copyright (c) Microsoft Corporation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * @license
- */
- Object.defineProperty(bidiTab, "__esModule", { value: true });
- const BidiMapper_js_1 = BidiMapper;
- const CdpConnection_js_1 = CdpConnection;
- const log_js_1 = log$1;
- const BidiParser_js_1 = BidiParser$1;
- const mapperTabPage_js_1 = mapperTabPage;
- const Transport_js_1 = Transport;
- (0, mapperTabPage_js_1.generatePage)();
- const mapperTabToServerTransport = new Transport_js_1.WindowBidiTransport();
- const cdpTransport = new Transport_js_1.WindowCdpTransport();
- /**
- * A CdpTransport implementation that uses the window.cdp bindings
- * injected by Target.exposeDevToolsProtocol.
- */
- const cdpConnection = new CdpConnection_js_1.MapperCdpConnection(cdpTransport, mapperTabPage_js_1.log);
- /**
- * Launches the BiDi mapper instance.
- * @param {string} selfTargetId
- * @param options Mapper options. E.g. `acceptInsecureCerts`.
- */
- async function runMapperInstance(selfTargetId, options) {
- // eslint-disable-next-line no-console
- console.log('Launching Mapper instance with selfTargetId:', selfTargetId);
- const bidiServer = await BidiMapper_js_1.BidiServer.createAndStart(mapperTabToServerTransport, cdpConnection,
- /**
- * Create a Browser CDP Session per Mapper instance.
- */
- await cdpConnection.createBrowserSession(), selfTargetId, options, new BidiParser_js_1.BidiParser(), mapperTabPage_js_1.log);
- (0, mapperTabPage_js_1.log)(log_js_1.LogType.debugInfo, 'Mapper instance has been launched');
- return bidiServer;
- }
- /**
- * Set `window.runMapper` to a function which launches the BiDi mapper instance.
- * @param selfTargetId Needed to filter out info related to BiDi target.
- * @param options Mapper options. E.g. `acceptInsecureCerts`. */
- window.runMapperInstance = async (selfTargetId, options) => {
- await runMapperInstance(selfTargetId, options);
- };
- return bidiTab;
- })();
- //# sourceMappingURL=mapperTab.js.map
|