Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 521255 - Eclipse SWT Browserfunction can not be called from Javascript on Linux system
Summary: Eclipse SWT Browserfunction can not be called from Javascript on Linux system
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-08-22 09:55 EDT by Markus Krug CLA
Modified: 2017-12-06 04:06 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Krug CLA 2017-08-22 09:55:47 EDT
I dont know if the invocation of Browserfunctions is not supported yet for GTK+ 3.*

However what i tried to accomplish is to use the SWT Browser widget to have a bidirectional communication between java and javascript.

On Windows 7 i can simply create a browserfunction and call it from JScript.

On Ubuntu 16.04, using GTK+3.0.18, the same code can not invoke any functions, that are registered as a Browserfunction.

If somebody could provide me with a working example (and possibly the steps that i need to setup my Ubuntu for it) this would be great. I also would not mind using any SWT version, but so far it did not work with 4.4 and 3.105 (which is bundled in my current eclipse)

Thanks
Markus
Comment 1 Leo Ufimtsev CLA 2017-08-22 10:23:37 EDT
(In reply to Markus Krug from comment #0)
> I dont know if the invocation of Browserfunctions is not supported yet for
> GTK+ 3.*
> 
> However what i tried to accomplish is to use the SWT Browser widget to have
> a bidirectional communication between java and javascript.
> 
> On Windows 7 i can simply create a browserfunction and call it from JScript.
> 
> On Ubuntu 16.04, using GTK+3.0.18, the same code can not invoke any
> functions, that are registered as a Browserfunction.
> 
> If somebody could provide me with a working example (and possibly the steps
> that i need to setup my Ubuntu for it) this would be great. I also would not
> mind using any SWT version, but so far it did not work with 4.4 and 3.105
> (which is bundled in my current eclipse)
> 
> Thanks
> Markus

Hello Markus, 

It's supported on Gtk2/3.

I'm currently working on improving this business as well.

As things stand, Gtk has Webkit1 and Webkit2 as a backend.

BrowserFunction works fully in Webkit1. We are in the process of porting to Webkit2 thou. (sort of like Gtk2->Gtk3 port).

It currently works mostly in Webkit2 but java can't provide a return value back to javascript when BrowserFunction is called, but I'm working on finishing that.  (see related).

This snippet demonstrates how to use BrowserFunction:
http://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet307.java

It should work on Webkit1. Half of it works on Webkit2.

To run webkit2:
export SWT_WEBKI2=1
./eclipse  

You should ideally use newest builds as it has most webkit2 related fixes:
http://download.eclipse.org/eclipse/downloads/

I think you're referring to Gtk3 3.18 not Gtk3.0.18. But to get exact version, you can run a snippet with the following environmental variable:

SWT_LIB_VERSIONS=1

It will then print gtk and webkit version.
Comment 2 Leo Ufimtsev CLA 2017-08-22 10:24:06 EDT
Was the above snippet helpful?

If not, what happens when you run the snippet?
Comment 3 Leo Ufimtsev CLA 2017-08-22 10:25:06 EDT
Btw, ubuntu is linux not unix. Did you mean linux?
Comment 4 Markus Krug CLA 2017-08-22 11:08:55 EDT
Hi Leo,
thanks for the quick answer :).

I tried the snippet on windows and it works perfectly fine (as expected).

Going to my 16.04 Ubuntu yielded : "Can`t find variable: theJavaFunction"

setting the Variable did not change anything


Setting the Environmental Variable did not print anything as well (i assume because i am using SWT 3.105 and i think it was added with 4.7, but the GTK is at version 3.18.9)

Is there a maven repository with the current version of SWT?




Also: Yeah i tried currenlty only have an Ubuntu 16.04 with a UI available for testing
Comment 5 Markus Krug CLA 2017-08-22 11:38:49 EDT
Okay i found a maven repository for the newer versions, i am now using SWT version 4.7M3.

I still cant get the versions printed. The error which is thrown now is "Cant find variable: external"
Comment 6 Leo Ufimtsev CLA 2017-08-22 11:42:53 EDT
Maven builds are kinda old I think. Try the newest integration build:
http://download.eclipse.org/eclipse/downloads/

Like click on something like:
I20170821-2000 

There somewhere you can find the swt.jar. 
I've only added SWT_LIB_VERSIONS=1  like a month ago, so it won't work on older SWT builds.

SWT 3.1 is very old. Can you try with the SWT from the integration builds above and see if you're more sucessfull? 

Btw, is webkit / webkitgtk libs installed on your system?
Comment 7 Markus Krug CLA 2017-08-23 02:07:51 EDT
Okay thank you,
i did what you said and got my Versions:

GTK 3.18.9 and WebkitGTK:2.16.0.

Im also no longer getting an exception, and also receive the call in my java function (but as you said no return value).

Is there an easy way, starting form here that would make the snippet work entirely?
Comment 8 Leo Ufimtsev CLA 2017-08-24 10:47:44 EDT
(In reply to Markus Krug from comment #7)
> Okay thank you,
> i did what you said and got my Versions:
> 
> GTK 3.18.9 and WebkitGTK:2.16.0.
> 
> Im also no longer getting an exception, and also receive the call in my java
> function (but as you said no return value).
> 
> Is there an easy way, starting form here that would make the snippet work
> entirely?

For webkit1 it should work out of the box. (i.e, export SWT_WEBKIT2=0), for webkit2, I'm currently working on implementing the return value support. (see related bug).

Does it work on webkit1 for you, or only on webkit2?
Comment 9 Markus Krug CLA 2017-08-24 11:03:51 EDT
Hi there is no difference for me, if i set the env. variable or not
Comment 10 Alexander Kurtakov CLA 2017-08-24 11:33:38 EDT
(In reply to Markus Krug from comment #9)
> Hi there is no difference for me, if i set the env. variable or not

A possibility is that you have only one webkit version installed on your system thus it automatically falls back to it no matter what you set via the env. variable. Can you post the webkitgtk packages versions on your system?
Comment 11 Alexander Kurtakov CLA 2017-12-06 04:06:59 EST
Webkit2 browser functions are in master now and you haven't responded in months. I'm marking the bug as resolved but please reopen if you still face the issue with latest builds.