webOS API

The webOS API provides methods for retrieving TV-specific information and settings.

Methods of this API are compatible with methods of the webOS.js library used on the previous versions of webOS TV. If you have used methods of webOS.js to implement your app, we recommend that you replace the webOS.js library with the webOSTV.js library.

Note

Some methods of webOS.js are not executed on webOS TV. In the webOSTV.js library, only the methods supported by TV are provided.

Methods

TypeNameDescription
Member
Holds properties representing the build version of the webOSTV.js library.
Holds properties representing the platform identification of webOS variants.
Method
Returns the device-specific information.
Returns the app ID of the caller app.
Returns the appinfo.json data of the caller app with a cache saved to `webOS.appInfo`.
Returns the full URI path of the caller app.
Emulates the back key of the remote controller to move backward 1 level.
Returns the system-specific information.
Checks whether the virtual keyboard is visible.
Creates and sends a service request to the system of the webOS TV.

libVersion

Description

A member representing the build version of the webOSTV.js library.

Properties

None

Example

if (Number(webOS.libVersion.split('.')[0]) > 0) {
  // use webOSDev APIs
}

See also

  • None

platform

Description

A member representing the platform identification of webOS variants.

Properties

NameTypeDescription
tv
Boolean
Indicates whether the platform identification is webOS TV. If the platform identification is not webOS TV, undefined is returned.
  • true: webOS TV

Example

if (webOS.platform.tv === true) {
    // calls TV specific service APIs
} else {
    console.log('This device is not TV.');
}

See also

  • None

deviceInfo

Description

Returns the device-specific information regarding the TV model, OS version, SDK version, screen size, and resolution.

Parameters

NameTypeDescriptionRequired
devicecallback(info)
Function
The function to call once the information is collected.
  • info: JSON object containing the device information details
Properties
NameTypeDescriptionRequired
modelName
String
The model name of the device in UTF-8 format.
Yes
version
String
The full name of TV SW version.
You can check the value in the software version of the TV Settings menu.
Yes
versionMajor
Number
The subset of TV SW version: Major version number.
Yes
versionMinor
Number
The subset of TV SW version: Minor version number.
Yes
versionDot
Number
The subset of TV SW version: Revision version number.
Yes
sdkVersion
String
The webOS TV SDK version in X.X.X format.
You can check the value in the webOS TV version of the TV Settings menu. For more details about the SDK version, see
webOS TV SDK Introduction.
Yes
screenWidth
Number
The screen width in pixels for video playback.
For the app resolution (width) for graphics display, use
`window.innerWidth`.
Yes
screenHeight
Number
The screen height in pixels for video playback.
For the app resolution (height) for graphics display, use
`window.innerHeight`.
Yes
uhd
Boolean
Indicates whether the device supports Ultra HD resolution.
  • true: The device supports Ultra HD resolution.
  • false: The device does not support Ultra HD resolution.
Yes
uhd8K
Boolean
Indicates whether the device supports 8K UHD resolution.
  • true: The device supports 8K UHD resolution.
  • false: The device does not support 8K UHD resolution.
Yes
oled
Boolean
Indicates whether the display type of device is OLED or not.
  • true: The display type is OLED.
  • false: The display type is LCD.
No*
ddrSize
String
The size of DDR DRAM in bytes. For example, if the size of DDR DRAM is 3G, the return value is 3G.
No*
hdr10
Boolean
Indicates whether the device supports HDR10.
  • true: The device supports HDR10.
  • false: The device does not support HDR10.
Yes
dolbyVision
Boolean
Indicates whether the device supports Dolby Vision.
  • true: The device supports Dolby Vision.
  • false: The device does not support Dolby Vision.
Yes
dolbyAtmos
Boolean
Indicates whether the device supports Dolby Atmos.
From
webOSTV.js v1.2.6, it returns whether the device supports Dolby Atmos considering the connection status of external ARC devices and sound settings.
  • true: The device supports Dolby Atmos.
  • false: The device does not support Dolby Atmos.
Yes
brandName
String
The brand name of the device.
  • For example, "LG"
Yes
manufacturer
String
The manufacturer of the device.
  • For example, "LG Electronics"
Yes
mainboardMaker
String
The mainboard maker of the device.
  • For example, "LG"
No*
platformBizType
String
The platform business type of the device.
  • "LG"
  • "wee": The platform business type is not "LG".
