On Thu, Oct 12, 2017 at 5:23 AM Andrea Giammarchi <andrea giammarchi gmail com> wrote:FWIW I've used the location with a private channel as protocol to intercept calls to/from the page and GJS.The channel is a random string: https://github.com/WebReflection/jsgtk-twitter/ blob/master/app#L59 From the page, which is aware of the "secret" channel, I call GJS actions via location.href = "">encodeURIComponent(JSON.stringify(value))})`; The protocol secret1234 is intercepted and the `controller.method(JSON.parse(decodeURIComponent(restOfURI)) )` invoked. To signal the page everything is fine I use this.webView.runJavaScripthttps://github.com/ WebReflection/jsgtk-twitter/ blob/master/app#L377 The page has a listener for the `secret1234` event on the main window, and such listener is instrumented to react accordingly with the CustomEvent .detail payload/info.This might look a bit convoluted, and it has JSON serialization as limitation for the kind of data you want to pass (i.e. I use base64 encoded images as source from remotely fetched files enabling somehow CORS for whatever I want) but it worked well, circumventing the missing communication channel available in Qt.Maybe today there are better ways for doing a similar thing and if that's the case, please share.Here is another, fairly new, way to do it. Start out by registering a "script message handler":To send a message to the page, use the same thing that Andrea uses:To send a message from the page to the GJS program, use the postMessage() method mentioned in the documentation, and connect to this signal in your GJS program to receive the message:
Although I just realized that unfortunately the values won't be able to be marshalled into GJS since you need to use the _javascript_Core API to get at them. This is a really nice method in C, but in JS you can only use it to send a message without any content. That is annoying. I should probably open up an issue about this.
On Wed, Oct 11, 2017 at 12:57 PM, Adriano Patrizio <adriano patrizio hotmail com> wrote:Thank you for response, this is my problem: have necessity to implement methods into my web application webkit2 based and comunicate with GJS script (example: filesystem functions to read and write files or window managment).Regards,Philip C
_______________________________________________
_javascript_-list mailing list
_javascript_-list gnome org
https://mail.gnome.org/mailman/listinfo/_javascript_- list