@@ -24,8 +24,8 @@ function pageUrl() {
2424 * POST the fields to the script, as the form of the server-rendered page would.
2525 *
2626 * `{state}`: the next page (or the same one, with an error). `{loggedIn}`: the login is over, and the
27- * user's script runs in the GET of the reload; any answer that isn't JSON means the same (the script
28- * printed its own page).
27+ * user's script runs in the GET of the reload; any successful answer that isn't JSON means the same (the
28+ * script printed its own page). A failed one (an error of PHP, of a proxy) is an error, not a login .
2929 */
3030export async function submitForm ( fields : Record < string , string > ) : Promise < SubmitResult > {
3131 submitted = true ;
@@ -41,6 +41,10 @@ export async function submitForm(fields: Record<string, string>): Promise<Submit
4141 body : new URLSearchParams ( fields )
4242 } ) ;
4343
44+ if ( ! response . ok ) {
45+ throw new Error ( 'HTTP ' + response . status ) ;
46+ }
47+
4448 if ( ! ( response . headers . get ( 'Content-Type' ) || '' ) . includes ( 'application/json' ) ) {
4549 return { loggedIn : true } ;
4650 }
@@ -76,8 +80,9 @@ export async function pollQr(endpoint: string, query: 'getQrCode' | 'waitQrCodeO
7680 throw new Error ( 'The QR code endpoint is on another origin' ) ;
7781 }
7882
79- // the validated URL itself: a path starting with `//`, fetched on its own, would be another host
80- url . search = '?' + query ;
83+ // the validated URL itself: a path starting with `//`, fetched on its own, would be another host. With the
84+ // query of the page, which may select the session or the bot (index.php?bot=x)
85+ url . search = url . search ? url . search + '&' + query : '?' + query ;
8186 url . hash = '' ;
8287 const response = await fetch ( url . href , { credentials : 'same-origin' , cache : 'no-store' , redirect : 'error' , signal} ) ;
8388 if ( ! response . ok ) {
0 commit comments