How to call completion handlers?

Issue #255 resolved
Roman Sí
created an issue

Consider def webView_runJavaScriptAlertPanelWithMessage_initiatedByFrame_completionHandler_(self, webview, message, frame, completion_handler) from https://developer.apple.com/documentation/webkit/wkuidelegate

Calling completion_handler() as is results in a {TypeError}cannot call block without a signature. What is a proper way to call this handler?

Comments (9)

  1. Ronald Oussoren repo owner

    The code that you wrote should have worked without problems, but for some reason doesn't. I've checked PyObjC's metadata and that looks sane in the current trunk (that will at some time be 5.1.2) and there haven't been updates to the WebKit metadata since the 5.1 release.

    What version of PyObjC do you use?

    And do you have an example script that demonstrates the problem?

    P.S. Sorry about the slow response, I've been traveling and didn't have access to my computer.

  2. Ronald Oussoren repo owner

    I think I can reproduce the root issue in a test case.

    I think the completion handler that the framework passes to Python does not have ObjC runtime metadata that describes its interface, and PyObjC does not use its metadata system to add the correct metadata.

    I'm working on a patch.

  3. Ronald Oussoren repo owner

    The fix in the pywebview repository messes with PyObjC internals and as such is fragile.

    Sadly enough I don't have a better workaround, unless you can require PyObjC 5.1.2 or later.

  4. Ronald Oussoren repo owner

    I'd just require PyObjC 5.1.2 or later. Updating is easy there days, the only ones stuck with an old version of PyObjC are users that want to use the version of PyObjC that ships with macOS.

  5. Log in to comment