pythonista-webview icon indicating copy to clipboard operation
pythonista-webview copied to clipboard

Wkwebview crashes at start in Pythonista beta 340007

Open cvpe opened this issue 2 years ago • 7 comments

WKWebView.py it-self crashes with this error

The app was terminated due to an Objective-C exception. Details below:

2023-03-14 15:32:08.098719 Completion handler passed to -[CustomNavigationDelegate webView:decidePolicyForNavigationAction:decisionHandler:] was not called

Something similar? Here
https://github.com/pichillilorenzo/flutter_inappwebview/issues/1221

cvpe avatar Mar 14 '23 16:03 cvpe

Thanks for reporting this. Seems something has changed in Apple APIs.

It is unlikely I will look at this soon. PRs are very welcome.

mikaelho avatar Mar 15 '23 07:03 mikaelho

WKWebView does not work with version 3.4 (Release of AppStore that is not TestFlight), is it the same problem?

ghost avatar Apr 28 '23 23:04 ghost

This issue with my WKWebView wrapper is unlikely to be dependent on Pythonista version.

But the soon-to-be-released version of Pythonista is expected to contain an ”official” (and working) version of WKWebView.

mikaelho avatar Apr 29 '23 05:04 mikaelho

Yes but the Pythonista WkWebView does not support the add_script method

cvpe avatar Apr 29 '23 06:04 cvpe

Hmm, it’s like 5 lines of code. Maybe we could see if we could get it added to the core version, or subclass and it ourselves.

mikaelho avatar Apr 29 '23 06:04 mikaelho

Sure!

cvpe avatar Apr 29 '23 07:04 cvpe

This modified version is working for me on Pythonista 3.4. https://gist.github.com/sbbosco/1290f59d79c6963e62bb678f0f05b035

Changes are:

    def __init__(self,
            swipe_navigation=False,
            data_detectors=NONE,
            log_js_evals=False,
            respect_safe_areas=False,
            inline_media=None,
            airplay_media=True,
            pip_media=True,
            **kwargs):

        dummy = self.dummy_webview()
        del dummy

        WKWebView.webviews.append(self)

    @on_main_thread
    def dummy_webview(self):
        dummy1 = WKWebView.WKWebView.alloc().initWithFrame_(((0,0), (100, 100))).autorelease()

    #@on_main_thread
    def _eval_js_sync_callback(self, value):
        self.eval_js_queue.put(value)

    #@on_main_thread
    def eval_js_async(self, js, callback=None):

    @ui.in_background
    def clear_cache(self, completion_handler=None):

#v.clear_cache()

sbbosco avatar Apr 30 '23 00:04 sbbosco