Skip to content

web: let a tap bring back the window's focus on iOS Safari (#485) - #492

Merged
samitbasu merged 1 commit into
mainfrom
ios-focus-485
Nov 23, 2026
Merged

samitbasu merged 1 commit into
mainfrom
ios-focus-485

Conversation

@samitbasu

Copy link
Copy Markdown
Owner

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.

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

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
@samitbasu
samitbasu merged commit 34f3cc0 into main Nov 23, 2026
4 checks passed
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