HTML artifacts (Android): enable DOM storage + pin a real base URL so localStorage/sessionStorage work — the library defaults domStorageEnabled off and a null base URL leaves the page on the opaque about:blank origin where the storage APIs throw, so interactive artifacts that persist state appeared broken; basic JS (DOM/event handlers) already ran

This commit is contained in:
ARIA committed 2026-08-21 01:05:31 +02:00
1 parent 0951ebbbce
commit 2f0cdbba17
1 file changed
+12 -3
@@ -10,12 +10,21 @@ import com.multiplatform.webview.web.WebView
import com.multiplatform.webview.web.rememberWebViewStateWithHTMLData import com.multiplatform.webview.web.rememberWebViewStateWithHTMLData
/** /**
* M9: HTML artifact preview on Android — the platform WebView (JavaScript * M9: HTML artifact preview on Android — the platform WebView.
* enabled by default in the library's WebSettings). *
* 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 @Composable
actual fun PlatformWebView(html: String, modifier: Modifier) { 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) WebView(state, modifier = modifier)
} }