[webkit-gtk] Is JS callback run from GUI thread?

Konstantin Tokarev annulen at yandex.ru
Thu Oct 19 11:30:15 PDT 2017

19.10.2017, 21:19, "Gaute Hope" <eg at gaute.vetsj.com>:
> Michael Catanzaro writes on oktober 19, 2017 17:54:
>>  On Thu, Oct 19, 2017 at 2:29 AM, Gaute Hope <eg at gaute.vetsj.com> wrote:
>>>  I am trying to use javascript in synchronized fashion, by waiting in
>>>  the calling thread using condition_variables and mutex (C++):
>>>  ```
>>>   void run_js () {
>>>     /* this runs in GTK gui thread */
>>>     webkit_web_view_run_javascript (...., callback, ...)
>>>     /* wait for notification from callback */
>>>   }
>>>   void callback (GObject *, GAsyncResult *r) {
>>>        /* non-GUI processing of result */
>>>     /* notify run_js thread */
>>>   }
>>>  ```
>>>  However, if I wait for notifications in run_js the callback is never
>>>  called. Is the JS callback somehow called from the main GTK thread?
>>  Yes, probably.
>>  Like GTK+ itself, WebKitGTK+ is not threadsafe and it must only be used
>>  from the main GTK+ thread. If you need to schedule some work from a
>>  secondary thread, then you need to post it to the main thread by using
>>  e.g. g_idle_add().
> Hi, thanks for your answer. I don't want execute JS from multiple
> threads, I want to run javascript *synchronously* from the main GTK+
> thread. Since the javascript is run async, I assume it is executed in a
> different thread/process than GTK+ main.
> However, it seems that I cannot wait for a javascript callback to happen
> in the GTK+ main thread without iterating the GTK main loop. I am using
> webkit with JS as an API (to avoid setting up webextensions and the IPC
> that follows with it), and I want to make sure that the JS is run and
> its effect on the UI are visible (or ready for drawing at least) before
> I allow any more user events to happen.

JS is executed in a different process, and you probably won't be able to receive
any result while event loop is blocked, because this result needs to be read from


> Regards, Gaute
> _______________________________________________
> webkit-gtk mailing list
> webkit-gtk at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-gtk


More information about the webkit-gtk mailing list