I am having trouble getting the JavaScriptCore to work with WebKit2Gtk. In my C application I am using WebKit2Gtk as a frontend for my application which I want to be able to access C functions.
There are a couple of examples with WebKitGtk (not the WebKit2 version). However in the mailing lists there are some information that given the threaded nature of WebKit2Gtk, it is more complicated. Unfortunately I have not found any example.
I wrote this code in the load callback:
JSGlobalContextRef jsContext = webkit_web_view_get_javascript_global_context
(WEBKIT_WEB_VIEW(gtk_webview));
JSEvaluateScript(jsContext,JSStringCreateWithUTF8CString
("$('#debuginfo').html('JS API OK')"),0,0,0,0);
Unfortunately absolutely nothing happens in WebKit2Gtk. However if I use the new function defined in the API docs and execute the following, I get the output as desired.
webkit_web_view_run_javascript(WEBKIT_WEB_VIEW(gtk_webview),
"$('#debuginfo').html('JS API OK')",NULL,NULL,NULL);
The new API with the run-javascript-function is ok to quickly execute JS-code, but I want to allow the JS code inside WebKit2Gtk to execute functions from JS that I can handle in my C code.
Looking forward to your help as I am kind of stuck with this thing and before reverting back to WebKitGtk (not the WebKit2Gtk version, but the previous), I quickly want to check if you guys have any idea on how to achieve it.