My favorites | Sign in
Logo
             
New issue | Search
for
| Advanced search | Search tips
Issue 580: Java Applet to JavaScript communication (liveconnect) is not working.
63 people starred this issue and may be notified of changes. Back to list
 
Reported by gutmant, Sep 03, 2008
Product Version      : 0.2.149.27 (1583)
URLs (if applicable) : -
Other browsers tested:
Add OK or FAIL after other browsers where you have tested this issue:
     Safari 3: DK
    Firefox 3: OK
         IE 7: OK

What steps will reproduce the problem?
1. Embed simple java applet with a string setter function in an html page.
2. Write a JS script that tries to set that filed.
3. Run it.

What is the expected result?
Success in setting the String inside the java code.

What happens instead?
Error in JS, claiming the applet does not have the given setter method.

------------
I'm adding a small example of a java file and html file. Works in FF3 and 
IE6, not in 
Google Chrome.
(Compile with any version you'd like, I tried with java 1.5)

The files should be in the same folder (the .class and .html).
TestApplet.java
232 bytes   Download
testHtml.html
538 bytes   Download
Comment 1 by br...@hulseware.com, Sep 03, 2008
I also experienced a problem with a page that contains an applet and has javascript 
routines that are supposed to interact with the applet. From what I could tell when I 
tested it, the interaction between the applet and the javascript functions are not 
executing. The applet is responding as it should to input, but the page does not 
update with the data the applet should be supplying to it.
Comment 2 by gutmant, Sep 04, 2008
Br, In my example the applet is *not* responding to the input, because the functions 
are not executing. Please look at the example I added and tell me you you get a 
different result...

Comment 3 by geofftitmuss, Sep 05, 2008
Also seen this with my Java applet at www.j2e.com/new

window.onbeforeunload does work with Chrome in simple javascript.
However in my case it does not. My application is a java application.
In order to stop window closure when the user has edited in the
application area, I have to get javascript to communicate with java. I
do this using the DOM, which works fine in Firefox, IE and Safari. The
following example code fails in Chrome at the DOM call. The script
does not echo the following alert, so it appears that Chrome just
kills the script?

<script language="JavaScript1.2" type="text/javascript">
<!--
  //register function with the event handler
  window.onbeforeunload = confirmUnload;

  function confirmUnload(){
       alert("?");  // test we came into this function - we did!

       // Call function in javaApplet to see if document has changed.
Function returns "yes" or "no".
       var c = document.javaApplet.changed();

       alert(c);  // This alert never happens with Chrome, window
just closes. Firefox and IE give this alert with correct value.

       if (c=="yes")
               return 'You have made changes, and they will be lost!';
  }
//-->
</script>


Comment 4 by ceisserer, Sep 09, 2008
This problem causes our application not to work properly.
This means we can't recommend nore support Chrome as browser, please fix it.
Comment 5 by simon.baird, Sep 09, 2008
TiddlyWiki users would like to see this one fixed also. It prevents TiddlyWiki from
being able to save.
Comment 6 by keithhmk, Sep 09, 2008
My application with applet liveconnect is not working too. My javascript unable to 
call the method in applet. Please fix it.
Comment 7 by todd.cha...@gmail.com, Sep 10, 2008
Just a "me too" (as a Tiddlywiki user) to increase the visibility of this bug.
Comment 8 by dshehane, Sep 10, 2008
Another me too!  This is stopping the adoption of Chrome as default since quite a few
web apps fail!
Comment 9 by darin@chromium.org, Sep 10, 2008
Chrome currently requires the latest Java 6 beta from 
Sun:http://java.sun.com/javase/downloads/ea/6u10/6u10RC.jsp
Comment 10 by feng@chromium.org, Sep 10, 2008
Have you tried Java 6 beta release?
http://java.sun.com/javase/downloads/ea/6u10/6u10RC.jsp

Comment 11 by ian.m.griffiths, Sep 10, 2008
We are using Java 6 beta (update 10) foe our tests. It is with this version that the
calls failed.

Comment 12 by feng@chromium.org, Sep 10, 2008
I will take a look into it.
Status: Assigned
Owner: f...@chromium.org
Comment 13 by ian.m.griffiths, Sep 10, 2008
Thanks,
If you need any extra information, don't hesitate to ask.
Ian
Comment 14 by feng@chromium.org, Sep 10, 2008
It turns out a silly mistake, the binding code didn't think Applet element is a 
plugin element. I made one-line change in the code and the simple test case you 
provided works fine now.

Before I claim this bug is fixed, do you have some more complicated Java Applets on 
the web that I can test out?
Comment 15 by kittrellbest, Sep 10, 2008
Feng - have you tried the fix with a TiddlyWiki save yet?
Thanks,
Chuck
empty.html
283 KB   Download
Comment 16 by feng@chromium.org, Sep 10, 2008
kittrellbest: can you provide steps to reproduce the problem you had with TiddlyWiki?

geofftitmuss: can you also provide steps to reproduce the problem? I didn't see the 
dialog when I close the window in Safari.
Comment 17 by geofftitmuss, Sep 10, 2008
Ok, to test my case.

Load www.j2e.com/new&beta
Then click on the blank page, and type some text into it eg "j2e in Chrome is really 
cool" ;-)
Then try to close the window.
A dialogue should appear asking if you are sure, you will lose changes...
Comment 18 by feng.qian, Sep 10, 2008
geofftitmusee: First you need to fix the your website:

document.j2e does not work in Safari and Chrome, you need to change it to window.j2e, 
or document.getElementById('j2e');
Comment 19 by feng.qian, Sep 10, 2008
geofftitmuss: other that, I can see window.j2e.changed() returns 'yes' or 'no' 
properly with my fix.
Comment 20 by radvani, Sep 10, 2008
You can test on a more complex applet that makes extensive use of LiveConnect at
www.upnext.com. Thanks.
Comment 21 by radvani, Sep 10, 2008
I should add, you'll know it's working if the applet resizes to fit the available
width of the screen whenever you change the browser window size.
Comment 22 by feng@chromium.org, Sep 10, 2008
geofftitmuss: actually this is a webkit "bug" or not. document.j2e should work, but 
in your code, <object ...> is not closed by </object>. It works in FF, but not work 
in Webkit (Safari). I am going to file a bug to WebKit.

Thanks for reporting.
Comment 23 by feng@chromium.org, Sep 10, 2008
Filed webkit bug about <object> https://bugs.webkit.org/show_bug.cgi?id=20775

radvani, the resize does not work yet. there are other issues. I will take another look.

JS code on http://upnext.com is obfuscated. Do you have snippets of JS code that talk to applets?
Comment 24 by gutmant, Sep 10, 2008
The <object> requiring </object> is not a bug - it's following the standard. The only 
reason FireFox allows it is that Explorer does (along with many other things that 
should not be allowed) and web-programmers got used to that. 
Valid HTML always has a </object>, or if you're looking at something like <img 
src...> then it should end like this: <img src="..." ... />.
Comment 25 by geofftitmuss, Sep 11, 2008
-> actually this is a webkit "bug" or not. document.j2e should work, but 
-> in your code, <object ...> is not closed by </object>.

In my code the <object> is closed by </object>.

Look carefully, the <object> line is done by a document.writeln in javascript.
the </object> is in the original html. This is done for a reason, my server generates 
the html with some parameters in it. The javascript is static and reused.

Safari on Mac OS is quite happy with with.
Comment 26 by geofftitmuss, Sep 11, 2008
-> document.j2e does not work in Safari and Chrome, you need to change it to 
window.j2e, 
-> or document.getElementById('j2e');

I have changed my code from document.j2e to document.getElementById('j2e').
My applet now works on Chrome.

document.j2e should have worked and must be a Chrome and Safari(Windows) bug.

thanks for your help.
Comment 27 by jeremy.ruston, Sep 11, 2008
I've tested TiddlyWiki with the latest nightly, and the JavaScript bridge is still not working correctly.

The code in question is:

if(document.applets["TiddlySaver"]) {
var s= String(document.applets["TiddlySaver"].loadFile(javaUrlToFilename(filePath),"UTF-8"));
return s;
}

When I alert document.applets["TiddlySaver"], it comes out as an HTMLAppletElement, and the Java console indicates that the applet is being 
loaded and initialised. When I try the code above to invoke a method exposed by the applet, the error I get is:

Uncaught TypeError: Object #<an HTMLAppletElement> has no method 'loadFile'

Comment 28 by feng@chromium.org, Sep 11, 2008
geofftitmuss:
document.j2e bug is filed to webkit: https://bugs.webkit.org/show_bug.cgi?id=20775

radvani:
http://www.upnext.com seems working on my local build, the map resizes when the 
window resizes.

jeremy.ruston:
The code seems fine to me, and it shouldn't throw the exception. Do you have easy 
reproducible steps?
Comment 29 by boraertun, Sep 11, 2008
Where do we download the latest build to test?

thanks
Comment 30 by feng@chromium.org, Sep 12, 2008
Yes, you can. Here is a recent build that has the fix:
http://build.chromium.org/buildbot/snapshots/chromium-rel-xp/2115/

You can download chrome-win32.zip and extract it. Start Chrome with a parameter like
chrome.exe --user-data-dir=c:\foo, so it won't mess up with your default profile.

And you can always find the latest build at
http://build.chromium.org/buildbot/waterfall/
looking for 'archived build' and click on the [download] below it.



Comment 31 by boraertun, Sep 12, 2008
Thanks for the build info,

Here is what we get from our live connect based platform;

1. The JRE loaded with Java Kernel upon plug-in component request from the chrome does not work and throws a 
cryptic exception from inside java plugin2 code.
2. The offline installation from http://java.sun.com/javase/downloads/ea/6u10/6u10rcDownload.jsp#6u10JREs of 
JRE runs liveconnect fine with the snapshot build; however, it can not instantiate live connect for the 
second applet. This means that it does not allow two applets to make a live connection on the same page or 
from different iframes from the same domain.
3. Our platform is quite complex and works fine with Safari for windows. I can provide a private demo to you 
to test the liveconnect with it. Just drop a message here I will email demo information to you.

thanks
Bora
Comment 32 by boraertun, Sep 12, 2008
By the way, the second execution of the scenario I have listed on item 2 has failed 
with the result of item 1. Here is the cryptic exception I have mentioned.

java.lang.Exception: comp is null
	at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown 
Source)
	at java.lang.Thread.run(Unknown Source)



