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) }