javascriptcgtk3webkit2webkit2-webextension

How to expose native code to javascript in webkit2gtk


I want to expose a native object or function to javascript so that i can have a callback function in C when the particular function is called in browser.

From this example, it seems it is possible in WebKitGTK1 using the signal "window-object-cleared".

How can i achieve the same in WebKitGTK2, i hope it has something to do with WebKitWebExtension. But i am not sure and also there is not clear guidelines or examples for implementing WebKitWebExtension. Can anyone help me with a solution for my request ?


Solution

  • Yes, WebKitWebExtension is the way to do this. Currently the best documentation on how to write one of those, is this blog post. There is a window-object-cleared signal similar to WebKit1 that you can connect to in your web extension and there use the JavaScriptCore API to define Javascript functions that are visible to your web page.