Skip to content

Webview Desktop - .css and .js files not working #388

@achatina

Description

@achatina

Hi there! Have an issue with WebView on Compose Desktop app:

I have a structure in my resources/assets
index.html
index.css
index.js

In index.html I'm calling them:

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Title</title>
<link href="index.css" rel="stylesheet">
</head>
<body>
.........
<script defer src="index.js"></script>
</body>

But in WebView both CSS and JS are not working.

Also, I tried fileChoose.html with styles.css from the sample - it also doesn't work.

Styles are not applied if they are in a separate file. CSS and JS inside an HTML file work fine.

This is my WebView code:

val webViewState = rememberWebViewStateWithHTMLFile(
        fileName = "index.html",
        readType = WebViewFileReadType.ASSET_RESOURCES,
    )
    val webViewNavigator = rememberWebViewNavigator()
    LaunchedEffect(Unit) {
        webViewState.webSettings.zoomLevel = 1.0

        webViewState.webSettings.apply {
            isJavaScriptEnabled = true
            zoomLevel = 1.0
            logSeverity = KLogSeverity.Debug
            backgroundColor = Color.White
        }
    }

WebView(
        state = webViewState,
        modifier = Modifier.fillMaxSize(),
        navigator = webViewNavigator,
        webViewJsBridge = jsBridge
    )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions