Skip to content

Commit

Permalink
KTOR-4993 Fix UrlBuilder origin in iframe (#3211)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsinukov committed Oct 19, 2022
1 parent 3a10900 commit 298e0ad
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions ktor-http/js/src/io/ktor/http/URLBuilderJs.kt
Expand Up @@ -16,10 +16,18 @@ import org.w3c.workers.*
*/
public actual val URLBuilder.Companion.origin: String
get() = when {
PlatformUtils.IS_BROWSER -> if (js("typeof window !== 'undefined'") as Boolean) {
window.location.origin
} else {
js("self.location.origin") as String
PlatformUtils.IS_BROWSER -> {
js(
"""
var origin = ""
if (typeof window !== 'undefined') {
origin = window.location.origin
} else {
origin = self.location.origin
}
origin && origin != "null" ? origin : "http://localhost"
"""
) as String
}
else -> "http://localhost"
}

0 comments on commit 298e0ad

Please sign in to comment.