[wpe-webkit] Synchronous JS interactions with native code

Ryan Walklin ryan at testtoast.com
Mon Jun 24 17:20:22 PDT 2019


Hi All,

I'm currently experimenting with implementing a basic subset of the WebExtension API (https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions) with WPE, and struggling with some basics. This may be due to my poor knowledge of JS, or sheer impossibility, but I'd love some help.

I know that Midori has a stub implementation using WebKitGTK (https://github.com/midori-browser/core/pull/250) and they use a combination of webkit_user_content_manager_register_script_message_handler to register a script handler, then in JS call window.webkit.messageHandlers.midori.postMessage to get back to UI code, then in their UI code use webkit_web_view_run_javascript to call "Promise.resolve()" to execute the callback. 

So far they have implemented functions that themselves return promises, however I need to implement APIs to directly return function results and variables, e.g. browser.runtime.getManifest() that returns the WebExtension's manifest.json file. I've tried to modify Midori's JS function to use async/await to return the value once the promise resolves, but have had no success so far. 

Has anyone else tried anything like this? Or is there any way to have synchronous communication between the JS context and my app?

Regards,

Ryan


More information about the webkit-wpe mailing list