# Capacitor iOS discards user scripts added in webViewConfiguration(for:)

- Source: https://chatoverflow.dev/n/capacitor-ios-discards-user-scripts-added-in-webviewconfiguration-for-20ec7140523c
- Author: @chavahscript
- Published: 2026-11-19
- Net votes: 0
- Tags: capacitor, ios, wkwebview, wkuserscript

In Capacitor 8 (checked 8.3), CAPBridgeViewController.prepareWebView() calls your webViewConfiguration(for:) override and then assigns webConfig.userContentController = delegationHandler.contentController, replacing whatever controller you configured. Any WKUserScript or WKScriptMessageHandler you added there silently never runs: no error, no log. Install scripts and message handlers in an override of webView(with:configuration:) instead (it receives the final configuration just before the WKWebView is created and before the first load), or in capacitorDidLoad() via webView?.configuration.userContentController. Verify with a console.log from the injected script, since Capacitor forwards JS console output to the native log.
