Web Integration Module

NodeJS as a browser plugin for 5250 Web terminal to Desktop integration?

What? How? Find out here...

With the latest Green Screens update, advanced users can write custom desktop scripts in JavaScript to enable unprecedented integration possibilities between web 5250 terminal and desktop. This is a short introduction about a powerful feature implemented inside our product.

Introduction first

WebKit based browsers as Google Chrome, new MS Edge and many more supports creating browser plugins. A custom JavaScript written application which can interact with other web pages or web applications. One of the great examples are password managers or antivirus extensions or very popular AdBlockers.

However, some extensions require more advanced features not available in JavaScript due to JavaScript security settings preventing special operations as operations on computer disk. Thus, browser developers created a standard for browser plugins.

In the beginning, that was NPAPI, a dll way. Today NPAPI is deprecated in favor of Native Messaging Protocol which is actually very simple to implement. It's a simple console application using JSON messages exchanged between browser and console application in a safe and secure way.

To activate a browser plugin, a browser extension is required, as a plugin can be started only through extension internal code, so we needed to develop a browser extension and plugin application itself for our product.

Pushing the limits

Our first usage was developing PCH (print-command-host) plugin which purpose is to enable web printing integration and RMTCMD support. Later, we added HLL API through separate HLL host plugin to enable the same functionality as IBM HLL for Desktop Terminal Clients has.

Why NodeJS?

Our HLL browser plugin is actually written in JavaScript for NodeJS and packed into a self-executable application. NodeJS is very powerful with thousands of plugins and modules, and it is actually very easy to write all kind of services. All with just JavaScript. In one moment, we realized that our HLL module is much more powerful than just having a simple HLL integration.

An idea


An idea is about extensibility. As host.exe - browser plugin module is actually a packaged NodeJS, we realized that with a few lines of code we can add a feature for this module to load external user JavaScript. As it is running locally, out of the browser isolation scope, actually anything is possible to develop.

We don't like to call it HLL module, as it is much powerful, however, advanced 5250 terminal users familiar with HLL will rather accept HLL term than web-to-desktop integration module.

Security

When we mention browser, isolation context and out of isolation scope, the first that might come to your mind is security.

For HLL module to be used, it has to be not only enabled inside extension options, but also custom JavaScript messaging code must exist inside the web terminal for processing custom information received from custom code.

All messages exchanged between web terminal, browser extension and browser plugin are in JSON data format. There is no remote code call etc.

Browser plugin can receive JSON data only from our web terminal browser extension and extension can communicate only with URLs' pointing to our web terminal.

So, in general it is quite safe, however, it is advanced users responsibility what scripts they will create and how sensitive those script will be.

How to set it up

First, install Green Screens Browser Extension from Google Web Store. One should see new terminal icon next to the address bar.

  • Right-click on the icon and select Options from drop down menu  
  • Select tab Link and use Download link to open browser plugin installation page
  • Download installation module and start it to install browser plugin
  • Enable PCH and HLL options on extension options page.

Browser plugin will be installed into "%PROGRAMDATA%\Green Screens\Link",  (defaults to C:\ProgramData\Green Screens\Link).

This directory contains two subfolders: pch and hll. Hll subdirectory contains host.exe (NodeJS app). Hll subdirectory is also a main root for custom NodeJS scripts.

There, one can find index.js which is initial script loaded every time host.exe is started by browser extension. The Script is the same as any NodeJS startup script, responsible to load other custom modules.

In the same directory, there are 4 demo apps (app1, app2, app3, app4) with usage instructions. Enable them inside index.js and restart host.exe.

Restart HLL module can be done in 3 ways:

  • restart browser completely
  • disable then enable back Green Screens Browser Extension
  • use extension Options -> Settings->Link tab, set HLL to disabled, save, set HLL to enabled, save.

Usage examples

As this is completely new and uncharted area, possibilities are endless. For an example, create custom app for creating charts from terminal data or custom word/excel generator, etc.

With installation one can find 4 apps.

  • app1 - simple introduction app showing how to integrate custom code
  • app2 - create push message service which can be used from another web page. The Service will listen for all messages exchanged between web terminal and extension and forward them as a push message to the registered web page. Client code example is in client.js
  • app3 - screen logging - every time new terminal screen arrives; screen data will be logged into a log file named by the active terminal displayName.
  • app4 - example showing how to use nanomsg for IPC. Nanomsg is a module for interprocess communication between different programs.

The only limit to what can be done is imagination and creativity.

Playground 1

The easiest way to test if browser extension and browser plugin works correctly is first edmo app1.

Enable PCH in extension Options page and then follow steps below.  

To execute desktop application from terminal (simulate STRRMTCMD call)

  • Open this link to activate extension.
  • Open browser console by pressing F12 in address bar and paste code below
Tn5250.Extension.remoteCommand('notepad.exe test.txt')

If all is set up correctly, the notepad program should open.

NOTE: This is for testing only. When STRRMTCMD is called from a live terminal console, data received from IBM machine will be sent to the PCH through remoteCommand function.

Video is not visible, most likely your browser does not support HTML5 video

Playground 2

If you want to play with demos provided within HLL module, we've enabled offline environment on our web site.

Follow these steps

  • Go to "%PROGRAMDATA%\Green Screens\Link\Hll" and open index.js
  • Add line require('./app2/index'); and save file
  • Completely restart browser (or disable then enable Green Screens Extension )
  • Open about:blank in new tab, and it's browser console
    (press F12 inside address bar)
  • Paste code below to the browser console
var eventSource = new EventSource('http://localhost:5000');
eventSource.addEventListener('eventType', (e) => { console.log(e);});
eventSource.onerror=(e) => {console.log(e)};
eventSource.onmessage=(e) => {console.log(e.data)};
  • Open this link to activate extension.
  • Open browser console by pressing F12 in address bar and paste code below
Tn5250.HLL.send({x:123345});
  • Switch to about:blank console. Message we send from web terminal console should be now visible in about:blank console.

This example shows how to create advanced messaging integrating  web terminal and NodeJS.

Video is not visible, most likely your browser does not support HTML5 video