Fix invalid mime type in Jetbrains IDE

connection.url.toString() contains values like:

jar:file:/Users/some.username/Library/Application%20Support/JetBrains/IntelliJIdea2024.3/plugins/continue-intellij-extension/lib/instrumented-continue-intellij-extension-1.0.2.jar!/webview/index.html

if user has "js" in his home folder name then index.html will be treated as text/javascript and continue dev sidebar will output html source code instead of working app
This commit is contained in:
Piotr Czekaj 2025-03-05 11:47:53 +01:00
parent 54c364d1cd
commit 9404e00e91

View file

@ -111,7 +111,10 @@ class OpenedConnection(private val connection: URLConnection?) :
) {
try {
if (connection != null) {
val url = connection.url.toString()
val fullUrl = connection.url.toString()
// Extract only the resource path after the JAR prefix to prevent incorrect mime type matching
// (e.g., if a user's home folder contains "js" in the path)
val url = fullUrl.substringAfterLast("jar!/", fullUrl)
when {
url.contains("css") -> cefResponse.mimeType = "text/css"
url.contains("js") -> cefResponse.mimeType = "text/javascript"