This commit is contained in:
844143714@qq,com 2026-05-14 22:25:03 +08:00
parent 1da8168558
commit cd09ed6429
1 changed files with 9 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoSession
import org.mozilla.geckoview.GeckoSessionSettings
import org.mozilla.geckoview.GeckoView
import org.mozilla.geckoview.StorageController.ClearFlags
import org.mozilla.geckoview.WebRequestError
import timber.log.Timber
@ -31,6 +32,7 @@ class MainActivity : AppCompatActivity() {
@JvmStatic
fun executeJs(script: String) {
Timber.tag("ExecuteJs").d(script)
synchronized(pendingJsCode ?: Any()) {
// 合并多次调用(用换行分隔)
pendingJsCode = if (pendingJsCode != null) "$pendingJsCode;$script" else script
@ -197,6 +199,13 @@ class MainActivity : AppCompatActivity() {
val runtime = GeckoRuntime.getDefault(this)
runtime.settings.aboutConfigEnabled = true
runtime.settings.consoleOutputEnabled = true
// 强制清缓存,确保 JS/CSS 等资源获取最新版本
try {
// runtime.storageController.clearData(ClearFlags.ALL)
Timber.tag("MainActivity").i("GeckoView cache cleared")
} catch (e: Exception) {
Timber.tag("MainActivity").w(e, "Failed to clear GeckoView cache")
}
return runtime
}