Skip to content

Strip IME insets from browser WebView to prevent double padding - #9396

Open
lmac012 wants to merge 1 commit into
developfrom
fix/lukasz/webview-keyboard-inset
Open

Strip IME insets from browser WebView to prevent double padding#9396
lmac012 wants to merge 1 commit into
developfrom
fix/lukasz/webview-keyboard-inset

Conversation

@lmac012

@lmac012 lmac012 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Task/Issue URL: https://app.asana.com/1/137249556945/project/1205617573940217/task/1217145253883158?focus=true
Tech Design URL (if applicable):
API Proposals URL(s) (if applicable):

Description

Since WebView M139, the WebView shrinks its visual viewport by any IME inset it receives. Our layout already resizes for the keyboard, so during IME entry both mechanisms briefly apply at once, transiently collapsing the visual viewport. This was confirmed to cause breakage on gemini.google.com, where collapsing the visual viewport clears composer focus and hides the on-screen keyboard, making it nearly impossible to use the site.

Fix: zero out ime() insets before they reach the browser WebView, as recommended in Google's WebView insets guidance.

Steps to test this PR

Keyboard stays open on Gemini

  • Navigate to https://gemini.google.com in the browser
  • Tap the message composer
  • Verify the keyboard opens and stays open (before this fix it dismissed itself within ~100ms)
  • Dismiss the keyboard and repeat the test a couple of times

Kill switch

  • Disable androidBrowserConfig > stripWebViewImeInsets in internal feature flag settings
  • Restart the app
  • Navigate to https://gemini.google.com
  • Tap the message composer
  • Verify the keyboard dismisses itself almost immediately after being shown
  • If the keyboard didn't dismiss itself (may happen occasionally), dismiss it and test again.

No UI changes


Note

Medium Risk
Changes keyboard and viewport behavior for all in-app browsing when enabled; mitigated by a remote kill switch and a narrow inset adjustment.

Overview
Fixes keyboard dismissal and visual viewport collapse on sites like Gemini when WebView M139 shrinks the visual viewport for IME insets while the browser layout already resizes for the keyboard.

DuckDuckGoWebView now optionally zeros ime() insets in onApplyWindowInsets before they reach the WebView, following Android’s WebView inset guidance. BrowserTabFragment enables this via setStripImeInsetsEnabled after reading androidBrowserConfig.stripWebViewImeInsets (defaults on). Disabling the flag restores the old double-padding behavior for verification.

Reviewed by Cursor Bugbot for commit 77eed60. Bugbot is set up for automated code reviews on this repo. Configure here.

@lmac012
lmac012 marked this pull request as draft August 5, 2026 10:13
Since WebView M139 the WebView subtracts any IME inset it receives from
its visual viewport ("WebView-Window intersection" resizing). The browser
layout already resizes for the keyboard, so during IME entry both
mechanisms applied within the same frame, transiently collapsing the
visual viewport (e.g. 455dp -> 135dp on a Pixel 8). Sites that react to
visualViewport resize by clearing element focus (e.g. the
gemini.google.com composer) blurred the focused editor, making Chromium
dismiss the keyboard ~90ms after showing it.

Zero out ime() insets before they reach the WebView, as recommended in
https://developer.android.com/develop/ui/views/layout/webapps/understand-window-insets
The behavior is opt-in via DuckDuckGoWebView.setStripImeInsetsEnabled(),
enabled for the browser tab WebView behind the
androidBrowserConfig.stripWebViewImeInsets sub-feature (enabled by
default; the remote flag acts as a kill switch).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@lmac012
lmac012 force-pushed the fix/lukasz/webview-keyboard-inset branch from 393a0ea to 77eed60 Compare August 5, 2026 11:20
@lmac012 lmac012 changed the title Strip IME insets from browser WebView to prevent keyboard dismissal Strip IME insets from browser WebView to prevent double padding Aug 5, 2026
@lmac012
lmac012 marked this pull request as ready for review August 5, 2026 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant