iOS: keyboardWillHide/keyboardDidHide are evaluated before the page loads on iPad, logging "JS Eval error" twice at launch

Aperta
#95 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
57/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ios, typescript
Ambito
mobile

Direzione di ricerca

Start with the iOS keyboard plugin’s Keyboard.m handlers for keyboardWillHide and keyboardDidHide, then compare how CapacitorBridge handles scene lifecycle events before the page loads. Reproduce on an iPad simulator and confirm the launch errors disappear while keyboard events still work after the page loads.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Report

Capacitor Version
💊   Capacitor Doctor  💊

Latest Dependencies:

  @capacitor/cli: 8.6.0
  @capacitor/core: 8.6.0
  @capacitor/android: 8.6.0
  @capacitor/ios: 8.6.0

Installed Dependencies:

  @capacitor/cli: 8.6.0
  @capacitor/core: 8.6.0
  @capacitor/android: 8.6.0
  @capacitor/ios: 8.6.0

[success] iOS looking great! 👌
[success] Android looking great! 👌

@capacitor/keyboard 8.0.6, the latest. Its Keyboard.m on main has the same handlers.

Platform(s)

iOS: iPad. Seen on the iPad Air 11-inch (M4) simulator, iOS 27.2 (Xcode 27.2). Not seen on the iPhone 18 Pro simulator.

Current Behavior

On every cold launch on iPad, the console shows two eval errors before the web view has loaded:

⚡️  Loading app at capacitor://localhost...
⚡️  JS Eval error A JavaScript exception occurred
⚡️  JS Eval error A JavaScript exception occurred
⚡️  WebView loaded

iOS posts UIKeyboardWillHideNotification and UIKeyboardDidHideNotification at launch while the web view is still loading its first page. onKeyboardWillHide: (through its timer) and onKeyboardDidHide: then call [self.bridge triggerWindowJSEventWithEventName:…]. That evaluates window.Capacitor.triggerEvent('keyboardWillHide', 'window') and …('keyboardDidHide', 'window') in a document where window.Capacitor is not defined yet, so both throw.

With an NSLog added at the top of both handlers, two cold launches logged:

⚡️  Loading app at capacitor://localhost...
[kbd-probe] willHide, loading=1
[kbd-probe] didHide, loading=1
⚡️  JS Eval error A JavaScript exception occurred
⚡️  JS Eval error A JavaScript exception occurred
⚡️  WebView loaded

(loading is self.webView.isLoading.)

The events are lost, which is harmless: the page does not exist yet, and the keyboard is hidden when it loads. But the two error lines show up on every launch, and they look like a bug in the app.

Expected Behavior

No eval error at launch. Keyboard events that arrive before the page can receive them are dropped quietly. CapacitorBridge 8.6 already does this for the scene lifecycle events (triggerSceneLifecycleJSEvent: on a cold start willEnterForeground is posted "before window.Capacitor has been defined… and surfaces as a 'JS Eval error' in the log", so it is dropped).

Code Reproduction

I haven't made a separate sample app. Seen in an Ionic Angular app on Capacitor 8.6's Swift Package Manager iOS template with @capacitor/keyboard (no keyboard config, so resize mode native). The handlers involved run the same way in any app:

  1. Install the plugin in a Capacitor 8 app and npx cap sync ios.
  2. Run the app on an iPad simulator (iPad Air 11-inch (M4), iOS 27.2) with the console attached (xcrun simctl launch --console-pty <device> <bundle id>).
  3. Read the two "JS Eval error" lines between "Loading app" and "WebView loaded".
Other Technical Details

Xcode 27.2, iOS 27.2 simulator runtime, macOS 26.6 on Apple silicon. Not checked on a physical iPad.

Additional Context

A possible fix: in the will/did hide (and show) handlers, skip triggerWindowJSEventWithEventName: while the web view has not loaded a page yet, as the bridge does. Another option is to guard the evaluated script (window.Capacitor && window.Capacitor.triggerEvent(…)). notifyListeners: is fine, since no listener exists before the page loads.

Lingua principale
TypeScript
Stelle
6
Fork
24
Merge medio
2g 4h
PR unite (30g)
6

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ionic-team/capacitor-keyboard

Tutte le issue di ionic-team/capacitor-keyboard

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.