Comment 33 by c...@norm-4.com, Sep 12, 2008

recent build works fine with javagotchis (reloading the given nr in the url)!

http://www.javagotchi.com/?1000

thank you and looking forward to the next release...

greetinx from germany

Comment 34 by c...@norm-4.com, Sep 12, 2008
sorry i was by accident in the wrong browser :|
same bug with javagotchis: :(

java.lang.Exception: comp is null
	at sun.plugin2.applet.Plugin2Manager.runOnEDT(Unknown Source)
	at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Comment 35 by boraertun, Sep 13, 2008
Further investigation reveals that there is in fact an initialization problem with 
the applets in chrome. When the said exception is received, pressing on the refresh 
button of the chrome loads the applet successfully. Therefore, the second issue I 
have listed in comment 31 was probably related to this failed initialization attempt 
of the second applet. How is this handled in webKit? is it really totally different?
Comment 36 by jeremy.ruston, Sep 13, 2008
Thanks very much feng, the applet seems to work perfectly in TiddlyWiki now. Your quick response is much 
appreciated by everyone in the TiddlyWiki community.
Comment 37 by dshehane, Sep 14, 2008
The following still will not load:
http://maps.rmlsweb.com/GeoJetElp/sjgeojet.asp?mapName=42&X=-48936082&Y=47782158&address=28282+SW+MOUNTAIN+RD,+97068
Is this the same problem?
Thanks
Comment 38 by feng@chromium.org, Sep 17, 2008
sorry, guys, I was a bit busy on other stuff in last a few days.

@boraertun, a private demo will certainly help, please email to feng @ chromium org

To comment 34, do you have a url I can try out?



Comment 39 by feng.qian, Sep 17, 2008
@dshehane,

I got the same error dialog box in Safari:

GeoJet not loaded successfully.
Check security settings to enable Java Applet and Javascript.
Comment 40 by c...@norm-4.com, Sep 17, 2008
>comment 34
http://www.javagotchi.com/?10020

seem to work good now,
just enter a number between 0 and 999999 after the questionmark, this parameter will
be transferred onload to the applet

thanx!
Comment 41 by sebdotv, Sep 18, 2008
Should be fixed in 0.2.149.30 according to changelog.
http://google-chrome-changelogs.blogspot.com/

Comment 42 by bob.jmol, Sep 19, 2008
the Jmol community (jmol.sourceforge.net) is VERY happy to see this working, for
example, at http://chemapps.stolaf.edu/jmol/docs/examples-11/new.htm

excellent!
Comment 43 by qu0ll64, Sep 21, 2008
We still cannot get Java to JavaScript execution to work properly in the latest 
Chromium build.  Whenever a script that is invoked from within a Java applet 
encounters a call to a Java method it produces an evaluation error and the script 
fails to execute.

Can this be fixed also?
Comment 44 by qu0ll64, Sep 23, 2008
Anyone out there?  This is serious!
Comment 45 by feng@chromium.org, Sep 25, 2008
Hi everyone, sorry for the delay. I am overwhelmed by other stuff.

Amit is our plugin person, and I forwarded all your private messages to him and re-
assign the bug to him.

I will help fix Java plugin bugs when I have free time.

Thanks for reporting, we are not ignoring you.
Owner: a...@chromium.org
Cc: f...@chromium.org
Comment 46 by mal.chromium, Sep 29, 2008
(No comment was entered for this change.)
Labels: -area-unknown Area-Misc
Comment 47 by nicolas.alvarez, Oct 03, 2008
document.applets[] is non-standard.
Comment 48 by amit@chromium.org, Oct 09, 2008
document.applets[] is supported in Google Chrome and should work. If someone can 
provide test cases for these issues then it will be very helpful in resolving them.

Thanks!



Comment 49 by qu0ll64, Oct 10, 2008
I provided a test case to Feng, but here it is again...
JSApplet.java
346 bytes   Download
jsapplet.html
223 bytes   Download
Comment 50 by amit@chromium.org, Oct 21, 2008
Thanks for the test case. It can be further reduced to:

<html><head><script language="javascript">
function runTest() {
  var g = document.scripter.getGraphics();
  g.setColor(new java.awt.Color(200, 200, 200));
}
</script>
</head>
<body onload="runTest()">
<applet id="app" code="java.applet.Applet" name="scripter"
        width="100" height="100">
</applet>
</body>
</html>

This fails because Chrome doesn't support global Java packages. So it is not possible 
to call 'new java.awt.Color(...)' in Chrome. 

However, I am looking into the newer way to support this using the following syntax: 
'new document.scripter.Packages.java.awt.Color(...)'

New Java plugin enables this syntax and more information about it can be found here: https://jdk6.dev.java.net/plugin2/liveconnect/#PER_APPLET_PACKAGES

Will revisit this later once we have 'Packages' keyword working.


Comment 51 by laforge@chromium.org, Oct 29, 2008
Looking at this thread, I'm going to take this out of Area:Misc and put it in 
Area:WebKit
Labels: -Area-Misc Area-WebKit
Comment 52 by thebeanieman, Feb 28, 2009
Is this related to the Bug I posted?

http://code.google.com/p/chromium/issues/detail?id=6170

Thanks,
Beanie
Comment 53 by des.public, Mar 02, 2009
Ardent user of tiddlywiki and this is currently preventing me from using it in 
Chrome.  Love the 'application' aspect and waned to set up a standalone tiddlywiki 
todo. 
Comment 54 by amit@chromium.org, Mar 02, 2009
From the script it does not look like it using 'java.awt.xxx..." pattern so it is not 
related. Also, it happens on Safari too so it could be a webkit issue.
Comment 55 by jon@chromium.org, May 15, 2009
(No comment was entered for this change.)
Labels: Area-Plugins JavaScript Mstone-2.1 Size-Large
Comment 56 by jon@chromium.org, May 15, 2009
(No comment was entered for this change.)
Status: Available
Owner: ---
Cc: a...@chromium.org mbel...@chromium.org
Comment 59 by laforge@chromium.org, May 22, 2009
(No comment was entered for this change.)
Labels: -mstone-2.1 mstone-3
Comment 60 by darin@chromium.org, May 23, 2009
(No comment was entered for this change.)
Summary: Java Applet to JavaScript communication (liveconnect) is not working.
Comment 61 by jon@chromium.org, May 29, 2009
(No comment was entered for this change.)
Status: Assigned
Owner: a...@chromium.org
Comment 62 by jimbo2150, Jun 01, 2009
I am not sure if this is related to this but or not, but using the <applet> tag works 
fine with LiveConnect, but using the <object> tag does not seem to work with 
LiveConnect.

eg.
<object name="testObj" type="..." ...>[params]</object>
<script language="Javascript">
javaObj = document.testObj;
alert(javaObj.someTestMethod());
</script>

This code works if <applet> is used instead of <object>. Both work in other browsers 
like Firefox.

Expected result:
An alert box featuring some text returned by the Java applet through LiveConnect.

Actual Result:
Nothing. No code beyond "javaObj.someTestMethod()" runs. Additionally, the developer 
javascript debugger fails to load on the page.

Version: 2.0.172.28

Comment 63 by amit@chromium.org, Jun 01, 2009
jimbo2150: have you tried using getElementById()? It may not be an issue with Java 
bindings at all.
Comment 64 by jimbo2150, Jun 01, 2009
Yes, I have tried getElementById(). Oddly enough, in Chrome and Firefox it returns an
HTML object, but not the java object. Attempting to call some Java method gives a
"that method does not exist" error.
Comment 65 by amit@chromium.org, Jun 01, 2009
Right, so this is not related to Java live connect. :)
Comment 66 by jon@chromium.org, Jun 05, 2009
(No comment was entered for this change.)
Status: Available
Owner: ---
Labels: -mstone-3 Mstone-X
Comment 68 by gke...@gmail.com, Oct 17, 2009
None of the example on https://jdk6.dev.java.net/plugin2/liveconnect/ work for me.
Comment 69 by jam@chromium.org, Oct 20, 2009
We don't ever intend to support LiveConnect in Chrome.  The newest version of the Java 
plugin from Sun removes the need for this, since it uses NPRuntime to allow scripting.
Status: Invalid
Comment 70 by gke...@gmail.com, Oct 20, 2009
I am happy with not suppporting LiveConnect but should the examples provided for the 
new plugin for Sun jvm 1.6 for javascript and Java communication work?  The link in 
comment # 68 is talking about the new plugin and "LiveConnect".  None of these 
examples work in chrome...any plans to support that?
Comment 71 by gke...@gmail.com, Oct 20, 2009
Also found this bug which shows that none of the java plugin2 LiveConnect tests 
passing:

