[wpe-webkit] Calling a JS function from a web extension thread aborts

Ludovic Cintrat ludovic.cintrat at nexvision.fr
Mon May 10 09:40:56 PDT 2021

Hi all,

I am writing a web extension for WPE Webkit, and the extension needs to 
asynchronously send and signal new data to the JS context.
Relevant parts of the native code below.


JSCValue *metadata_callback;

void register_metadata_callback(JSCValue *value) {



   metadata_callback = value;

void register_class(JSCContext *context) {

   JSCClass *jscClass = jsc_context_register_class(context, "Pipeline", 
                                                   nullptr, nullptr);
   g_assert_true(jscClass != nullptr);

   JSCValue *constructor = jsc_class_add_constructor(
       jscClass, nullptr, G_CALLBACK(pipeline_init), nullptr, nullptr,
       pipeline_get_type(), 1, G_TYPE_STRING);

   g_assert_true(constructor != nullptr);

   jsc_class_add_method(jscClass, "registerMetadataCallback",
                        nullptr, nullptr, G_TYPE_NONE, 1, JSC_TYPE_VALUE);

   jsc_context_set_value(context, "Pipeline", constructor);


And from another thread created by the extension, the following code is 

jsc_value_function_call(metadata_callback, G_TYPE_NONE);


JS part:

var pipeline = new Pipeline("test")


Abort occurs with the following message if the JS callback function 
changes the DOM:

ASSERTION FAILED: Unsafe to ref/deref from different threads
m_isOwnedByMainThread == isMainThread()
DerivedSources/ForwardingHeaders/wtf/RefCounted.h(114) : void 
WTF::RefCountedBase::applyRefDerefThreadingCheck() const

If only a JS variable is changed for example there is no such abort.

How can I call a JS callback from the main thread from a web extension?
Maybe another way exists for that feature?

Best regards,

More information about the webkit-wpe mailing list