Hello,
This is a cross post with WebKit’s mailing list where I haven’t gotten any help (yet), hoping someone here might point me in the right direction. Original message is here (but I’m going to copy/paste and add some more info below): [webkit-help] [WebKitGTK] Issue with web process extensions
I’m on Ubuntu Linux 24.04 Noble Numbat, with the following packages installed:
- libwebkitgtk-6.0-4 2.46.1-0ubuntu0.24.04.1 amd64
- libwebkitgtk-6.0-dev 2.46.1-0ubuntu0.24.04.1 amd64
I’m trying to enable web process extensions in a mostly C++ written application. I’ve spent some hours going through the documentation and searching over the internet for a solution, but I don’t find any issue with my code (although, I may be overlooking a small detail).
The main symptom of my issue is that WebKit looks like it never loads my plugin (the extension’s g_print
line’s output never appears on standard output of terminal).
Below, there’s a minimal reproducing sample. Is anything wrong with my code? If not, how should I proceed to figure out where the issue is?
Based on the code below, here’s a few things I’ve tried already:
- moving the
libextension.so
file to another path than ./ or specifying an absolute path towebkit_web_context_set_web_process_extensions_directory
. - writing a tool using GModule functions that loads
libextension.so
and checkswebkit_web_process_extension_initialize
symbol can be reached withg_module_symbol()
. - running inside gdb and placing a breakpoint on
WebKit::WebProcessExtensionManager::initialize
fromSource/WebKit/WebProcess/InjectedBundle/API/glib/WebProcessExtensionManager.cpp
. That breakpoint is never triggered. - building WebKitGTK from source following instructions in
Readme.md
file. Even with 30G memory, compiler runs out of memory when trying to compile “unified source” files.
CMakeLists.txt:
cmake_minimum_required(VERSION 3.28.3)
project(
IssueSample
VERSION 1.0.0
LANGUAGES C CXX)
find_package(PkgConfig REQUIRED)
pkg_check_modules(WebkitGTK REQUIRED IMPORTED_TARGET glib-2.0>=2.74 gtk4>=4.14.2 webkitgtk-6.0)
add_executable(browser main.cpp)
target_link_libraries(browser PkgConfig::WebkitGTK)
add_library(extension MODULE extension.c)
target_link_libraries(extension PkgConfig::WebkitGTK)
extension.c:
#include <gtk/gtk.h>
#include <webkit/webkit-web-process-extension.h>
#ifdef __cplusplus
#error Must be compiled as C
#endif
static void web_page_created_cb(WebKitWebProcessExtension *extension, WebKitWebPage *web_page, gpointer /* unused */)
{
g_print("Page %ld created for %s with table\n", webkit_web_page_get_id(web_page),
webkit_web_page_get_uri(web_page));
}
G_MODULE_EXPORT void webkit_web_process_extension_initialize(WebKitWebProcessExtension *extension)
{
g_print("Inside webkit_web_extension_initialize %p\n", extension);
g_signal_connect(extension, "page-created", G_CALLBACK(web_page_created_cb), NULL);
}
main.cpp:
#include <gtk/gtk.h>
#include <webkit/webkit.h>
void initialize_web_extensions(WebKitWebContext *context, gpointer /*unused*/)
{
webkit_web_context_set_web_process_extensions_directory(context, "./");
}
int main()
{
gtk_init();
g_signal_connect(webkit_web_context_get_default(), "initialize-web-process-extensions",
G_CALLBACK(initialize_web_extensions), NULL);
GtkWindow * window = GTK_WINDOW(gtk_window_new());
WebKitWebView * web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
webkit_web_view_load_uri(web_view, "https://linux.org/");
gtk_window_set_child(window, GTK_WIDGET(web_view));
gtk_window_present(window);
while (g_list_model_get_n_items(gtk_window_get_toplevels()) > 0)
{
g_main_context_iteration(NULL, TRUE);
}
}