# Chrome Remote Debugger

Use the Chrome Remote Debugger to debug a Cast application.

> [!CAUTION]
> **Caution:** Leaving the Remote Debugger attached for prolonged periods can exhaust resources on the Web Receiver and result in a failure.

> [!NOTE]
> **Note:** Second and third generation Chromecast devices running firmware version 1.49 may not be able to debug Cast sessions using the Chrome Remote Debugger. If you are not able to see your app in chrome://inspect, please try another Cast device or use the [Cast Debug Logger](https://developers.google.com/cast/docs/debugging/cast_debug_logger).

Launch Chrome Remote Debugger for a particular Google Cast device as follows:

To debug Cast apps on an Android TV device, see
[Android TV: Debugging](https://developers.google.com/cast/docs/android_tv_receiver/debugging#debugging).

To debug a Web Receiver app on Google Cast devices, do the following:

1. [Register](https://developers.google.com/cast/docs/registration) your application and Google Cast device
   on the [Google Cast SDK Developer Console](https://cast.google.com/publish).

   > [!NOTE]
   > **Note:** The device serial number can be found by navigating to the Google Cast SDK Developer Console and casting the tab to your device.

   <br />

   Both the application and device must be registered to the same developer
   account in order for you to perform debugging.
2. Start your *sender* app and cast to the Google Cast device
   to load the Web Receiver app for debugging. Make sure your sender and Web
   Receiver devices are connected to the same network.

   > [!WARNING]
   > **Important:** Debugging will not work if the this step is skipped.

   <br />

3. There are two ways to connect to your device for remote debugging:

   1. Chrome Inspector

      1. In the Chrome browser, enter the following in the address
         field to go to the Chrome inspector:

             chrome://inspect

         A list of Cast-enabled devices on that network appears.
      2. Select the device for the Web Receiver app you want to debug by
         clicking its `Inspect` link.

         An inspector window should open, enabling you to remotely debug the
         Web Receiver app.
   2. Directly to the device's 9222 port

      1. In the Chrome browser, enter the following in the address field to
         go to the device you are debugging directly. This may be faster
         than the Chrome Inspector if you have many devices on your network:

             <device IP address>:9222

         The device IP address can be found by selecting the device in the
         Google Home app, going to settings, and looking under the
         Information section.
      2. Select the session you would like to debug by clicking its
         `Remote Debugging` link.

      3. If the Chrome Remote Debugger does not populate, select the
         icon to the left of the address bar and select `site settings`.
         Scroll to the bottom of the settings and change the setting for
         `Insecure content` to `Allow`.

4. In the Chrome Remote Debugger console, enable debug logging, by entering the
   following:

   ```
   cast.framework.CastReceiverContext.getInstance().setLoggerLevel(cast.framework.LoggerLevel.DEBUG);
   ```

   <br />

   > [!WARNING]
   > **Warning:** Always disable debug logging for production, and never log any personally identifiable information.

   Full DOM manipulation is supported as well as the full Chrome JavaScript
   REPL ([console](https://developers.google.com/chrome-developer-tools/docs/console)), which will allow you
   to tinker with the running Web Receiver app.

   When your Web Receiver is torn down (lifecycle ended), the debugger will
   become inactive with a warning message along the top. At this point you can
   no longer interact with the debugger. To restart debugging, you must restart
   the Web Receiver app and then reload the inspector.

## Breakpoints

You can add manual breakpoints to your code by using `debugger;` within your
Web Receiver code.

## Local caching

Use `window.location.reload(true);` to perform a forced reload that flushes the
cache of the Web Receiver application.

## Preserving logs between sessions

You can preserve the logs between sessions by clicking the gear icon within the
debugger and checking the box next to "Preserve log upon navigation".

> [!NOTE]
> **Note:** If you're having problems playing streams on a Cast device, it may be an issue with CORS. Use a publicly available CORS proxy server to test your streams. (Be aware that third-party software referenced here is not controlled by Google. Google cannot guarantee that third-party software will operate as intended. Proceed with caution.)