Skip to content

Enable passkey support in browser for internal builds #6550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ import com.duckduckgo.app.browser.viewstate.LoadingViewState
import com.duckduckgo.app.browser.viewstate.OmnibarViewState
import com.duckduckgo.app.browser.viewstate.PrivacyShieldViewState
import com.duckduckgo.app.browser.viewstate.SavedSiteChangedViewState
import com.duckduckgo.app.browser.webauthn.WebViewPasskeyInitializer
import com.duckduckgo.app.browser.webshare.WebShareChooser
import com.duckduckgo.app.browser.webview.WebContentDebugging
import com.duckduckgo.app.browser.webview.WebViewBlobDownloadFeature
Expand Down Expand Up @@ -583,6 +584,9 @@ class BrowserTabFragment :
@Inject
lateinit var androidBrowserConfigFeature: AndroidBrowserConfigFeature

@Inject
lateinit var passkeyInitializer: WebViewPasskeyInitializer

/**
* We use this to monitor whether the user was seeing the in-context Email Protection signup prompt
* This is needed because the activity stack will be cleared if an external link is opened in our browser
Expand Down Expand Up @@ -3111,6 +3115,10 @@ class BrowserTabFragment :
}

WebView.setWebContentsDebuggingEnabled(webContentDebugging.isEnabled())

lifecycleScope.launch {
webView?.let { passkeyInitializer.configurePasskeySupport(it) }
}
}

private fun screenLock(data: JsCallbackData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ class DuckDuckGoWebView : WebView, NestedScrollingChild3 {
}
}

fun isDestroyed(): Boolean {
return isDestroyed
}

@SuppressLint("RequiresFeature", "AddWebMessageListenerUsage")
suspend fun safeAddWebMessageListener(
webViewCapabilityChecker: WebViewCapabilityChecker,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright (c) 2025 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.app.browser.webauthn

import android.annotation.SuppressLint
import androidx.webkit.WebSettingsCompat
import androidx.webkit.WebSettingsCompat.WEB_AUTHENTICATION_SUPPORT_FOR_BROWSER
import androidx.webkit.WebViewFeature
import androidx.webkit.WebViewFeature.WEB_AUTHENTICATION
import com.duckduckgo.app.browser.DuckDuckGoWebView
import com.duckduckgo.autofill.api.AutofillFeature
import com.duckduckgo.common.utils.DispatcherProvider
import com.duckduckgo.di.scopes.AppScope
import com.squareup.anvil.annotations.ContributesBinding
import javax.inject.Inject
import kotlinx.coroutines.withContext
import logcat.logcat

interface WebViewPasskeyInitializer {
suspend fun configurePasskeySupport(webView: DuckDuckGoWebView)
}

@ContributesBinding(AppScope::class)
class RealWebViewPasskeyInitializer @Inject constructor(
private val autofillFeature: AutofillFeature,
private val dispatchers: DispatcherProvider,
) : WebViewPasskeyInitializer {

override suspend fun configurePasskeySupport(webView: DuckDuckGoWebView) {
if (featureFlagEnabled() && webViewCapable()) {
enablePasskeySupport(webView)
}
}

@SuppressLint("RequiresFeature")
private suspend fun enablePasskeySupport(webView: DuckDuckGoWebView) {
withContext(dispatchers.main()) {
if (!webView.isDestroyed()) {
WebSettingsCompat.setWebAuthenticationSupport(webView.settings, WEB_AUTHENTICATION_SUPPORT_FOR_BROWSER)
logcat { "Autofill-passkey: WebView passkey support (WebAuthn) enabled" }
}
}
}

private suspend fun featureFlagEnabled(): Boolean {
return withContext(dispatchers.io()) {
autofillFeature.passkeySupport().isEnabled()
}
}

private suspend fun webViewCapable(): Boolean {
return withContext(dispatchers.main()) {
WebViewFeature.isFeatureSupported(WEB_AUTHENTICATION)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,7 @@ interface AutofillFeature {

@Toggle.DefaultValue(defaultValue = DefaultFeatureValue.TRUE)
fun canShowImportOptionInAppSettings(): Toggle

@Toggle.DefaultValue(defaultValue = DefaultFeatureValue.INTERNAL)
fun passkeySupport(): Toggle
}
2 changes: 2 additions & 0 deletions autofill/autofill-impl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.duckduckgo.autofill.impl">

<uses-permission android:name="android.permission.CREDENTIAL_MANAGER_SET_ORIGIN" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is required for browsers as we're a special kind of app that is looking to interact with passkeys based on URLs (origins) rather than app package IDs. Google has us listed as an app with privileges to do this (most general apps cannot).


<application>
<activity
android:name=".ui.credential.management.importpassword.ImportPasswordsActivity"
Expand Down
Loading