Re: GJS: How to communicate with js inside webkit webview



http://www.roojs.com/seed/gir-1.2-gtk-3.0/seed/WebKit.WebView.html

This indicates that context is a void* in the gir, so it's unlikely any of the binding languages can access it.

I've done quite a but of work with seed and webkit, i would suggest forget about passing objects between webkit/gjs or even seed and expecting to interact via method calls etc. it is unlikely to work ever.

The normal work around is to use two way messaging between the two Scopes.

Execute_script, is a method of webview afair. That allows you to send data and call stuff in webkit scope

Then you can capture the console log, or alert messages and pass data and events back from webkit using json.

Be aware also that webkit seems to eat memory alive when used from introspection

Regards
Alan

Rich <rl6 shinyblue net> wrote:
Hi

I have a webkit webview, set up as in the hello tutorial[1]. I'd like to
be able to access JS inside the webview (or vice versa). e.g. I want my
GJS to allow the user to select a directory, and then to pass the
filenames into the web app.

From what I've read, I tried this

this._webView.connect('window-object-cleared', Lang.bind(this,
this.my_test));

And the docs[2] suggest that this signal should come with the window
object and the context for the JS environment inside the webview. So I
thought I could just add to this and thereby communicate with something
inside.

But my method my_test does not seem to be receiving all the parameters
it should.

e.g.

my_test:function(wv,f,c,w,u){ //web_view, frame, context,
window_object, user_data) {
c.test123 = 123;
},

gives me
JS ERROR: !!! Exception was: TypeError: c is undefined
JS ERROR: !!! lineNumber = '30'
JS ERROR: !!! fileName = '"hello.js"'
JS ERROR: !!! stack = '"([object
_private_WebKit_WebView],[object _private_WebKit_WebFr
ame],(void 0),(void 0))@hello.js:30
wrapper([object _private_WebKit_WebView],[object
_private_WebKit_WebFrame],(void 0),(void 0))@/
usr/share/gjs-1.0/lang.js:204
@hello.js:64

I'm a complete beginner to GJS and am finding it v difficult. I can't
find a way, either, to debug the thing. Even if I could write to stdout
that would help. Is Looking Glass just for extensions? Any tips most
welcome!

Thanks
Rich



[1]:
https://developer.gnome.org/gnome-devel-demos/unstable/hellognome.js.html.en
[2]:
http://webkitgtk.org/reference/webkitgtk/stable/webkitgtk-webkitwebview.html#WebKitWebView-window-object-cleared


_javascript_-list mailing list
_javascript_-list gnome org
https://mail.gnome.org/mailman/listinfo/_javascript_-list

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]