Yes
tuner
Boolean
Indicates whether the device supports a tuner.
  • true: The device supports a tuner.
  • false: The device is tunerless.
Yes
* On previous versions of webOS TV that do not support a property, the value undefined is returned.
Yes

Call returns

Returns undefined.

Example

webOS.deviceInfo(function (device) {
  if (device.modelName.indexOf('32LB') > -1) {
    // Do something
  }

  var version = device.version.split('.');
  if (Number(version[0]) > 3 || Number(device.versionMajor) > 3) {
    // Do something
    if (Number(version[1]) > 2 || Number(device.versionMinor) > 2) {
      // Do something
      if (Number(version[2]) > 13 || Number(device.versionDot) > 13) {
        // Do something
      }
    }
  }

  var sdkVersion = device.sdkVersion.split('.');
  if (sdkVersion[0] === '3') {
    // Do something
  }

  if (device.screenWidth === 1920 && device.screenHeight === 1080) {
    // Do something
  }

  if (device.uhd && device.uhd === true) {
    // Shows UHD contents
  }

  if (device.uhd8K && device.uhd8K === true) {
    // Shows 8K UHD contents
  }

  if (device.oled && device.oled === true) {
    // Do something
  }

  if (device.ddrSize) {
    var ddrSize = device.ddrSize.split('G')[0];
    // Do something
  }

  if (device.hdr10 && device.hdr10 === true) {
    // Play HDR10 contents
  }

  if (device.dolbyVision && device.dolbyVision === true) {
    // Play Dolby Vision contents
  }

  if (device.dolbyAtmos && device.dolbyAtmos === true) {
    // Play Dolby Atmos contents
  }

  if (device.brandName && device.brandName === 'LG') {
    // Do something
  }

  if (device.manufacturer && device.manufacturer === 'LG Electronics') {
    // Do something
  }

  if (device.mainboardMaker && device.mainboardMaker === 'LG') {
    // Do something
  }

  if (device.platformBizType && device.platformBizType === 'LG') {
    // Do something
  }

  if (device.tuner === false) {
    // The device is tunerless
  }
});

See also

fetchAppId

Description

Returns the app ID of the calling app.

Parameters

None

Call returns

Name

Type

Description

appId

String

The app ID

Example

var appId = webOS.fetchAppId();
if (appId.length !== 0) {
  webOS.service.request('luna://com.webos.service.drm', {
    method: 'load',
    parameters: {
      appId: appId,
      drmType: 'playready',
    },
    onSuccess: function (res) {
      // sendDrmMessage
    },
    onFailure: function (res) {
      // error handling
    },
  });
} else {
  console.error('Getting application ID failed.');
}

See also

fetchAppInfo

Description

Returns the appinfo.json data of the caller app with a saved cache.

Parameters

NameTypeDescriptionRequired
appinfocallback
Function
The function to be called upon completion
NameTypeDescription
info
Object
The JSON object read from the app's appinfo.json file. If it is not found, undefined is returned.
No
path
String
An optional relative file path to read appinfo.json. The file name (appinfo.json) must be included in the file path.
  • If your app is packaged into an IPK file, get the path using the fetchAppRootPath method.
  • If your app is hosted by a server, the path will be the URL of the server.
No

Call returns

Returns undefined.

Example

var path = webOS.fetchAppRootPath();
if (path.length !== 0) {
  // It works only in the case of packaged application
  webOS.fetchAppInfo(function (info) {
    if (info) {
      var version = info.version && info.version.split('.');
      if (Number(version[0]) > 1) {
        // different implementation
      }
    } else {
      console.error('Error occurs while getting appinfo.json.');
    }
  }, path + 'appinfo.json');
} else {
  console.error('Getting application root path failed.');
}

See also

fetchAppRootPath

Description

Returns the full URI path of the caller app.

Parameters

None

Call returns

Name

Type

Description

uri

String

The app's URI path where the app is located

Example

var path = webOS.fetchAppRootPath();
if (path.length !== 0) {
  // It works only in the case of packaged application
  webOS.fetchAppInfo(function (info) {
    if (info) {
      var version = info.version && info.version.split('.');
      if (Number(version[0]) > 1) {
        // different implementation
      }
    } else {
      console.error('Error occurs while getting appinfo.json.');
    }
  }, path + 'appinfo.json');
} else {
  console.error('Getting application root path failed.');
}

