Skip to content

Commit 6c3c273

Browse files
Log WebView login hook failures
1 parent bf7cf4d commit 6c3c273

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

android/app/src/main/java/com/clhs/score/ui/WebViewLoginScreen.kt

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ package com.clhs.score.ui
22

33
import android.annotation.SuppressLint
44
import android.graphics.Bitmap
5+
import android.util.Log
56
import android.view.View
67
import android.webkit.CookieManager
8+
import android.webkit.ConsoleMessage
79
import android.webkit.JavascriptInterface
810
import android.webkit.WebChromeClient
911
import android.webkit.WebResourceRequest
@@ -47,6 +49,8 @@ import androidx.compose.ui.viewinterop.AndroidView
4749

4850
private const val LOGIN_URL = "https://shcloud2.k12ea.gov.tw/CLHSTYC/Auth/Auth/CloudLogin"
4951
private const val SCHOOL_DOMAIN = "shcloud2.k12ea.gov.tw"
52+
private const val LOGIN_HOOK_LOG_PREFIX = "[ScoreLoginHook]"
53+
private const val WEB_VIEW_LOGIN_TAG = "WebViewLogin"
5054

5155
@Composable
5256
fun WebViewLoginScreen(
@@ -260,6 +264,15 @@ private fun WebViewContent(
260264
override fun onProgressChanged(view: WebView?, newProgress: Int) {
261265
onProgressChanged(newProgress)
262266
}
267+
268+
override fun onConsoleMessage(consoleMessage: ConsoleMessage?): Boolean {
269+
val message = consoleMessage?.message().orEmpty()
270+
if (message.startsWith(LOGIN_HOOK_LOG_PREFIX)) {
271+
Log.w(WEB_VIEW_LOGIN_TAG, message)
272+
return true
273+
}
274+
return super.onConsoleMessage(consoleMessage)
275+
}
263276
}
264277

265278
onWebViewCreated(this)
@@ -322,13 +335,17 @@ private val LOGIN_HOOK_JS = """
322335
try {
323336
var loginField = document.querySelector('input[name="LoginId"]');
324337
if (loginField) loginId = loginField.value || '';
325-
} catch(e) {}
338+
} catch(e) {
339+
console.warn('$LOGIN_HOOK_LOG_PREFIX LoginId field lookup failed: ' + (e && e.message ? e.message : e));
340+
}
326341
327342
if (!loginId && body) {
328343
try {
329344
var params = new URLSearchParams(body);
330345
loginId = params.get('LoginId') || '';
331-
} catch(e) {}
346+
} catch(e) {
347+
console.warn('$LOGIN_HOOK_LOG_PREFIX LoginId body parse failed: ' + (e && e.message ? e.message : e));
348+
}
332349
}
333350
334351
self.addEventListener('load', function() {
@@ -339,7 +356,9 @@ private val LOGIN_HOOK_JS = """
339356
window.AndroidLogin.onLoginSuccess(loginId);
340357
}
341358
}
342-
} catch(e) {}
359+
} catch(e) {
360+
console.warn('$LOGIN_HOOK_LOG_PREFIX Login response handling failed: ' + (e && e.message ? e.message : e));
361+
}
343362
});
344363
}
345364
return origSend.apply(this, arguments);

0 commit comments

Comments
 (0)