Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow extension of WebViewDelegationHandler in iOS #6605

Closed
e-e-e opened this issue May 19, 2023 · 5 comments
Closed

feat: Allow extension of WebViewDelegationHandler in iOS #6605

e-e-e opened this issue May 19, 2023 · 5 comments
Assignees
Labels
platform: ios type: feature request A new feature, enhancement, or improvement

Comments

@e-e-e
Copy link

e-e-e commented May 19, 2023

Feature Request

Description

We are wanting to run custom crashlytics reporting within our capacitor app to get observability on any unusual spikes in webview crashes per a release. In order to do this we want to report errors within the WKNavigationDelegate's webViewWebContentProcessDidTerminate method, so that we can monitor the number of times our webviews are being terminated.

At the time of writing, Capacitor on iOS sets the webview's navigation delegate to an instance of WebViewDelegationHandler which has a lot of extra functionality, including reloading the webview on crashes. We experimented with overwriting the webviews navigation delegate with our own custom implementation, however this caused issues as doing so removed the functionality from WebViewDelegationHandler.

Platform(s)

iOS

Preferred Solution

Remove internal scoping from WebViewDelegationHandler to allow consumers to extend its functionality through extensions.

Alternatives

I am not a strong swift developer, so am unsure if there are better alternatives. Open to any suggestions as to how else we could execute custom code when the webview is unexpectedly terminated.

Additional Context

We are able to add such override behavior on android as such:

public class CrashReportingWebViewClient extends BridgeWebViewClient { ... }
public class MainActivity extends BridgeActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        WebView webView = this.bridge.getWebView();
        CrashReportingWebViewClient webViewClient = new CrashReportingWebViewClient(this.bridge);
        webView.setWebViewClient(webViewClient);
    }
}
~~
@peitschie
Copy link

I've got a PR for Android that exposes this as a plugin hook: #6416

If we can get any type of buy-in from the core Capacitor team, I'd be happy to extend that to support this use-case as well 🙂

Just for my own record keeping, there's some existing discussion about this hook #5260 and #5488

@markemer markemer added the type: feature request A new feature, enhancement, or improvement label May 30, 2023
@markemer markemer self-assigned this May 30, 2023
@alextreppass
Copy link

Hi @markemer thanks for picking this up. Making the change backwards-compatible with Capacitor 4 would be great if possible, we'd love to use this but are not yet in a position to upgrade to 5 🤞🏼

@gummibjorn
Copy link

Hi @markemer

We would also be interested in having the option to extend the WebViewDelegationHandler in iOS.

e.g.
Screenshot 2023-09-25 at 09 28 39

Something like that would be awesome.

Please contact me if this seems feasible to you.

BR
Mario

@jcesarmobile
Copy link
Member

It's already possible to use your own WebViewDelegationHandler by using a custom ViewController

But also, in Capacitor 6 WebViewDelegationHandler will be public #6894

@ionitron-bot
Copy link

ionitron-bot bot commented Oct 25, 2023

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Oct 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
platform: ios type: feature request A new feature, enhancement, or improvement
Projects
None yet
Development

No branches or pull requests

7 participants