Sample Web Extension for Webkit [ GTK & WPE ] based on JSC GLib API
webkit_port : wpe or gtk
extension_path : Relative path to webkit libdir, where the extension will be installed
meson -Dwebkit_port='gtk' -Dextension_path=webkit/web-extensions builddir
ninja -C builddir/
sudo ninja -C builddir install
NOTE: In case if webkit is installed to a custom location configure with PKG_CONFIG_PATH=
Example
PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig/ meson -Dwebkit_port='gtk' -Dextension_path=webkit/web-extensions builddir
In the browser make sure you connect to web-extension signal, and in signal handler make sure to set extenstion directory and call extension initialize.
You can use html/sample_web_extension.html as reference
#define WEB_EXTENSIONS_DIRECTORY "/usr/local/lib64/webkit/web-extensions/"
static void initialize_web_extensions (WebKitWebContext *context, gpointer user_data)
{
// Web Extensions get a different ID for each Web Process
static guint32 unique_id = 0;
webkit_web_context_set_web_extensions_directory ( context, WEB_EXTENSIONS_DIRECTORY);
webkit_web_context_set_web_extensions_initialization_user_data (context, g_variant_new_uint32 (unique_id++));
}
g_signal_connect (webContext, "initialize-web-extensions", G_CALLBACK (initialize_web_extensions), NULL);