[webkit-gtk] Modifying HTML before loading it in a WebView

Michael Gratton mike at vee.net
Mon Aug 1 19:58:59 PDT 2016

Hey all,

I'm (slowly) working on porting Geary to WebKit2.

One of the things that needs to be taken care of is how Geary does 
manipulates an HTML email's markup before loading it into a WebView. 
This is done for a few reasons: Applying app-specific and user-specific 
CSS, to implement collapsible quote sections, for handling loading of 
inline and attached images, and to ensure that bulk and junk messages 
containing bugged remote images, etc. aren't automatically triggered.

I can parse, manipulate and re-serialise the HTML in the in the app 
before shipping it off to WebKit, but it would be nice to be able take 
advantage of WK's excellent parser instead. Is loading the HTML in a 
WebView and manipulating it from there using a WebExtension the only 
way to achieve this? I couldn't see anything like the DOM Load/Save 
APIs being documented as implemented. Is it possible to get a 
"background" WebKitWebPage for doing this without having the web view 
visibly change as the DOM is modified, then hand-ball the modified DOM 
over to a visible page for display?

For intercepting resource loads, connecting to 
WebKitWebPage::send-request and/or registering a handler with 
webkit_web_context_register_uri_scheme() looks like the way to go - I 
assume that one or the other will allow intercepting and cancelling 
loads of all remote resources at load-time, including images, CSS and 
JS, but how secure are they? Will a DNS lookup be performed for 
resources with remote URIs before asking for load permission?


⊨ Michael Gratton, Percept Wrangler.
⚙ <http://mjog.vee.net/>

More information about the webkit-gtk mailing list