[wpe-webkit] Use WebKit-WPE Web Extensions to append custom <scipt> element to HTML DOM
Adrian Perez de Castro
aperez at igalia.com
Tue Jul 27 07:40:38 PDT 2021
Hi Michael,
On Tue, 27 Jul 2021 10:36:46 +0300 Michael Pantazoglou <michael.pantazoglou at oceanbluesoftware.co.uk> wrote:
> I have recently started working with the WebKit-WPE Web Extensions API to
> develop some additional functionality for the WPE browser. In particular, I
> need to 'inject' a custom <script> element to the HTML DOM *before* the
> latter is loaded/processed by the WebPage/WebFrame.
>
> As far as I have seen, the WebKit-WPE Extensions API allows for executing
> custom JavaScript as well as exposing native code to JS via the JSC API, in
> response to the window-object-cleared signal. However, those techniques do
> not serve my needs, because my custom <script> element executes JS code
> that needs the DOM document and document.documentElement to exist and be
> fully populated in advance.
The window-cleared-signal is intentionally triggered early during the
initialization of the JS context (hence the “cleared” in its name: it
will have a very minimal set of contents), before loaded content has had
any chance to touch it.
> So, I was wondering if the WebKit-WPE Extensions API provides any other
> signal that I could connect to and respond by altering the HTML DOM tree
> -or the raw network reply- before it is passed to the
> WebPage/WebFrame/HTMLDocumentParser. Has anybody else tried anything
> similar in the past? What is the best way to move forward besides patching
> WebKit itself?
The public API does not provide a way of replacing the raw network replies.
You can probably achieve your goal by using an injected script, see:
https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#webkit-user-content-manager-add-script
https://webkitgtk.org/reference/webkit2gtk/stable/webkit2gtk-4.0-WebKitUserContent.html#webkit-user-script-new
I hope this helps :)
Cheers,
-Adrian
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <http://lists.webkit.org/pipermail/webkit-wpe/attachments/20210727/a2000762/attachment.bin>
More information about the webkit-wpe
mailing list