From 7f91e0b687bfc4775ce7a92ca77788d35b83b8b6 Mon Sep 17 00:00:00 2001 From: rsinukov Date: Tue, 18 Oct 2022 14:45:21 +0200 Subject: [PATCH] KTOR-4993 Fix UrlBuilder origin in iframe --- ktor-http/js/src/io/ktor/http/URLBuilderJs.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/ktor-http/js/src/io/ktor/http/URLBuilderJs.kt b/ktor-http/js/src/io/ktor/http/URLBuilderJs.kt index e1693ca3fa..11573e5749 100644 --- a/ktor-http/js/src/io/ktor/http/URLBuilderJs.kt +++ b/ktor-http/js/src/io/ktor/http/URLBuilderJs.kt @@ -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" }