See also

  • None

platformBack

Description

Emulates the back key of the remote controller to move backward 1 level. On webOS TV 6.0 or higher, a popup asking whether to exit the app is displayed, and on webOS TV 5.0 or lower, the Home launcher is launched. For more information, see Back Button.

Parameters

None

Call returns

None

Example

function initPage() {
  document.querySelector('#refresh').addEventListener('click', function () {
    window.location.reload();
  });
  ...
  document
    .querySelector('#platformBack')
    .addEventListener('click', function () {
      webOS.platformBack();
    });
}

See also

  • None

systemInfo

Description

Returns the system-specific information regarding country, service country, and timezone.

Parameters

None

Call returns

Name

Type

Description

country

String

The country where the TV broadcasts. If the value does not exist, undefined is returned.

smartServiceCountry

String

The country where the smart service is provided. If the value does not exist, undefined is returned.

timezone

String

The time zone where the TV broadcasts. If the value does not exist, undefined is returned.

Example

if (
  (sysInfo.country && sysInfo.country === 'KOR') ||
  (sysInfo.smartServiceCountry && sysInfo.smartServiceCountry === 'KOR') ||
  (sysInfo.timezone && sysInfo.timezone === 'Asia/Seoul')
) {
  // Shows Korean contents
}

See also

keyboard.isShowing

Description

Checks whether the virtual keyboard is visible. On the previous version of webOS TV that does not support this property, undefined is returned.

Parameters

None

Call returns

NameTypeDescription
show
Boolean
Indicates whether the virtual keyboard is displayed or hidden.
  • true: The virtual keyboard is displayed.
  • false: The virtual keyboard is hidden.

Example

if (webOS.keyboard.isShowing() === true) {
  // other div style fade out
} else {
  console.log('Keyboard is hidden or this API is not supported.');
}

See also

  • None

service.request

Description

Creates and sends a service request to the system of the webOS TV.

Parameters

NameTypeDescriptionRequired
uri
String
The service URI.
It accepts the normal service URI format, as well as the extended format with the service method included.
Yes
param
Object
Service request options.
Properties
NameTypeDescriptionRequired
method
String
The service method being called.
No
parameters
Object
The JSON object of the request parameters to send.
No
subscribe
Boolean
Indicates whether a subscription is desired for this request.
  • true: Request the subscription.
  • false: Do not request the subscription.
No
resubscribe
Boolean
Indicates whether the request should resubscribe after a failure has occurred.
  • true: Request the re-subscription.
  • false: Do not request the re-subscription.
No
onSuccess
Function
The callback function called when the method succeeds.
No
onFailure
Function
The callback function called when the method fails.
No
onComplete
Function
The callback function called when a request is complete (regardless of success or failure).
No
No

Call returns

NameTypeDescription
requestObject
Object
Resulting request object. This object can be used to cancel subscriptions.
Properties
NameTypeDescription
uri
String
The full-service request URI, including method name.
params
Object
The JSON object of the request parameters to send.
subscribe
Boolean
Indicates whether a subscription is desired for this request.
  • true: Subscribed
  • false: Not subscribed
resubscribe
Boolean
Indicates whether the request should resubscribe after a failure has occurred.
  • true: Resubscribed
  • false: Not resubscribed
onSuccess
Function
The callback function called when the method succeeds.
onFailure
Function
The callback function called when the method fails.
onComplete
Function
The callback function called when a request is complete (regardless of success or failure).
send
Function
Sends the request. It is automatically called on creation. No argument is required.
cancel
Function
Cancels the service request and any associated subscription. No argument is required.

Complete callback returns

Name

Type

Description

response

Object

The JSON object containing the service's response data; either one of proper response data or error details.

Success callback returns

Name

Type

Description

response

Object

The JSON object containing the service's response data

Failure callback returns

Name

Type

Description

error

Object

The JSON object containing the service's error details.

Example

function callSystemService() {
  webOS.service.request('luna://com.palm.systemservice', {
    method: 'time/getSystemTime',
    parameters: { subscribe: true },
    onSuccess: function (res) {
      console.log('system time suc', res);
    },
    onFailure: function (res) {
      console.log('system time fail', res);
    },
  });
}

See also

  • None

No Headings