Calling JS Service

Version added 07-Mar-2018| Modified 15-Oct-2018

Importing JS File

In webOS Open Source Edition, basic template contains the webOS library in its webOSjs-0.1.0 directory. You can add this library to your app as below:

<script type="text/javascript" src="webOSjs-0.1.0/webOS.js"></script>

If you import already existing web app, follow the next steps: 

  1. Download the compressed library file from here. Then, unzip

  2. In your app project, create a subfolder named webOSjs-0.1.0 and copy the downloaded webOS.js into the lib folder. The webOS library file can be placed in any folder within your app project. You should set the proper directory when including the library in the source code. 

  3. Include the webOS library in your app as above.

Calling Services from Any Web App

Any application can include webOS.js and make webOS service calls using the webOS.service.request method.

To call a service in an app, use webOS.service.request.

var subscribeStatus = true; //change this to false to disable subscription 
var resubscribeStatus = true; //change this to false to disable resubscription 

var request = webOS.service.request("luna://com.mycom.helloworld/", {
	parameters: {  
	onSuccess: function(inResponse) {  
	onFailure: function(inError) {  
	onComplete: function(inResponse) {  
	subscribe: subscribeStatus,
	resubscribe: resubscribeStatus

Calling Service from another Service

Any service can include webOS.js and make webOS service calls using the method.

Below is an example of how a webOS service can be called using webOS.js.

var Service = require('webos-service'); 
var service = new Service("com.mycom.helloworld");

service.register("hello", function(message) {"luna://com.webos.service.connectionmanager/getstatus", {}, function(response) {
        if(response.payload.isInternetConnectionAvailable == true) {
            // ...
                "returnValue": true

For more details about webos-service module, see webos-service API Reference.


Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.