[Bug]: iOS UIScene template starts a second web app instance when an external display or AirPlay mirroring connects
メンテナーはふだん 2 日以内に返信
@theproducer がすでに取り組んでいます。
2026年10月9日 から。
評価
この issue はまだ評価されていません。
説明
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.
- 主要言語
- TypeScript
- スター
- 17.1k
- フォーク
- 1.3k
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 32
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ionic-team/capacitor のほかの issue
-
[Bug]: Plugin call after navigation can be answered before reply proxy is updated対応中かも @MateStrysewske が 56 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
ionic-team/capacitor#8616 ·
メンテナーはふだん 2 日以内に返信
-
[Bug]: SystemBars shrinks the WebView twice for the keyboard on Android 10 (API 29) when WebView >= 140 and viewport-fit=cover対応中かも @theproducer が 18 日前に担当しました。 オープンneeds reply
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor#8601 · コメント 2 件 · リアクション 3 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
-
help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
ionic-team/capacitor#8574 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信
-
SystemBars: safe area CSS injection throws "Cannot read properties of null" on startup (Android 16)対応中かも @kttalley が 47 日前に担当しました。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor#8530 · コメント 2 件 ·
メンテナーはふだん 2 日以内に返信
-
fix(android): remove unchecked Java compilation warnings対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンtriage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
ionic-team/capacitor#8529 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
ionic-team/capacitor の issue をすべて見る
似ている issue
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
lingdojo/kana-dojo#34223 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
bug status: needs triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
mastra-ai/mastra#30587 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
area:web p2 product:business triage:active type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
cuadrao-ai/argus#2228 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
embedpdf/embed-pdf-viewer#1098 ·
メンテナーはふだん 1 日以内に返信
-
.Needs Triage .Team/Metabot Priority:P3 Type:Bug
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
metabase/metabase#87252 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信