[webkit-gtk] Webkit2 signals/callbacks

Adrian Perez de Castro aperez at igalia.com
Tue Feb 5 04:51:02 PST 2019


On Mon, 04 Feb 2019 09:01:27 -0600, Michael Catanzaro <mcatanzaro at igalia.com> wrote:
> On Mon, Feb 4, 2019 at 2:46 AM, Daniel Berek <berekdaniel at gmail.com> 
> wrote:
> > Hi, is there any signal or callback for handling an "onClick" event 
> > in c++ program (similar to mouse-target-changed)?
> > Html sites are loaded with webkit_web_view_load_html() and my goal is 
> > to process user input, when HTML divs are clicked.
> > (or connect the html onClick event through javascriptcore with my 
> > code)
> > Does anybody have any solution for my problem? Thnaks, Daniel
> 
> You're going to need to do this in JavaScript, possibly in the web 
> process using the web process extension API [1]. I don't have any 
> simple examples, but [2] will at least get you started at running code 
> in the web process, including the JavaScript under resources/js. Good 
> luck!

You can also use an injected JS script [1] which hooks into the “onclick”
events and send user script messages [2] to the process that is embedding
the Web view. Depending on your use case that might be good enough, while
being much simpler to implement. Of course, with Michael's suggestion (a
Web process extension) you have full control of the JS context, so in some
cases that may be a better approach :)

Cheers,


-Adrián


---
[1] https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#webkit-user-content-manager-add-script
[2] https://webkitgtk.org/reference/webkit2gtk/stable/WebKitUserContentManager.html#webkit-user-content-manager-register-script-message-handler
-------------- 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-gtk/attachments/20190205/9a1aee4a/attachment.bin>


More information about the webkit-gtk mailing list