JavaScriptExecutor is now API

October 17, 2012 | 1 min Read

In the second milestone of RAP v2.0 we introduced a new Client API. It allows as to distinguish between different clients (web client, native android client…) and handle their specific capabilities. We added a service provider interface Client that can be acquired using the new method RWT.getClient(). Client implementations can provide different services. One of the most requested enhancements in RAP was to provide a public JavaScript execution API. With the new Client API in place we decided to expose the JavaScriptExecutor as a service of the WebClient. For those of you, that are using the old internal JSExecutor class, you have to replace the old static call:

JSExecutor.executeJS( script );

with the new service call:

Client client = RWT.getClient();
JavaScriptExecutor executor = client.getService( JavaScriptExecutor.class );
if( executor != null ) {
  executor.execute( script );
  ...
}

Please note that the null check is obligatory, because only the WebClient provides JavaScriptExecutor service. Always execute a script with a caution. If the script throws an error, it will crash the web client. Accessing internals of the web client is strongly discouraged. These changes are currently available only in the latest nightly RAP build and will be part of RAP v2.0M3. P.S. BrowserHistory has been converted to a client service too.

Stay Updated with Our Latest Articles

Want to ensure you get notifications for all our new blog posts? Follow us on LinkedIn and turn on notifications:

  1. Go to the EclipseSource LinkedIn page and click "Follow"
  2. Click the bell icon in the top right corner of our page
  3. Select "All posts" instead of the default setting
Follow EclipseSource on LinkedIn
Ivan Furnadjiev

Ivan Furnadjiev

RAP Project Lead at EclipseSource