Skip to content

Commit db4ed5a

Browse files
committed
WasmJs iframe shadowRoot fix
1 parent e847779 commit db4ed5a

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

webview-compose/src/wasmJsMain/kotlin/io/github/kdroidfilter/webview/web/HtmlView.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import kotlinx.serialization.json.put
2020
import org.w3c.dom.Element
2121
import org.w3c.dom.HTMLDivElement
2222
import org.w3c.dom.HTMLIFrameElement
23+
import org.w3c.dom.Node
2324
import org.w3c.dom.events.Event
2425
import kotlin.uuid.ExperimentalUuidApi
2526
import kotlin.uuid.Uuid
@@ -43,7 +44,7 @@ fun HtmlView(
4344
) {
4445
val scope = rememberCoroutineScope()
4546
val element = remember { mutableStateOf<HTMLIFrameElement?>(null) }
46-
val root = LocalLayerContainer.current
47+
val root: Node = document.body?.shadowRoot ?: document.body!!
4748
val density = LocalDensity.current.density
4849
val focusManager = LocalFocusManager.current
4950

@@ -74,7 +75,7 @@ fun HtmlView(
7475
componentReady.value = true
7576
val container = componentInfo.container as HTMLDivElement
7677

77-
(root as Element).appendChild(container)
78+
root.appendChild(container)
7879
container.append(componentInfo.component)
7980

8081
container.style.position = "absolute"
@@ -177,7 +178,7 @@ fun HtmlView(
177178
}
178179

179180
onDispose {
180-
(root as Element).removeChild(componentInfo.container)
181+
root.removeChild(componentInfo.container)
181182
componentInfo.updater.dispose()
182183
element.value?.let { onDispose(it) }
183184
state.htmlElement = null

webview-compose/src/wasmJsMain/kotlin/io/github/kdroidfilter/webview/web/WebView.wasmJs.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ import io.github.kdroidfilter.webview.setting.WebSettings
1313
import io.github.kdroidfilter.webview.util.KLogger
1414
import kotlinx.browser.document
1515
import kotlinx.coroutines.launch
16-
import org.w3c.dom.Element
1716
import org.w3c.dom.HTMLIFrameElement
17+
import org.w3c.dom.Node
1818

1919
/**
2020
* Platform-specific parameters for the WebView factory in WebAssembly/JavaScript.
2121
*/
2222
actual class WebViewFactoryParam {
23-
var container: Element = document.body!!
23+
var container: Node = document.body?.shadowRoot ?: document.body!!
2424
var existingElement: HTMLIFrameElement? = null
2525
}
2626

0 commit comments

Comments
 (0)