-
Notifications
You must be signed in to change notification settings - Fork 49
GTKWebkitWebView change WebDataDir and WebCacheDir #1472
Description
Discussed in #1471
Originally posted by andreasld97 March 12, 2026
Hi,
I am just using a normal WebView trying to change the folders where it stores its content (because I will use multiple webviews in my project). The documentation (https://webkitgtk.org/reference/webkitgtk/stable/migrating-to-webkitgtk-6.0.html#network-session-api) here says the following:
"[...] WebKitNetworkSession to be used must be passed to the WebKitWebView as a construct parameter."
So thats what I am trying, but I dont know how to do this right. I managed to create a new NetworkSession with the pathes which is simple, but is it even possible to pass it using the ConstructArgument from the bindings?
Heres my code:
using GObject;
using WebKit;
internal class Program
{
private static void Main(string[] args)
{
WebKit.Module.Initialize();
var _app = Adw.Application.New("Test.App", Gio.ApplicationFlags.FlagsNone);
_app.OnActivate += (sender, args) =>
{
var _window = Gtk.ApplicationWindow.New(_app);
_window.Title = $"Test";
_window.SetDefaultSize(800, 600);
var webView = CreateWebView("/home/andy/test/data", "/home/andy/test/cache"); // new WebView();
webView.LoadUri("https://www.google.de");
_window.SetChild(webView);
_window.Show();
};
_app.OnShutdown += (sender, args) => { };
_app.Run([]);
WebView CreateWebView(string webDataDir, string webCacheDir)
{
try
{
// "[...] WebKitNetworkSession to be used must be passed to the WebKitWebView as a construct parameter." (https://webkitgtk.org/reference/webkitgtk/stable/migrating-to-webkitgtk-6.0.html#network-session-api)
var networkSession = NetworkSession.New(webDataDir, webCacheDir);
// Problem: The specified structure must be blittable or have layout information. (Parameter 'structure'):
return new WebView(new ConstructArgument("network-session", new Value(networkSession)));
}
catch (Exception ex)
{
return null;
}
}
}
}So here I get the exception that the specified structure must be blittable or have layout information. May I only pass primitive types here? But the property is a construct-only-property as you can see here: https://webkitgtk.org/reference/webkitgtk/stable/property.WebView.network-session.html. So it seems like there is the only way to pass it via constructor?