Skip to content

Commit 298e0ad

Browse files
authored
KTOR-4993 Fix UrlBuilder origin in iframe (#3211)
1 parent 3a10900 commit 298e0ad

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

ktor-http/js/src/io/ktor/http/URLBuilderJs.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,18 @@ import org.w3c.workers.*
1616
*/
1717
public actual val URLBuilder.Companion.origin: String
1818
get() = when {
19-
PlatformUtils.IS_BROWSER -> if (js("typeof window !== 'undefined'") as Boolean) {
20-
window.location.origin
21-
} else {
22-
js("self.location.origin") as String
19+
PlatformUtils.IS_BROWSER -> {
20+
js(
21+
"""
22+
var origin = ""
23+
if (typeof window !== 'undefined') {
24+
origin = window.location.origin
25+
} else {
26+
origin = self.location.origin
27+
}
28+
origin && origin != "null" ? origin : "http://localhost"
29+
"""
30+
) as String
2331
}
2432
else -> "http://localhost"
2533
}

0 commit comments

Comments
 (0)