Bug: with gui_hooks.webview_did_receive_js_message

from typing import Any

from aqt import gui_hooks

def handle_calls(handled: tuple[bool, Any], message: str, context: Any) -> tuple[bool, Any]:
    if not message.startswith('myaddon:'):
        return handled
    # handle my custom message ...
    return (True, None) # but how to give the JavaScript information??

gui_hooks.webview_did_receive_js_message(handle_calls)

causes the error

    gui_hooks.webview_did_receive_js_message(handle_calls)
TypeError: __call__() missing 2 required positional arguments: 'message' and 'context'

You’re not using hooks correctly.
https://addon-docs.ankiweb.net/hooks-and-filters.html#new-style-hooks

2 Likes