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:
1 parent
ac4097e9a1
commit
73815b032a
1 file changed
+12
-3
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user