From 73815b032a47a584aee34e958cc96e10469a6e2e Mon Sep 17 00:00:00 2001 From: ARIA Date: Fri, 21 Aug 2026 01:05:31 +0200 Subject: [PATCH] =?UTF-8?q?HTML=20artifacts=20(Android):=20enable=20DOM=20?= =?UTF-8?q?storage=20+=20pin=20a=20real=20base=20URL=20so=20localStorage/s?= =?UTF-8?q?essionStorage=20work=20=E2=80=94=20the=20library=20defaults=20d?= =?UTF-8?q?omStorageEnabled=20off=20and=20a=20null=20base=20URL=20leaves?= =?UTF-8?q?=20the=20page=20on=20the=20opaque=20about:blank=20origin=20wher?= =?UTF-8?q?e=20the=20storage=20APIs=20throw,=20so=20interactive=20artifact?= =?UTF-8?q?s=20that=20persist=20state=20appeared=20broken;=20basic=20JS=20?= =?UTF-8?q?(DOM/event=20handlers)=20already=20ran?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/iris/platform/AndroidWebView.kt | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/shared/src/androidMain/kotlin/iris/platform/AndroidWebView.kt b/app/shared/src/androidMain/kotlin/iris/platform/AndroidWebView.kt index 3364d31..7fc3ba2 100644 --- a/app/shared/src/androidMain/kotlin/iris/platform/AndroidWebView.kt +++ b/app/shared/src/androidMain/kotlin/iris/platform/AndroidWebView.kt @@ -10,12 +10,21 @@ import com.multiplatform.webview.web.WebView import com.multiplatform.webview.web.rememberWebViewStateWithHTMLData /** - * M9: HTML artifact preview on Android — the platform WebView (JavaScript - * enabled by default in the library's WebSettings). + * M9: HTML artifact preview on Android — the platform WebView. + * + * JavaScript is on by default in the library's WebSettings, but interactive + * artifacts also need DOM storage (localStorage/sessionStorage), which the + * library leaves disabled and which additionally requires the document to sit + * on a real origin. Loading with a null base URL puts the page on the opaque + * `about:blank` origin, where the storage APIs are inaccessible, so we pin a + * real (unresolvable) base URL and switch DOM storage on. */ +private const val ARTIFACT_BASE_URL = "https://iris-artifact.local/" + @Composable actual fun PlatformWebView(html: String, modifier: Modifier) { - val state = rememberWebViewStateWithHTMLData(data = html) + val state = rememberWebViewStateWithHTMLData(data = html, baseUrl = ARTIFACT_BASE_URL) + state.webSettings.androidWebSettings.domStorageEnabled = true WebView(state, modifier = modifier) }