Repository navigation
web: let a tap bring back the window's focus on iOS Safari (#485) - #492
Merged
Merged
Conversation
On iOS Safari, once something outside the page takes the window's focus (the address bar, reproduced on demand), the keyboard never comes back. eframe cancels every touch on the canvas, and Safari returns the window's focus only for a tap it handles itself, so no tap on the canvas can undo it. eframe's own focus check reads `document.activeElement`, which never leaves the canvas or its text agent, so egui sees nothing wrong and keeps focusing the agent inside each tap to no effect. `eggshell_ui::web::should_prevent_default` (wasm32) is a drop-in for eframe's `WebOptions::should_prevent_default`: it prevents the browser's default as eframe's default does, except while `document.hasFocus()` is false. `PageFocus` carries that state and the policy (`PageFocus::prevents_default`) for apps that combine it with a rule of their own. The examples install it. Device results (iPhone, iOS 18.7, Safari) that shaped it: - leave the whole touch to the browser: window focus back on the first tap, every time (7 of 7 losses in one session); keyboard on the second - leave the press, cancel the release: no recovery - whole touch plus cancelling the compatibility mousedown: same as the first; window focus returns after the tap's touchend handlers have run, so one tap is the floor for restoring focus and the keyboard needs the next Behaviour changes (web only): - While the page lacks the window's focus, one tap on the canvas is not prevented: the browser restores focus and sends its compatibility mouse events for that tap, which eframe does not act on. Once the page has focus, nothing differs from eframe's default. Part of #485 (the stuck-keyboard state). The intermittent first-tap miss (egui's IME output one pass after focus) is not addressed here. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PWiKKfuCkqYUunfU4wxsRK
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
On iOS Safari, once something outside the page takes the window's focus
(the address bar, reproduced on demand), the keyboard never comes back.
eframe cancels every touch on the canvas, and Safari returns the window's
focus only for a tap it handles itself, so no tap on the canvas can undo
it. eframe's own focus check reads
document.activeElement, which neverleaves the canvas or its text agent, so egui sees nothing wrong and keeps
focusing the agent inside each tap to no effect.
eggshell_ui::web::should_prevent_default(wasm32) is a drop-in foreframe's
WebOptions::should_prevent_default: it prevents the browser'sdefault as eframe's default does, except while
document.hasFocus()isfalse.
PageFocuscarries that state and the policy(
PageFocus::prevents_default) for apps that combine it with a rule oftheir own. The examples install it.
Device results (iPhone, iOS 18.7, Safari) that shaped it:
tap, every time (7 of 7 losses in one session); keyboard on the second
first; window focus returns after the tap's touchend handlers have run,
so one tap is the floor for restoring focus and the keyboard needs the
next
Behaviour changes (web only):
prevented: the browser restores focus and sends its compatibility mouse
events for that tap, which eframe does not act on. Once the page has
focus, nothing differs from eframe's default.
Part of #485 (the stuck-keyboard state). The intermittent first-tap miss
(egui's IME output one pass after focus) is not addressed here.
Tried on the device: the user tried the fix on an iPhone (iOS 18.7, Safari) at a trial page and couldn't break it. The keyboard covering the edited field (#485 §4, after #486) also stays open. The device traces and analysis are on #485.
🤖 Generated with Claude Code
https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up