From 0b402156c048dc5ce0079ce4facec564d460b333 Mon Sep 17 00:00:00 2001 From: ujeon Date: Wed, 17 Apr 2024 20:05:19 +0900 Subject: [PATCH] =?UTF-8?q?feat(android):=20=EA=B8=B0=EB=B3=B8=20userAgent?= =?UTF-8?q?=EC=97=90=20source=EC=97=90=EC=84=9C=20=EC=A0=84=EB=8B=AC?= =?UTF-8?q?=EB=B0=9B=EC=9D=80=20user=20agent=EB=A5=BC=20=EC=B6=94=EA=B0=80?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=ED=95=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../reactnativecommunity/webview/RNCWebViewManagerImpl.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt index d57949a09..1a4c7903f 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt @@ -418,6 +418,7 @@ class RNCWebViewManagerImpl { return } if (source.hasKey("uri")) { + val defaultUserAgent = WebSettings.getDefaultUserAgent(view.context) val url = source.getString("uri") val previousUrl = view.url if (previousUrl != null && previousUrl == url) { @@ -451,7 +452,7 @@ class RNCWebViewManagerImpl { val name = headerCasted.get("name") ?: "" val value = headerCasted.get("value") ?: "" if ("user-agent" == name.lowercase(Locale.ENGLISH)) { - view.settings.userAgentString = value + view.settings.userAgentString = "$defaultUserAgent $value" } else { headerMap[name] = value } @@ -462,7 +463,8 @@ class RNCWebViewManagerImpl { while (iter.hasNextKey()) { val key = iter.nextKey() if ("user-agent" == key.lowercase(Locale.ENGLISH)) { - view.settings.userAgentString = headers.getString(key) + val customUserAgent = headers.getString(key) + view.settings.userAgentString = "$defaultUserAgent $customUserAgent" } else { headerMap[key] = headers.getString(key) }