Launch webstart without downloading...? Launch webstart without downloading...? google-chrome google-chrome

Launch webstart without downloading...?


After getting fed up this problem, I wrote my own work around extension.

It's written under ubuntu, but should be portable (even to win32 with some work/reading).

Single click launches a jnlp file without prompting, or downloading. it just passes the url for the jnlp file to javaws directly. no cluttered Downloads folder, no extra clicks.

It's simple, crude and effective. I filtered the URL so it would only apply to my own internal server so I don't accidentally launch some random jnlp file. Lots more could be done to improve it, I'm sure. Use AS-IS, no warranty, etc, etc.

The files:

/usr/local/bin/jnlp-launcher

#!/usr/bin/env pythonimport structimport sysimport threadingimport Queueimport jsonimport os# On Windows, the default I/O mode is O_TEXT. Set this to O_BINARY# to avoid unwanted modifications of the input/output streams.if sys.platform == "win32":  import os, msvcrt  msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)  msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)# Helper function that sends a message to the webapp.def send_message(message):   # Write message size.  sys.stdout.write(struct.pack('I', len(message)))  # Write the message itself.  sys.stdout.write(message)  sys.stdout.flush()# Thread that reads messages from the webapp.def read_thread_func(queue):  message_number = 0  while 1:    # Read the message length (first 4 bytes).    text_length_bytes = sys.stdin.read(4)    if len(text_length_bytes) == 0:      if queue:        queue.put(None)      sys.exit(0)    # Unpack message length as 4 byte integer.    text_length = struct.unpack('i', text_length_bytes)[0]    # Read the text (JSON object) of the message.    text = sys.stdin.read(text_length).decode('utf-8')    decoded = json.loads(text);    os.system("javaws " + decoded['url']);def Main():  read_thread_func(None)  send_message('"complete"')  sys.exit(0)if __name__ == '__main__':  Main()

The chrome extension is 2 files placed in a local directory:

manifest.json

{  "manifest_version": 2,   "background": {      "persistent": false,      "scripts": [ "bg.js" ]   },  "name": "JNLP Fixer",  "description": "Handle JNLPs",  "version": "1.0",  "permissions": [    "downloads", "nativeMessaging"  ]}

And bg.js (edit as needed for host filters)

chrome.downloads.onCreated.addListener(function(downloadId) {    var expr = /\.jnlp$/;    //this is to limit where we apply the auto-launch.    //for our use, i only wanted it for internal jnlps.    var hostExpr = /(http|https):\/\/internal.company.com\//;    if (hostExpr.test(downloadId.url)) {        if (downloadId.state == "in_progress") {            console.log(downloadId.url);            chrome.downloads.cancel(downloadId.id,function() {                console.log("cancelled");            });            chrome.runtime.sendNativeMessage("com.hcs.jnlplauncher",                                              {url:downloadId.url},                                              function(response)                                              {                    console.log(chrome.runtime.lastError);                    console.log(response);                    }                );        }    }})

Put manifest.json and bg.js in a folder and load it as an Unpacked extension in chrome in developer mode under chrome://extensions

Get the ID for the extension from the chrome://extensions pages.

Next is the bridge between the extension and the shell script.

File: com.hcs.jnlplauncher.json

{  "name": "com.hcs.jnlplauncher",  "description": "JNLP Launcher",  "path": "/usr/local/bin/jnlp-launcher",  "type": "stdio",  "allowed_origins": [    "chrome-extension://iacomlhfiphkdfjjjmlgckdkhmkhkibe/"  ]}

Place this under "~/.config/google-chrome/NativeMessagingHosts" (for linux). see google for windows locations.

Put your extension ID from the previous step into that file.

Make sure javaws is in the path. (that chrome runs with). link to /usr/bin is easiest way to be sure.

Click on a jnlp file and enjoy!!! No prompt, no ClickToOpen, and no file saved in the Downloads directory.!

If someone would like to bundle this all together into a nice packaged installer and/or chrome extension feel free. Please credit me (Chris Holt -- hobie744@gmail.com) and let me know. At first glance, I couldn't see how to bundle the NativeMessagingHosts piece into the extension. Perhaps it has to be 2 pieces? This is my first adventure in Chrome Extensions and NativeMessaging. Most of the code comes from the API docs and examples, and there are probably a few bugs.


Launch the JNLP using an embedded applet deployed using web start.

  1. Start with a Swing based JApplet that accepts an image path (icon) and a string for the button. Deploy the applet (embedded in the web page, where the link would be) using JWS.
  2. When the user clicks the button, use the BasicService.showDocument(URL) method to launch the JWS (frame based) app. As I note in the demo. of the BasicService..

    ..In Java 6+, a call to show another web start launch file (e.g. BasiceService.showDocument(another.jnlp)) will be handed directly to JavaWS, with no browser window appearing.


Unfortunately this is a bug(/feature?) in Google Chrome which still exists, however it is partly fixed: you can now automatically open jnlp files, but it they are still saved to the downloads folder

  • download the jnlp
  • right click in the download bar and select to always open files of this type
  • clicking the jnlp now directly launches it