Skip to content

Commit

Permalink
Jelly: Remove Version/4.0 from UA
Browse files Browse the repository at this point in the history
Similar to "; wv", "Version/4.0" is also hardcoded for WebView clients,
see: android_webview/browser/aw_content_browser_client.cc.

Change-Id: Iaa79a87acb58eb5b6b552893d7b5f02b042537e8
  • Loading branch information
SaeedDev94 authored and luk1337 committed Dec 24, 2024
1 parent ab14dab commit 2723b5e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/src/main/java/org/lineageos/jelly/webview/WebViewExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,19 @@ class WebViewExt @JvmOverloads constructor(
activity.downloadFileAsk(url, userAgent, contentDisposition, mimeType, contentLength)
}

// Mobile: Remove "wv" from the WebView's user agent. Some websites don't work
// properly if the browser reports itself as a simple WebView.
// Mobile: Remove "wv" and "Version/4.0" from the WebView's user agent.
// Some websites don't work properly if the browser reports itself as a simple WebView.
// Desktop: Generate the desktop user agent starting from the mobile one so that
// we always report the current engine version.
val pattern = Pattern.compile("([^)]+ \\()([^)]+)(\\) .*)")
val matcher = pattern.matcher(settings.userAgentString)
if (matcher.matches()) {
val mobileDevice = matcher.group(2)!!.replace("; wv", "")
mobileUserAgent = matcher.group(1)!! + mobileDevice + matcher.group(3)
mobileUserAgent = matcher.group(1)!! + mobileDevice + matcher.group(3)!!
.replace(" Version/4.0 ", " ")
desktopUserAgent = matcher.group(1)!! + DESKTOP_DEVICE + matcher.group(3)!!
.replace(" Mobile ", " ")
.replace(" Version/4.0 ", " ")
settings.userAgentString = mobileUserAgent
} else {
Log.e(TAG, "Couldn't parse the user agent")
Expand Down

0 comments on commit 2723b5e

Please sign in to comment.