close search

Debugging — Web

This topic includes the following sections:

Logging to the console

When you're developing your application, place the code below somewhere in your application. Doing so will produce more logging output to your console, allowing you to better trace your program and understand what is happening behind the scenes.


You can also log messages to the console by calling the OT.log() method:

OT.log("my session ID: " + session.sessionId);

(Call OT.setLogLevel(OT.DEBUG) or OT.setLogLevel(OT.LOG) before calling OT.log().)

Testing multiple client connections on one machine

You cannot subscribe to a stream you publish in the same browser page. However, you can open the page in a second tab (or browser window) and subscribe to a stream published in the other tab (or window).

Using completion handlers

For many methods that complete asynchronously, the final parameter you pass in is a completion handler function. This function is called when the method completes or fails. If it fails, the function is passed an error object as a parameter.

For example, the following code calls the Session.connect() method, passing in a completion handler:

  var session = OT.initSession(apiKey, session);
  session.connect(token, function (error) {
    if (error) {
      if ( === "OT_NOT_CONNECTED") {
        alert("You are not connected to the internet. Check your network connection.");
      console.log("Failed to connect: ", error.message);
    } else {

For more information, see Handling exceptions.

Listening for exception events

To detect all exception events, add an event listener for the exception event, dispatched by the OT object. However, it is easier to react to errors in completion handlers for specific methods. See Handling exceptions.

// Listen for exceptions
OT.on("exception", function(event) {

Troubleshooting sessions with Inspector

Inspector provides post-mortem diagnostic information about OpenTok sessions. Enter a session ID or a reported issue ID (see the next section) into Inspector to view raw information at stream and user levels to help pinpoint errors, failures, and quality issues.

For details, see the Inspector documentation.

Reproducing issues with OpenTok Playground

Playground uses the OpenTok.js SDK to access the OpenTok platform and helps you recreate issues experienced in deployment.

For details, see the Playground documentation.

Reporting an issue

You can call the OT.reportIssue() method to programmatically report when your app experiences an issue. This method provides you with an issue ID, which you can use with the Inspector or when discussing the issue with the TokBox support team.

OT.reportIssue(function(error, issueId) {
  if (error) {
  } else {
    // You may want to use XMLHttpRequest to report this issue ID to a server
    // that can store it in a database for later reference.

The OT.reportIssue() method takes one parameter, a completion handler function, which is called when the call to OT.reportIssue() succeeds or fails. The completion handler function has two parameters. The first parameter is an error object that is set when the call to the reportIssue() method fails (for example, if the client is not connected to the network) or null when the call to the reportIssue() method succeeds. The second parameter is set to the reported issue ID (a unique string) when the call succeeds.