[Bug]: iOS UIScene template starts a second web app instance when an external display or AirPlay mirroring connects
Maintainer thường phản hồi trong vòng 2 ngày
@theproducer đang làm issue này rồi.
Từ ngày 9/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
Capacitor Version
💊 Capacitor Doctor 💊
Latest Dependencies:
@capacitor/cli: 8.5.3
@capacitor/core: 8.5.3
@capacitor/android: 8.5.3
@capacitor/ios: 8.5.3
Installed Dependencies:
@capacitor/cli: 8.5.2
@capacitor/android: 8.5.2
@capacitor/core: 8.5.2
@capacitor/ios: 8.5.2
[success] iOS looking great! 👌
Other API Details
npm --version: 11.4.2
node --version: v22.16.0
pod --version: 1.16.2
Xcode 26.3 (17C529)
Plugins mentioned below: @capacitor-community/sqlite 8.1.1, @capacitor/screen-orientation 8.0.2
Platforms Affected
- iOS
- Android
- Web
Current Behavior
Since the 8.5 iOS template adopted UIScene, an app made from it starts a second, independent copy of the web app when an external display is connected or AirPlay screen mirroring starts.
Cause, in ios-pods-template/App/App/ (the SPM template has the same code):
AppDelegate.application(_:configurationForConnecting:options:)returns a configuration withdelegateClass = SceneDelegate.selffor every session role.SceneDelegate.scene(_:willConnectTo:options:)creates aUIWindowwith a newCAPBridgeViewController()for everyUIWindowScene.
When an external display connects, iOS calls configurationForConnecting with the role UIWindowSceneSessionRoleExternalDisplayNonInteractive, even though UIApplicationSupportsMultipleScenes is false. Apple DTS confirms this and says the app should not create a window for that scene unless it wants to stop mirroring: https://developer.apple.com/forums/thread/815376. (Info.plist declares the SceneDelegate only for UIWindowSceneSessionRoleApplication, but the AppDelegate method returns it for all roles.)
Result: a second CAPBridgeViewController with its own WKWebView, bridge and plugin instances, running in parallel to the main one:
- The external display shows this separate copy of the app (it stays on the start page and does not follow the device) instead of mirroring the device screen.
- Both instances share local storage. With
@capacitor-community/sqlitethis causeddatabase is lockederrors in production on iPads. - Plugins initialise twice (e.g. in-app purchase listeners).
Expected Behavior
Only the windowApplication scene gets a CAPBridgeViewController. Connecting an external display or starting AirPlay mirroring does not start a second web view, and iOS mirrors the device screen as usual.
Project Reproduction
any app created from the Capacitor 8.5 iOS template reproduces it
Additional Information
No separate repository needed: any app created from the Capacitor 8.5 iOS template reproduces it.
- Run the app in the iOS Simulator (we used iPad Air 11-inch (M3), iOS 18.5; same with iOS 26.2).
- Simulator menu I/O → External Displays → any resolution.
- The Xcode/simctl console shows a second
⚡️ Loading app at capacitor://localhost..., and Safari → Develop lists two inspectable pages for the app.
In our run iOS connected the external display scene, disconnected it and connected it again, which gave three web views.
On a real device (iPad, iPadOS 18.7.8, debug build from Xcode, AirPlay screen mirroring to a Mac):
- Start the app, then start screen mirroring from Control Center.
- The Xcode console shows another
⚡️ Loading app at capacitor://localhost...each time mirroring starts. - The Mac shows the app's start page and does not follow what happens on the iPad.
Proposed fix (what we use now), in AppDelegate.swift:
func application(_ application: UIApplication,
configurationForConnecting connectingSceneSession: UISceneSession,
options: UIScene.ConnectionOptions) -> UISceneConfiguration {
let config = UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
if connectingSceneSession.role == .windowApplication {
config.delegateClass = SceneDelegate.self
}
return config
}
Verified with the fix:
- Simulator, iOS 18.5 and 26.2: only one web app instance with an external display attached, and also on a cold start with the display already attached. The Simulator shows a black external display for every app, because it does not mirror.
- Real iPad, iPadOS 18.7.8, AirPlay to a Mac:
- Starting mirroring several times, and a cold start while mirroring, always gave exactly one
Loading app at. - The Mac mirrors the iPad screen and follows it.
- Starting mirroring several times, and a cold start while mirroring, always gave exactly one
An alternative is a role guard at the top of SceneDelegate.scene(_:willConnectTo:options:): guard session.role == .windowApplication else { return }.
Where the same code lives:
- Templates on
main(checked on 2026-10-08, identical to 8.5.2 and 8.5.3):ios-pods-template/App/App/AppDelegate.swift,ios-spm-template/App/App/AppDelegate.swift, and theSceneDelegate.swiftnext to them. - The UIScene migrator (#8544) copies
SceneDelegate.swiftand theconfigurationForConnectingmethod from the template archive, so a template fix reaches newly migrated projects. It skips projects that already containUISceneConfiguration(name:, so apps that already migrated keep the old code and need a note in the update guide. - The 8.5 update guide shows the same snippet (step 3 in
docs/main/updating/8-5.mdof capacitor-docs): https://capacitorjs.com/docs/updating/8-5
Makes it worse: @capacitor/screen-orientation 8.0.2 holds CAPBridgeViewController strongly (ScreenOrientation.capViewController), so a bridge is never released and the web views of disconnected external display scenes keep running after the display is removed. Already reported in ionic-team/capacitor-plugins#2462.
See also: the same bug class in SDL: libsdl-org/SDL#16465.
- Ngôn ngữ chính
- TypeScript
- Star
- 17.1k
- Fork
- 1.3k
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 32
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của ionic-team/capacitor
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updatedCó thể đã có người làm @MateStrysewske đã nhận 56 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
ionic-team/capacitor#8616 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Bug]: SystemBars shrinks the WebView twice for the keyboard on Android 10 (API 29) when WebView >= 140 and viewport-fit=coverCó thể đã có người làm @theproducer đã nhận 18 ngày trước. Đang mởneeds reply
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8601 · 2 bình luận · 3 reaction · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
help wanted
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
ionic-team/capacitor#8574 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)Có thể đã có người làm @kttalley đã nhận 47 ngày trước. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8530 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
fix(android): remove unchecked Java compilation warningsCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ionic-team/capacitor#8529 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của ionic-team/capacitor
Issue tương tự
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
lingdojo/kana-dojo#34223 · 1 bình luận · 5 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug status: needs triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
mastra-ai/mastra#30587 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area:web p2 product:business triage:active type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
cuadrao-ai/argus#2228 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
embedpdf/embed-pdf-viewer#1098 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
.Needs Triage .Team/Metabot Priority:P3 Type:Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
metabase/metabase#87252 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày