javascript:%2F%2A%20Trafikverket%20earliest-test%20finder.%20Run%20as%20a%20bookmark%20on%20fp.trafikverket.se.%0A%20%2A%20Uses%20the%20current%20browser%20login.%20No%20credentials%20are%20included%20in%20this%20file.%0A%20%2A%20Searches%20availability%20only%3B%20never%20reserves%2C%20books%2C%20cancels%2C%20or%20pays.%0A%20%2A%2F%0A%28%28%29%20%3D%3E%20%7B%0A%20%20%27use%20strict%27%3B%0A%20%20if%20%28location.origin%20%21%3D%3D%20%27https%3A%2F%2Ffp.trafikverket.se%27%29%20%7B%0A%20%20%20%20alert%28%27First%20open%20https%3A%2F%2Ffp.trafikverket.se%2FBoka%2F%20and%20sign%20in.%20Then%20click%20this%20bookmark%20again.%27%29%3B%0A%20%20%20%20return%3B%0A%20%20%7D%0A%20%20const%20id%20%3D%20%27trv-earliest-tests-helper%27%3B%0A%20%20if%20%28document.getElementById%28id%29%29%20return%3B%0A%20%20const%20host%20%3D%20document.createElement%28%27div%27%29%3B%0A%20%20host.id%20%3D%20id%3B%0A%20%20host.style.cssText%20%3D%20%27position%3Afixed%3Binset%3A0%3Bz-index%3A2147483647%3Bbackground%3A%2316202b99%3Bpadding%3A20px%3Bbox-sizing%3Aborder-box%3Boverflow%3Aauto%27%3B%0A%20%20const%20root%20%3D%20host.attachShadow%28%7Bmode%3A%20%27open%27%7D%29%3B%0A%20%20root.innerHTML%20%3D%20%60%0A%20%20%20%20%3Cstyle%3E%0A%20%20%20%20%20%20%3Ahost%7Bcolor-scheme%3Alight%3Bfont%3A16px%2F1.5%20system-ui%2Csans-serif%3Bcolor%3A%23182a36%7D%0A%20%20%20%20%20%20%2A%7Bbox-sizing%3Aborder-box%7D%20.panel%7Bmax-width%3A960px%3Bmargin%3A0%20auto%3Bbackground%3A%23fff%3Bborder-radius%3A18px%3Bpadding%3A26px%3Bbox-shadow%3A0%2012px%2080px%20%230004%7D%0A%20%20%20%20%20%20h1%7Bfont-size%3A27px%3Bmargin%3A0%200%208px%3Bline-height%3A1.2%7Dp%7Bmargin%3A8px%200%2016px%7D.muted%7Bcolor%3A%23526473%3Bfont-size%3A14px%7D%0A%20%20%20%20%20%20.top%2C.actions%2C.fields%7Bdisplay%3Aflex%3Bgap%3A14px%3Balign-items%3Acenter%3Bflex-wrap%3Awrap%7D.top%7Bjustify-content%3Aspace-between%3Balign-items%3Astart%7D%0A%20%20%20%20%20%20.fields%7Balign-items%3Aend%3Bmargin%3A20px%200%7Dlabel%7Bdisplay%3Ablock%3Bfont-weight%3A600%3Bfont-size%3A14px%7Dinput%2Cselect%7Bdisplay%3Ablock%3Bmargin-top%3A6px%3Bpadding%3A10px%3Bborder%3A1px%20solid%20%239babb7%3Bborder-radius%3A7px%3Bfont%3Ainherit%3Bbackground%3A%23fff%3Bcolor%3A%23182a36%3Bmax-width%3A100%25%7D%0A%20%20%20%20%20%20button%7Bfont%3A600%2014px%20system-ui%2Csans-serif%3Bpadding%3A11px%2016px%3Bborder-radius%3A8px%3Bborder%3A1px%20solid%20%23a5b6c1%3Bbackground%3A%23f5f8fa%3Bcolor%3A%23182a36%3Bcursor%3Apointer%7Dbutton.primary%7Bbackground%3A%2312604f%3Bcolor%3Awhite%3Bborder-color%3A%2312604f%7Dbutton%3Adisabled%7Bopacity%3A.5%3Bcursor%3Adefault%7D%0A%20%20%20%20%20%20%23status%7Bbackground%3A%23eef5f2%3Bpadding%3A13px%3Bborder-radius%3A9px%3Bmargin%3A18px%200%3Bwhite-space%3Apre-wrap%7D%23status.error%7Bbackground%3A%23fff0ee%3Bcolor%3A%23972a20%7D%0A%20%20%20%20%20%20.table-wrap%7Boverflow%3Aauto%3Bmax-height%3A52vh%3Bborder%3A1px%20solid%20%23dce4e8%3Bborder-radius%3A9px%7Dtable%7Bborder-collapse%3Acollapse%3Bwidth%3A100%25%3Bfont-size%3A14px%3Btext-align%3Aleft%7Dth%2Ctd%7Bpadding%3A10px%2012px%3Bborder-bottom%3A1px%20solid%20%23e7ecef%3Bwhite-space%3Anowrap%7Dth%7Bbackground%3A%23eef3f6%3Bposition%3Asticky%3Btop%3A0%7Dtd%3Alast-child%7Bwhite-space%3Anormal%3Bmin-width%3A150px%7D%0A%20%20%20%20%20%20%5Bhidden%5D%7Bdisplay%3Anone%21important%7D.actions%7Bmargin-top%3A12px%7Dprogress%7Bwidth%3A100%25%3Bheight%3A12px%3Baccent-color%3A%2312604f%7Dbutton%3Afocus-visible%2Cinput%3Afocus-visible%2Cselect%3Afocus-visible%7Boutline%3A3px%20solid%20%23e4ae48%3Boutline-offset%3A2px%7D%0A%20%20%20%20%20%20%40media%28max-width%3A600px%29%7B.panel%7Bpadding%3A17px%7Dh1%7Bfont-size%3A22px%7D%7D%0A%20%20%20%20%3C%2Fstyle%3E%0A%20%20%20%20%3Csection%20class%3D%22panel%22%20role%3D%22dialog%22%20aria-modal%3D%22true%22%20aria-label%3D%22Earliest%20licence%20tests%22%3E%0A%20%20%20%20%20%20%3Cdiv%20class%3D%22top%22%3E%3Cdiv%3E%3Ch1%3EFind%20the%20earliest%20licence%20test%3C%2Fh1%3E%3Cp%20class%3D%22muted%22%3EB%20licence%20%C2%B7%20theory%20or%20driving%20%C2%B7%20all%20locations%20in%20Sweden%20%C2%B7%20your%20own%20Trafikverket%20login%3C%2Fp%3E%3C%2Fdiv%3E%3Cbutton%20id%3D%22close%22%20aria-label%3D%22Close%20finder%22%3EClose%3C%2Fbutton%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%3Cp%3ESign%20in%20to%20Trafikverket%20first.%20Enter%20the%20personal%20number%20you%20are%20signed%20in%20with%2C%20then%20start%20the%20search.%3C%2Fp%3E%0A%20%20%20%20%20%20%3Cform%20id%3D%22form%22%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22fields%22%3E%3Clabel%3EPersonal%20number%3Cinput%20id%3D%22person%22%20type%3D%22text%22%20inputmode%3D%22numeric%22%20placeholder%3D%22YYYYMMDD-XXXX%22%20autocomplete%3D%22off%22%20spellcheck%3D%22false%22%20required%3E%3C%2Flabel%3E%0A%20%20%20%20%20%20%20%20%3Clabel%3ETest%20type%3Cselect%20id%3D%22test%22%3E%3Coption%20value%3D%2212%22%3EDriving%20test%20%28K%C3%B6rprov%29%3C%2Foption%3E%3Coption%20value%3D%223%22%3ETheory%20%2F%20knowledge%20test%20%28Kunskapsprov%29%3C%2Foption%3E%3C%2Fselect%3E%3C%2Flabel%3E%0A%20%20%20%20%20%20%20%20%3Clabel%20id%3D%22car-field%22%3ECar%3Cselect%20id%3D%22vehicle%22%3E%3Coption%20value%3D%224%22%3EAutomatic%3C%2Foption%3E%3Coption%20value%3D%222%22%3EManual%3C%2Foption%3E%3C%2Fselect%3E%3C%2Flabel%3E%0A%20%20%20%20%20%20%20%20%3Clabel%20id%3D%22language-field%22%20hidden%3ETest%20language%3Cselect%20id%3D%22language%22%3E%3Coption%20value%3D%2213%22%3ESwedish%20%2F%20Svenska%3C%2Foption%3E%3Coption%20value%3D%224%22%3EEnglish%20%2F%20Engelska%3C%2Foption%3E%3Coption%20value%3D%221%22%3EAlbanian%20%2F%20Albanska%3C%2Foption%3E%3Coption%20value%3D%222%22%3EArabic%20%2F%20Arabiska%3C%2Foption%3E%3Coption%20value%3D%223%22%3EBosnian%2C%20Croatian%2C%20Serbian%3C%2Foption%3E%3Coption%20value%3D%225%22%3EFinnish%20%2F%20Finska%3C%2Foption%3E%3Coption%20value%3D%226%22%3EFrench%20%2F%20Franska%3C%2Foption%3E%3Coption%20value%3D%227%22%3EPersian%20%2F%20Persiska%3C%2Foption%3E%3Coption%20value%3D%228%22%3ERussian%20%2F%20Ryska%3C%2Foption%3E%3Coption%20value%3D%22128%22%3ESomali%20%2F%20Somaliska%3C%2Foption%3E%3Coption%20value%3D%229%22%3ESorani%3C%2Foption%3E%3Coption%20value%3D%2210%22%3ESpanish%20%2F%20Spanska%3C%2Foption%3E%3Coption%20value%3D%22133%22%3EThai%20%2F%20Thail%C3%A4ndska%3C%2Foption%3E%3Coption%20value%3D%22150%22%3ETigrinya%20%2F%20Tigrinja%3C%2Foption%3E%3Coption%20value%3D%2211%22%3ETurkish%20%2F%20Turkiska%3C%2Foption%3E%3Coption%20value%3D%2212%22%3EGerman%20%2F%20Tyska%3C%2Foption%3E%3C%2Fselect%3E%3C%2Flabel%3E%0A%20%20%20%20%20%20%20%20%3Cbutton%20id%3D%22start%22%20class%3D%22primary%22%20type%3D%22submit%22%3EFind%20earliest%20tests%3C%2Fbutton%3E%3Cbutton%20id%3D%22stop%22%20type%3D%22button%22%20disabled%3EStop%3C%2Fbutton%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%3C%2Fform%3E%0A%20%20%20%20%20%20%3Cp%20class%3D%22muted%22%3EYour%20personal%20number%20goes%20only%20to%20Trafikverket%20and%20is%20cleared%20when%20you%20close%20this%20panel.%20The%20browser%20uses%20your%20existing%20login%20automatically.%20This%20tool%20only%20searches%3B%20book%20your%20chosen%20test%20on%20the%20normal%20Trafikverket%20page.%3C%2Fp%3E%0A%20%20%20%20%20%20%3Cdiv%20id%3D%22status%22%20role%3D%22status%22%20aria-live%3D%22polite%22%3EReady.%20A%20nationwide%20search%20usually%20takes%20a%20few%20minutes.%3C%2Fdiv%3E%0A%20%20%20%20%20%20%3Cprogress%20id%3D%22progress%22%20max%3D%221%22%20value%3D%220%22%20aria-label%3D%22Locations%20checked%22%3E%3C%2Fprogress%3E%0A%20%20%20%20%20%20%3Cdiv%20id%3D%22results%22%20hidden%3E%3Cp%20id%3D%22summary%22%3E%3C%2Fp%3E%3Cdiv%20class%3D%22table-wrap%22%3E%3Ctable%3E%3Cthead%3E%3Ctr%3E%3Cth%3ELocation%3C%2Fth%3E%3Cth%3EDate%3C%2Fth%3E%3Cth%3ETime%3C%2Fth%3E%3Cth%3EPrice%3C%2Fth%3E%3Cth%3EStatus%3C%2Fth%3E%3C%2Ftr%3E%3C%2Fthead%3E%3Ctbody%20id%3D%22rows%22%3E%3C%2Ftbody%3E%3C%2Ftable%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%20%20%3Cdiv%20class%3D%22actions%22%3E%3Cbutton%20id%3D%22save%22%20disabled%3ESave%20results%3C%2Fbutton%3E%3Cspan%20class%3D%22muted%22%3EAll%20times%20are%20Swedish%20local%20time.%20Availability%20can%20change.%3C%2Fspan%3E%3C%2Fdiv%3E%0A%20%20%20%20%20%20%3C%2Fdiv%3E%0A%20%20%20%20%3C%2Fsection%3E%60%3B%0A%20%20document.documentElement.append%28host%29%3B%0A%20%20const%20%24%20%3D%20selector%20%3D%3E%20root.querySelector%28selector%29%3B%0A%20%20let%20controller%20%3D%20null%3B%0A%20%20let%20entries%20%3D%20%5B%5D%3B%0A%20%20let%20report%20%3D%20null%3B%0A%20%20let%20running%20%3D%20false%3B%0A%20%20let%20closed%20%3D%20false%3B%0A%20%20%24%28%27%23test%27%29.onchange%20%3D%20%28%29%20%3D%3E%20%7B%0A%20%20%20%20const%20theory%20%3D%20%24%28%27%23test%27%29.value%20%3D%3D%3D%20%273%27%3B%0A%20%20%20%20%24%28%27%23car-field%27%29.hidden%20%3D%20theory%3B%0A%20%20%20%20%24%28%27%23language-field%27%29.hidden%20%3D%20%21theory%3B%0A%20%20%7D%3B%0A%20%20const%20status%20%3D%20%28message%2C%20error%20%3D%20false%29%20%3D%3E%20%7B%0A%20%20%20%20%24%28%27%23status%27%29.textContent%20%3D%20message%3B%0A%20%20%20%20%24%28%27%23status%27%29.className%20%3D%20error%20%3F%20%27error%27%20%3A%20%27%27%3B%0A%20%20%7D%3B%0A%20%20const%20sorted%20%3D%20%28%29%20%3D%3E%20%5B...entries%5D.sort%28%28a%2C%20b%29%20%3D%3E%0A%20%20%20%20%28a.earliest%3F.duration.start%20%7C%7C%20%279999%27%29.localeCompare%28b.earliest%3F.duration.start%20%7C%7C%20%279999%27%29%20%7C%7C%20a.location.localeCompare%28b.location%2C%20%27sv%27%29%29%3B%0A%20%20function%20render%28%29%20%7B%0A%20%20%20%20const%20body%20%3D%20%24%28%27%23rows%27%29%3B%0A%20%20%20%20body.replaceChildren%28%29%3B%0A%20%20%20%20for%20%28const%20item%20of%20sorted%28%29%29%20%7B%0A%20%20%20%20%20%20const%20o%20%3D%20item.earliest%3B%0A%20%20%20%20%20%20const%20row%20%3D%20document.createElement%28%27tr%27%29%3B%0A%20%20%20%20%20%20const%20values%20%3D%20%5Bitem.location%2C%20o%3F.date%20%7C%7C%20%27%E2%80%94%27%2C%20o%3F.time%20%7C%7C%20%27%E2%80%94%27%2C%20o%20%3F%20%60%24%7Bo.cost%20%7C%7C%20%27%27%7D%24%7Bo.costText%20%7C%7C%20%27%27%7D%60%20%3A%20%27%E2%80%94%27%2C%0A%20%20%20%20%20%20%20%20o%20%3F%20%27Earliest%20returned%27%20%3A%20item.complete%20%3F%20%60None%20returned%20in%20%24%7Breport.maxSearchPeriodInMonths%7D-month%20search%60%20%3A%20item.searchedMonths%20%3F%20%60Checked%20%24%7Bitem.searchedMonths%7D%20months%3B%20more%20to%20search%60%20%3A%20%27Not%20checked%20yet%27%5D%3B%0A%20%20%20%20%20%20for%20%28const%20value%20of%20values%29%20%7B%0A%20%20%20%20%20%20%20%20const%20cell%20%3D%20document.createElement%28%27td%27%29%3B%0A%20%20%20%20%20%20%20%20cell.textContent%20%3D%20value%3B%0A%20%20%20%20%20%20%20%20row.append%28cell%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20body.append%28row%29%3B%0A%20%20%20%20%7D%0A%20%20%20%20const%20done%20%3D%20entries.filter%28x%20%3D%3E%20x.complete%29.length%3B%0A%20%20%20%20const%20found%20%3D%20entries.filter%28x%20%3D%3E%20x.earliest%29.length%3B%0A%20%20%20%20%24%28%27%23progress%27%29.max%20%3D%20entries.length%20%7C%7C%201%3B%0A%20%20%20%20%24%28%27%23progress%27%29.value%20%3D%20done%3B%0A%20%20%20%20%24%28%27%23summary%27%29.textContent%20%3D%20%60%24%7Breport.test%7D%24%7Breport.language%20%3F%20%27%20%C2%B7%20%27%20%2B%20report.language%20%3A%20%27%20%C2%B7%20%27%20%2B%20report.car%7D%20%C2%B7%20%24%7Bdone%7D%20of%20%24%7Bentries.length%7D%20locations%20completed%20%C2%B7%20appointments%20at%20%24%7Bfound%7D%20locations%60%3B%0A%20%20%20%20%24%28%27%23results%27%29.hidden%20%3D%20false%3B%0A%20%20%20%20%24%28%27%23save%27%29.disabled%20%3D%20entries.length%20%3D%3D%3D%200%3B%0A%20%20%7D%0A%20%20async%20function%20post%28endpoint%2C%20payload%29%20%7B%0A%20%20%20%20const%20timeout%20%3D%20setTimeout%28%28%29%20%3D%3E%20controller%3F.abort%28%27timeout%27%29%2C%2045000%29%3B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20const%20response%20%3D%20await%20fetch%28%60%2FBoka%2F%24%7Bendpoint%7D%60%2C%20%7B%0A%20%20%20%20%20%20%20%20method%3A%20%27POST%27%2C%20credentials%3A%20%27same-origin%27%2C%20redirect%3A%20%27error%27%2C%0A%20%20%20%20%20%20%20%20headers%3A%20%7B%27Content-Type%27%3A%20%27application%2Fjson%27%2C%20%27Accept%27%3A%20%27application%2Fjson%27%7D%2C%0A%20%20%20%20%20%20%20%20body%3A%20JSON.stringify%28payload%29%2C%20signal%3A%20controller.signal%0A%20%20%20%20%20%20%7D%29%3B%0A%20%20%20%20%20%20const%20text%20%3D%20await%20response.text%28%29%3B%0A%20%20%20%20%20%20let%20result%3B%0A%20%20%20%20%20%20try%20%7B%20result%20%3D%20JSON.parse%28text%29%3B%20%7D%20catch%20%7B%20result%20%3D%20null%3B%20%7D%0A%20%20%20%20%20%20if%20%28result%3F.type%20%3D%3D%3D%20%27LoginRequiredException%27%20%7C%7C%20response.status%20%3D%3D%3D%20401%20%7C%7C%20response.status%20%3D%3D%3D%20403%29%20%7B%0A%20%20%20%20%20%20%20%20throw%20new%20Error%28%27Your%20login%20is%20missing%20or%20has%20expired.%20Close%20this%20panel%2C%20sign%20in%20to%20Trafikverket%2C%20then%20click%20the%20bookmark%20again.%27%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20if%20%28response.status%20%3D%3D%3D%20429%29%20throw%20new%20Error%28%27Trafikverket%20asked%20us%20to%20slow%20down.%20The%20search%20has%20stopped.%20Wait%20before%20trying%20again%3B%20partial%20results%20are%20available%20below.%27%29%3B%0A%20%20%20%20%20%20if%20%28%21response.ok%20%7C%7C%20%28typeof%20result%3F.status%20%3D%3D%3D%20%27number%27%20%26%26%20result.status%20%3E%3D%20400%29%29%20%7B%0A%20%20%20%20%20%20%20%20throw%20new%20Error%28%60Trafikverket%20rejected%20the%20search%20%28HTTP%20%24%7Bresponse.status%7D%29.%20Check%20your%20personal%20number%20and%20login%2C%20and%20make%20sure%20you%20can%20search%20for%20your%20selected%20B%20licence%20test%20on%20the%20normal%20booking%20page.%60%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20if%20%28%21result%3F.data%20%7C%7C%20typeof%20result.data%20%21%3D%3D%20%27object%27%29%20throw%20new%20Error%28%27Trafikverket%20returned%20an%20unfamiliar%20response.%20Sign%20in%20again%20and%20retry.%20The%20tool%20may%20need%20updating%20if%20the%20website%20has%20changed.%27%29%3B%0A%20%20%20%20%20%20return%20result.data%3B%0A%20%20%20%20%7D%20finally%20%7B%20clearTimeout%28timeout%29%3B%20%7D%0A%20%20%7D%0A%20%20function%20stop%28%29%20%7B%20if%20%28running%29%20controller.abort%28%27user%27%29%3B%20%7D%0A%20%20%24%28%27%23stop%27%29.onclick%20%3D%20stop%3B%0A%20%20%24%28%27%23close%27%29.onclick%20%3D%20%28%29%20%3D%3E%20%7B%20stop%28%29%3B%20closed%20%3D%20true%3B%20%24%28%27%23person%27%29.value%20%3D%20%27%27%3B%20host.remove%28%29%3B%20%7D%3B%0A%20%20%24%28%27%23save%27%29.onclick%20%3D%20%28%29%20%3D%3E%20%7B%0A%20%20%20%20const%20snapshot%20%3D%20%7B...report%2C%20finished%3A%20entries.every%28x%20%3D%3E%20x.complete%29%2C%20savedAt%3A%20new%20Date%28%29.toISOString%28%29%2C%20results%3A%20sorted%28%29%7D%3B%0A%20%20%20%20const%20url%20%3D%20URL.createObjectURL%28new%20Blob%28%5BJSON.stringify%28snapshot%2C%20null%2C%202%29%5D%2C%20%7Btype%3A%20%27application%2Fjson%27%7D%29%29%3B%0A%20%20%20%20const%20a%20%3D%20document.createElement%28%27a%27%29%3B%0A%20%20%20%20a.href%20%3D%20url%3B%0A%20%20%20%20a.download%20%3D%20%60earliest-%24%7Breport.examinationTypeId%20%3D%3D%3D%203%20%3F%20%27theory%27%20%3A%20%27driving%27%7D-tests-%24%7Bnew%20Date%28%29.toISOString%28%29.slice%280%2C%2010%29%7D.json%60%3B%0A%20%20%20%20a.click%28%29%3B%0A%20%20%20%20setTimeout%28%28%29%20%3D%3E%20URL.revokeObjectURL%28url%29%2C%2030000%29%3B%0A%20%20%7D%3B%0A%20%20%24%28%27%23form%27%29.onsubmit%20%3D%20async%20event%20%3D%3E%20%7B%0A%20%20%20%20event.preventDefault%28%29%3B%0A%20%20%20%20if%20%28running%29%20return%3B%0A%20%20%20%20const%20digits%20%3D%20%24%28%27%23person%27%29.value.replace%28%2F%5B%5Cs%2B-%5D%2Fg%2C%20%27%27%29%3B%0A%20%20%20%20if%20%28%21%2F%5E%5Cd%7B12%7D%24%2F.test%28digits%29%29%20%7B%0A%20%20%20%20%20%20status%28%27Enter%20your%20personal%20number%20with%20all%2012%20digits%3A%20YYYYMMDD-XXXX.%27%2C%20true%29%3B%0A%20%20%20%20%20%20%24%28%27%23person%27%29.focus%28%29%3B%0A%20%20%20%20%20%20return%3B%0A%20%20%20%20%7D%0A%20%20%20%20const%20examinationTypeId%20%3D%20Number%28%24%28%27%23test%27%29.value%29%3B%0A%20%20%20%20const%20theory%20%3D%20examinationTypeId%20%3D%3D%3D%203%3B%0A%20%20%20%20const%20examinationCategory%20%3D%20theory%20%3F%201%20%3A%202%3B%0A%20%20%20%20const%20testName%20%3D%20theory%20%3F%20%27B%20theory%20%2F%20knowledge%20test%27%20%3A%20%27B%20driving%20test%27%3B%0A%20%20%20%20const%20languageId%20%3D%20theory%20%3F%20Number%28%24%28%27%23language%27%29.value%29%20%3A%200%3B%0A%20%20%20%20const%20bookingSession%20%3D%20%7B%0A%20%20%20%20%20%20socialSecurityNumber%3A%20%60%24%7Bdigits.slice%280%2C%208%29%7D-%24%7Bdigits.slice%288%29%7D%60%2C%0A%20%20%20%20%20%20licenceId%3A%205%2C%20bookingModeId%3A%200%2C%20ignoreDebt%3A%20false%2C%20ignoreBookingHindrance%3A%20false%2C%0A%20%20%20%20%20%20examinationTypeId%2C%20excludeExaminationCategories%3A%20%5B%5D%2C%20rescheduleTypeId%3A%200%2C%0A%20%20%20%20%20%20paymentIsActive%3A%20false%2C%20paymentReference%3A%20%27%27%2C%20paymentUrl%3A%20%27%27%2C%20searchedMonths%3A%200%0A%20%20%20%20%7D%3B%0A%20%20%20%20%2F%2F%20The%20booking%20site%27s%20query%20builder%20defaults%20this%20unused%20field%20to%202%20for%20theory.%0A%20%20%20%20const%20vehicleTypeId%20%3D%20theory%20%3F%202%20%3A%20Number%28%24%28%27%23vehicle%27%29.value%29%3B%0A%20%20%20%20running%20%3D%20true%3B%0A%20%20%20%20controller%20%3D%20new%20AbortController%28%29%3B%0A%20%20%20%20%24%28%27%23start%27%29.disabled%20%3D%20%24%28%27%23test%27%29.disabled%20%3D%20%24%28%27%23language%27%29.disabled%20%3D%20%24%28%27%23vehicle%27%29.disabled%20%3D%20%24%28%27%23person%27%29.disabled%20%3D%20true%3B%0A%20%20%20%20%24%28%27%23stop%27%29.disabled%20%3D%20false%3B%0A%20%20%20%20%24%28%27%23save%27%29.disabled%20%3D%20true%3B%0A%20%20%20%20%24%28%27%23results%27%29.hidden%20%3D%20true%3B%0A%20%20%20%20%24%28%27%23progress%27%29.value%20%3D%200%3B%0A%20%20%20%20entries%20%3D%20%5B%5D%3B%0A%20%20%20%20status%28%27Checking%20your%20login%20and%20loading%20locations%E2%80%A6%27%29%3B%0A%20%20%20%20try%20%7B%0A%20%20%20%20%20%20const%20info%20%3D%20await%20post%28%27search-information%27%2C%20%7BbookingSession%7D%29%3B%0A%20%20%20%20%20%20if%20%28info.canBookLicence%20%3D%3D%3D%20false%29%20throw%20new%20Error%28%27Trafikverket%20says%20this%20account%20cannot%20book%20this%20licence.%20Check%20the%20normal%20booking%20page%20for%20details.%27%29%3B%0A%20%20%20%20%20%20if%20%28%21Array.isArray%28info.locations%29%20%7C%7C%20%21info.timeIntervals%3F.%5B0%5D%3F.startDate%20%7C%7C%20%21Number.isInteger%28info.maxSearchPeriodInMonths%29%20%7C%7C%20info.maxSearchPeriodInMonths%20%3C%201%29%20%7B%0A%20%20%20%20%20%20%20%20throw%20new%20Error%28%27The%20location%20information%20has%20changed.%20This%20version%20of%20the%20tool%20needs%20updating.%27%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20const%20maxMonths%20%3D%20info.maxSearchPeriodInMonths%3B%0A%20%20%20%20%20%20const%20language%20%3D%20theory%20%3F%20info.languages%3F.find%28x%20%3D%3E%20x.id%20%3D%3D%3D%20languageId%29%20%3A%20null%3B%0A%20%20%20%20%20%20if%20%28theory%20%26%26%20%21language%29%20throw%20new%20Error%28%27Your%20selected%20language%20is%20not%20available%20for%20this%20account.%20Choose%20another%20language%20or%20check%20the%20normal%20booking%20page.%27%29%3B%0A%20%20%20%20%20%20const%20supportsTest%20%3D%20x%20%3D%3E%20x.examinationCategories%3F.some%28c%20%3D%3E%20c.value%20%3D%3D%3D%20examinationCategory%29%3B%0A%20%20%20%20%20%20const%20supportsLanguage%20%3D%20x%20%3D%3E%20%21theory%20%7C%7C%20%21language.locationIds%3F.length%20%7C%7C%20language.locationIds.includes%28x.location.id%29%3B%0A%20%20%20%20%20%20const%20extra%20%3D%20info.enableNearbyLocations%20%26%26%20Number.isInteger%28info.maxNearbyLocations%29%20%3F%20Math.max%280%2C%20Math.min%283%2C%20info.maxNearbyLocations%29%29%20%3A%200%3B%0A%20%20%20%20%20%20entries%20%3D%20info.locations.filter%28x%20%3D%3E%20supportsTest%28x%29%20%26%26%20supportsLanguage%28x%29%29%0A%20%20%20%20%20%20%20%20.map%28x%20%3D%3E%20%28%7BlocationId%3A%20x.location.id%2C%20location%3A%20x.location.name.trim%28%29%2C%20searchedMonths%3A%200%2C%20complete%3A%20false%2C%20earliest%3A%20null%7D%29%29%3B%0A%20%20%20%20%20%20if%20%28%21entries.length%29%20throw%20new%20Error%28%27No%20locations%20were%20returned%20for%20this%20test%20type%20and%20language.%27%29%3B%0A%20%20%20%20%20%20report%20%3D%20%7B%0A%20%20%20%20%20%20%20%20startedAt%3A%20new%20Date%28%29.toISOString%28%29%2C%20searchStartDate%3A%20info.timeIntervals%5B0%5D.startDate%2C%0A%20%20%20%20%20%20%20%20test%3A%20testName%2C%20examinationTypeId%2C%20languageId%2C%20language%3A%20language%3F.name%20%7C%7C%20null%2C%0A%20%20%20%20%20%20%20%20car%3A%20theory%20%3F%20null%20%3A%20vehicleTypeId%20%3D%3D%3D%204%20%3F%20%27Automatic%27%20%3A%20%27Manual%27%2C%20maxSearchPeriodInMonths%3A%20maxMonths%2C%0A%20%20%20%20%20%20%20%20excludedLocations%3A%20info.locations.filter%28x%20%3D%3E%20%21supportsTest%28x%29%20%7C%7C%20%21supportsLanguage%28x%29%29.map%28x%20%3D%3E%20%28%7BlocationId%3A%20x.location.id%2C%20location%3A%20x.location.name.trim%28%29%2C%20reason%3A%20%21supportsTest%28x%29%20%3F%20%27Not%20listed%20for%20the%20selected%20test%20type%27%20%3A%20%27Not%20listed%20for%20the%20selected%20language%27%7D%29%29%0A%20%20%20%20%20%20%7D%3B%0A%20%20%20%20%20%20render%28%29%3B%0A%20%20%20%20%20%20while%20%28entries.some%28x%20%3D%3E%20%21x.complete%29%29%20%7B%0A%20%20%20%20%20%20%20%20if%20%28controller.signal.aborted%29%20throw%20new%20DOMException%28%27Stopped%27%2C%20%27AbortError%27%29%3B%0A%20%20%20%20%20%20%20%20const%20pending%20%3D%20entries.filter%28x%20%3D%3E%20%21x.complete%29%3B%0A%20%20%20%20%20%20%20%20const%20month%20%3D%20Math.min%28...pending.map%28x%20%3D%3E%20x.searchedMonths%29%29%3B%0A%20%20%20%20%20%20%20%20const%20batch%20%3D%20pending.filter%28x%20%3D%3E%20x.searchedMonths%20%3D%3D%3D%20month%29.slice%280%2C%20extra%20%2B%201%29%3B%0A%20%20%20%20%20%20%20%20status%28%60Searching%20%24%7Bbatch.map%28x%20%3D%3E%20x.location%29.join%28%27%2C%20%27%29%7D%E2%80%A6%5Cn%24%7Bentries.filter%28x%20%3D%3E%20x.complete%29.length%7D%20of%20%24%7Bentries.length%7D%20locations%20completed.%60%29%3B%0A%20%20%20%20%20%20%20%20const%20data%20%3D%20await%20post%28%27occasion-bundles%27%2C%20%7B%0A%20%20%20%20%20%20%20%20%20%20bookingSession%3A%20%7B...bookingSession%2C%20searchedMonths%3A%20month%7D%2C%0A%20%20%20%20%20%20%20%20%20%20occasionBundleQuery%3A%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20startDate%3A%20info.timeIntervals%5B0%5D.startDate%2C%20searchedMonths%3A%20month%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20locationId%3A%20batch%5B0%5D.locationId%2C%20nearbyLocationIds%3A%20batch.slice%281%29.map%28x%20%3D%3E%20x.locationId%29%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20languageId%2C%20vehicleTypeId%2C%20tachographTypeId%3A%20info.tachographTypeId%20%7C%7C%201%2C%20occasionChoiceId%3A%20info.occasionChoiceId%20%7C%7C%200%2C%20examinationTypeId%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%7D%29%3B%0A%20%20%20%20%20%20%20%20if%20%28%21Array.isArray%28data.bundles%29%20%7C%7C%20%21Number.isInteger%28data.searchedMonths%29%20%7C%7C%20data.searchedMonths%20%3C%3D%20month%20%7C%7C%20data.bundles.some%28b%20%3D%3E%20%21Array.isArray%28b.occasions%29%29%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20throw%20new%20Error%28%27The%20search%20response%20has%20changed%20or%20stopped%20advancing.%20Partial%20results%20are%20shown%20below.%27%29%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20const%20occasions%20%3D%20data.bundles.flatMap%28b%20%3D%3E%20b.occasions%29%3B%0A%20%20%20%20%20%20%20%20if%20%28occasions.some%28o%20%3D%3E%20%21batch.some%28x%20%3D%3E%20x.locationId%20%3D%3D%3D%20o.locationId%29%20%7C%7C%20%21Number.isFinite%28Date.parse%28o.duration%3F.start%29%29%20%7C%7C%20%28o.examinationTypeId%20%21%3D%20null%20%26%26%20o.examinationTypeId%20%21%3D%3D%20examinationTypeId%29%20%7C%7C%20%28theory%20%26%26%20o.languageId%20%21%3D%20null%20%26%26%20o.languageId%20%21%3D%3D%20languageId%29%29%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20throw%20new%20Error%28%27The%20search%20returned%20unexpected%20appointment%20details.%20Partial%20results%20are%20shown%20below.%27%29%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20for%20%28const%20item%20of%20batch%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20const%20found%20%3D%20occasions.filter%28o%20%3D%3E%20o.locationId%20%3D%3D%3D%20item.locationId%20%26%26%20Date.parse%28o.duration.start%29%20%3E%3D%20Date.now%28%29%29%0A%20%20%20%20%20%20%20%20%20%20%20%20.sort%28%28a%2C%20b%29%20%3D%3E%20Date.parse%28a.duration.start%29%20-%20Date.parse%28b.duration.start%29%29%3B%0A%20%20%20%20%20%20%20%20%20%20item.searchedMonths%20%3D%20data.searchedMonths%3B%0A%20%20%20%20%20%20%20%20%20%20if%20%28found.length%29%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20const%20o%20%3D%20found%5B0%5D%3B%0A%20%20%20%20%20%20%20%20%20%20%20%20item.earliest%20%3D%20%7Bdate%3A%20o.date%2C%20time%3A%20o.time%2C%20duration%3A%20o.duration%2C%20cost%3A%20o.cost%2C%20costText%3A%20o.costText%20%7C%7C%20%27%27%7D%3B%0A%20%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20%20%20item.complete%20%3D%20%21%21item.earliest%20%7C%7C%20item.searchedMonths%20%3E%3D%20maxMonths%3B%0A%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20%20%20report.updatedAt%20%3D%20new%20Date%28%29.toISOString%28%29%3B%0A%20%20%20%20%20%20%20%20render%28%29%3B%0A%20%20%20%20%20%20%20%20if%20%28entries.some%28x%20%3D%3E%20%21x.complete%29%29%20await%20new%20Promise%28resolve%20%3D%3E%20setTimeout%28resolve%2C%20900%29%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%20%20status%28%60Search%20complete.%20Appointments%20found%20at%20%24%7Bentries.filter%28x%20%3D%3E%20x.earliest%29.length%7D%20of%20%24%7Bentries.length%7D%20locations.%20Earliest%20appointments%20are%20at%20the%20top.%60%29%3B%0A%20%20%20%20%7D%20catch%20%28error%29%20%7B%0A%20%20%20%20%20%20if%20%28%21closed%29%20%7B%0A%20%20%20%20%20%20%20%20const%20reason%20%3D%20controller.signal.reason%3B%0A%20%20%20%20%20%20%20%20status%28controller.signal.aborted%20%3F%20reason%20%3D%3D%3D%20%27timeout%27%20%3F%20%27Trafikverket%20took%20too%20long%20to%20respond.%20The%20search%20stopped%3B%20any%20partial%20results%20are%20shown%20below.%27%20%3A%20%27Search%20stopped.%20Results%20below%20may%20be%20incomplete.%27%20%3A%20error.message%20%7C%7C%20%27The%20search%20failed.%20Check%20your%20connection%20and%20Trafikverket%20login.%27%2C%20true%29%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%20finally%20%7B%0A%20%20%20%20%20%20bookingSession.socialSecurityNumber%20%3D%20%27%27%3B%0A%20%20%20%20%20%20running%20%3D%20false%3B%0A%20%20%20%20%20%20if%20%28%21closed%29%20%7B%0A%20%20%20%20%20%20%20%20%24%28%27%23start%27%29.disabled%20%3D%20%24%28%27%23test%27%29.disabled%20%3D%20%24%28%27%23language%27%29.disabled%20%3D%20%24%28%27%23vehicle%27%29.disabled%20%3D%20%24%28%27%23person%27%29.disabled%20%3D%20false%3B%0A%20%20%20%20%20%20%20%20%24%28%27%23stop%27%29.disabled%20%3D%20true%3B%0A%20%20%20%20%20%20%7D%0A%20%20%20%20%7D%0A%20%20%7D%3B%0A%20%20%24%28%27%23person%27%29.focus%28%29%3B%0A%7D%29%28%29%3B%0A
