RESOLVED INVALID 283160
webkit_web_view_run_javascript() incompatible with webkit_web_view_call_async_javascript_function()
https://bugs.webkit.org/show_bug.cgi?id=283160
Summary webkit_web_view_run_javascript() incompatible with webkit_web_view_call_async...
Milan Crha
Reported 2024-11-15 00:53:13 PST
According to the documentation the `webkit_web_view_call_async_javascript_function()` is meant to replace `webkit_web_view_run_javascript()` since 2.40, but these two functions are incompatible, which means any attempt to replace one with the other means also replacing all/most-of the scripts, which is not great. The problem: I've a script: document.getElementById('cnt').innerText which I want to execute form a C code. The webkit_web_view_run_javascript() returns a value, for which `jsc_value_is_string()` returns `1`, while the webkit_web_view_call_async_javascript_function() returns for the same script a value, for which jsc_value_is_undefined() returns `1`. To make the webkit_web_view_call_async_javascript_function() work I need to change the script to: return document.getElementById('cnt').innerText; but then, when I run this new script with the webkit_web_view_run_javascript() I get an exception failure: none-local://:1: SyntaxError: Return statements are only valid inside functions. (WebKitJavascriptError, 699) I thought it's a 1:1 replacement, just hiding the WebKitJavascriptResult type, but if it does completely different things, then it's a completely different story. I know the function is called "call_async_javascript_function" (with the *function* at the end, but still, JavaScript is not (only) about functions. Also, I usually provide temporary JavaScript code in the call to the `webkit_web_view_run_javascript()`, which can define a new (temporary) function, contains several statements, simply does more than just a simple call to a previously defined static/global/whatever function.
Attachments
Carlos Garcia Campos
Comment 1 2024-11-15 04:12:53 PST
Then documentation is wrong, webkit_web_view_evaluate_javascript() is the replacement for webkit_web_view_run_javascript(). webkit_web_view_call_async_javascript_function() is to run async functions that can return a promise.
Milan Crha
Comment 2 2024-11-18 02:12:03 PST
Hmm, the documentation is correct, it's me who've been wrong. I'll sign to an elementary school class where they teach people to read... :-/
Milan Crha
Comment 3 2024-11-18 02:21:12 PST
You are right. I'm sorry for the noise.
Note You need to log in before you can comment on or make changes to this bug.