I use simple unix pipes for communication between the main thread and my webextension.
Please note that this is a work in progress!
You can take a look at both branches at my git repo: https://gitweb.softwarefools.com/?p=miguel/surf-webext-dom.git.
A little video demonstrating what was achieved so far (inside the glorious, webkit2gtk+ based, suckless surf browser):
The browser itself can be found here: https://surf.suckless.org/.