<div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Mon, Jun 27, 2016 at 5:17 AM Adrián Pérez de Castro <<a href="mailto:aperez@igalia.com">aperez@igalia.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi there,<br>
<br>
Quoting Carlos Garcia Campos (2016-06-27 08:21:13)<br>
> El dom, 26-06-2016 a las 18:53 +0200, Jay Strict escribió:<br>
> > On 26.06.2016 08:20, Carlos Garcia Campos wrote:<br>
> > > So, the answer is yes, you need a web extension, and the API you<br>
> > > want<br>
> > > is the signal WebKitWebPage::send-request. That signal is emitted<br>
> > > right<br>
> > > after the request is created and before it's sent to the network<br>
> > > process, so that you can modify the request or even block it. The<br>
> > > problem is how to create a web extension when using the js<br>
> > > bindings,<br>
> > > because a web extension is a .so loaded by the web process at<br>
> > > startup.<br>
> > > So at this moment I'm afraid it's not possible to do that with js,<br>
> > > but<br>
> > > I guess you could write the web extension in C, it will be just a<br>
> > > few<br>
> > > lines of code.<br>
> ><br>
> > That's a pity, because Gnome shell extensions seem to support only<br>
> > JS.<br>
> > You can upload the extensions on <a href="http://extensions.gnome.org" rel="noreferrer" target="_blank">extensions.gnome.org</a>, but what .so<br>
> > file<br>
> > should I upload? For every platform, there must be a different .so<br>
> > file.<br>
> > Furthermore, I suppose the Gnome people wouldn't accept a binary file<br>
> > uploaded there.<br>
> ><br>
> > Is there any other way?<br>
><br>
> I don't think so.<br>
><br>
> > ><br>
> > > > Fortunately, I think you can get the behavior you want using the<br>
> > > > UI<br>
> > > > process API, by connecting to the resource-load-started signal of<br>
> > > > WebKitWebView; that will give you a WebKitURIRequest that you can<br>
> > > > modify. I haven't tried this before; hope it works for you.<br>
> > ><br>
> > > No, that signal is emitted when the request has already been sent,<br>
> > > note<br>
> > > that the signal is named resource-load-started, it has already<br>
> > > started,<br>
> > > and the signal is only a notification.<br>
> ><br>
> ><br>
> > I don't know much about WebKitGTK, but do you think there is any<br>
> > chance<br>
> > that the authors (is that you?) would consider accepting a feature<br>
> > request for my use case?<br>
><br>
> Of course, we just need to fully understand the problem and decide how<br>
> to make it possible. The easiest solution might be to add support for<br>
> loading JS web extensions. Adri started to work on python web<br>
> extensions, I don't know if JS support would be very different. See:<br>
><br>
> <a href="https://lists.webkit.org/pipermail/webkit-gtk/2015-August/002416.html" rel="noreferrer" target="_blank">https://lists.webkit.org/pipermail/webkit-gtk/2015-August/002416.html</a><br>
><br>
> This would be the ideal solution in my opinion. But we could also add<br>
> API to the UI process to provide a set of headers to be added to any<br>
> request, for example, and use that from the web process. This would<br>
> probably be easier, but we can't add UI process API for every single<br>
> web extension feature required by JS apps, so adding a way to load JS<br>
> extensions would be much better.<br>
<br>
I do agree with Carlos here, and WebKitGTK+ should provide a way of loading<br>
JavaScript web extensions. As for Python, I have a working proof of concept<br>
C WebExtension which is a shim that itself loads the Python extension. You<br>
can check it here:<br>
<br>
<a href="https://github.com/aperezdc/webkit2gtk-python-webextension-example" rel="noreferrer" target="_blank">https://github.com/aperezdc/webkit2gtk-python-webextension-example</a><br>
<br>
(I am aware of a couple of people using the code in there as a basis for<br>
their Python applications which need a web extension, though in the longer<br>
term we will have something similar shipped with WebKitGTK+.)<br>
<br>
Having a similar proof-of-concept for JavaScript extensions would be great.<br>
Ideally, it would be great to use JavaScriptCore for that, because it is<br>
part of WebKitGTK+. As tempting as it might be to use GJS, it looks like<br>
sticking to JSC (via Seed, see <a href="https://wiki.gnome.org/Projects/Seed" rel="noreferrer" target="_blank">https://wiki.gnome.org/Projects/Seed</a>) would<br>
be better to have less dependencies in the case where one wants to use<br>
WebKitGTK+ *without* having GNOME Shell installed.<br></blockquote><div><br></div><div>I am fairly certain GJS is the more frequently used of the two, in GNOME applications at least. In any case, GJS is not just used for GNOME Shell, but also several applications like GNOME Documents (which itself uses WebKitGTK), GNOME Weather, etc.</div><div><br></div><div>And after all, I don't suppose it's a burden to include a dependency on Python for the Python shim. <span style="line-height:1.5">You might be able to write WebExtension shims for any number of interpreted languages and make them an optional part of the build. In package-based distributions, for example, they could be shipped in separate packages.</span></div><div><span style="line-height:1.5"><br></span></div><div><span style="line-height:1.5">Regards,</span></div><div><span style="line-height:1.5">Philip C</span></div></div></div>