http://code.google.com/p/chromium/issues/detail?id=3285#c39
Comment 72 by mal.chromium, Dec 18, 2009
(No comment was entered for this change.)
Labels: -Area-Plugins Area-Internals Internals-Plugins
Comment 73 by SpinnerdogDave, Dec 30, 2009
I've found LiveConnect works as long as the <applet> are a part of the static html 
document.  But if I try something like this LiveConnect stops working.

appletinsert = '<applet>...</applet>'
document.getElementByID( 'targetdiv' ).innerHTML = appletinsert;

LiveConnect calls to the javascript work but not from the javascript back to the 
applet.

Can anyone suggest any alternatives that might allow me to dynamically insert the 
applet tag into an html element?  

Thanks. 
Comment 74 by vladtarko, Feb 21, 2010
jeremy.ruston is incorrect in saying the problem with tiddly wiki is solved. it is 
not :|

the stepts to reproduce the problem: 
1. save the two attached files somewhere (they're the latest version of tiddly wiki)
2. open 'empty.html' (an blank tiddly wiki file) with Chrome
3. edit something (click 'edit' in the upper-right side, change something, and click 
'done')
4. click 'save changes' in the right panel (a confirmation message will appear that 
the file was saved)
5. close the file
6. reopen the file - the change made at step 3 is no more...
empty.html
344 KB   Download
TiddlySaver.jar
4.9 KB   Download
Sign in to add a comment

Powered by Google Project Hosting