// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

[
  {
    "namespace": "debugger",
    "description": "The <code>chrome.debugger</code> API serves as an alternate transport for Chrome's <a href='http://code.google.com/chrome/devtools/docs/remote-debugging.html'>remote debugging protocol</a>. Use <code>chrome.debugger</code> to attach to one or more tabs to instrument network interaction, debug JavaScript, mutate the DOM and CSS, etc. Use the Debuggee <code>tabId</code> to target tabs with sendCommand and route events by <code>tabId</code> from onEvent callbacks.",
    "types": [
      {
        "id": "Debuggee",
        "type": "object",
        "description": "Debuggee identifier. Either tabId or extensionId must be specified",
        "properties": {
          "tabId": { "type": "integer", "optional": true, "description": "The id of the tab which you intend to debug." },
          "extensionId": { "type": "string", "optional": true, "description": "The id of the extension which you intend to debug. Attaching to an extension background page is only possible when 'enable-silent-debugging' flag is enabled on the target browser." },
          "targetId": { "type": "string", "optional": true, "description": "The opaque id of the debug target." }
        }
      },
      {
        "id": "TargetInfo",
        "type": "object",
        "description": "Debug target information",
        "properties": {
          "type": {
            "type": "string",
            "description": "Target type.",
            "enum" : ["page", "background_page", "worker", "other" ]
          },
          "id": { "type": "string", "description": "Target id." },
          "tabId": { "type": "integer", "optional": true, "description": "The tab id, defined if type == 'page'." },
          "extensionId": { "type": "string", "optional": true, "description": "The extension id, defined if type = 'background_page'." },
          "attached": { "type": "boolean", "description": "True if debugger is already attached." },
          "title": { "type": "string", "description": "Target page title." },
          "url": { "type": "string", "description": "Target URL." },
          "faviconUrl": { "type": "string", "optional": true, "description": "Target favicon URL." }
        }
      }
    ],
    "functions": [
      {
        "name": "attach",
        "type": "function",
        "description": "Attaches debugger to the given target.",
        "parameters": [
          {
            "$ref": "Debuggee",
            "name": "target",
            "description": "Debugging target to which you want to attach."
          },
          {
            "type": "string",
            "name": "requiredVersion",
            "description": "Required debugging protocol version (\"0.1\"). One can only attach to the debuggee with matching major version and greater or equal minor version. List of the protocol versions can be obtained <a href='http://code.google.com/chrome/devtools/docs/remote-debugging.html'>here</a>."
          },
          {
            "type": "function",
            "name": "callback",
            "optional": true,
            "parameters": [],
            "description": "Called once the attach operation succeeds or fails. Callback receives no arguments. If the attach fails, $ref:runtime.lastError will be set to the error message."
          }
        ]
      },
      {
        "name": "detach",
        "type": "function",
        "description": "Detaches debugger from the given target.",
        "parameters": [
          {
            "$ref": "Debuggee",
            "name": "target",
            "description": "Debugging target from which you want to detach."
          },
          {
            "type": "function",
            "name": "callback",
            "optional": true,
            "parameters": [],
            "description": "Called once the detach operation succeeds or fails. Callback receives no arguments. If the detach fails, $ref:runtime.lastError will be set to the error message."
          }
        ]
      },
      {
        "name": "sendCommand",
        "type": "function",
        "description": "Sends given command to the debugging target.",
        "parameters": [
          {
            "$ref": "Debuggee",
            "name": "target",
            "description": "Debugging target to which you want to send the command."
          },
          {
            "type": "string",
            "name": "method",
            "description": "Method name. Should be one of the methods defined by the <a href='http://code.google.com/chrome/devtools/docs/remote-debugging.html'>remote debugging protocol</a>."
          },
          {
            "type": "object",
            "name": "commandParams",
            "optional": true,
            "additionalProperties": { "type": "any" },
            "description": "JSON object with request parameters. This object must conform to the remote debugging params scheme for given method."
          },
          {
            "type": "function",
            "name": "callback",
            "optional": true,
            "parameters": [
              {
                "type": "object",
                "name": "result",
                "optional": true,
                "additionalProperties": { "type": "any" },
                "description": "JSON object with the response. Structure of the response varies depending on the method and is defined by the remote debugging protocol."
              }
            ],
            "description": "Response body. If an error occurs while posting the message, the callback will be called with no arguments and $ref:runtime.lastError will be set to the error message."
          }
        ]
      },
      {
        "name": "getTargets",
        "type": "function",
        "description": "Returns the list of available debug targets.",
        "parameters": [
          {
            "type": "function",
            "name": "callback",
            "parameters": [
              {
                "type": "array",
                "name": "result",
                "items": {"$ref": "TargetInfo"},
                "description": "Array of TargetInfo objects corresponding to the available debug targets."
              }
            ]
          }
        ]
      }
    ],
    "events": [
      {
        "name": "onEvent",
        "type": "function",
        "description": "Fired whenever debugging target issues instrumentation event.",
        "parameters": [
          {
            "$ref": "Debuggee",
            "name": "source",
            "description": "The debuggee that generated this event."
          },
          {
            "type": "string",
            "name": "method",
            "description": "Method name. Should be one of the notifications defined by the <a href='http://code.google.com/chrome/devtools/docs/remote-debugging.html'>remote debugging protocol</a>."
          },
          {
            "type": "object",
            "name": "params",
            "optional": true,
            "additionalProperties": { "type": "any" },
            "description": "JSON object with the response. Structure of the response varies depending on the method and is defined by the remote debugging protocol."
          }
        ]
      },
      {
        "name": "onDetach",
        "type": "function",
        "description": "Fired when browser terminates debugging session for the tab. This happens when either the tab is being closed or Chrome DevTools is being invoked for the attached tab.",
        "parameters": [
          {
            "$ref": "Debuggee",
            "name": "source",
            "description": "The debuggee that was detached."
          },
          {
            "type": "string",
            "name": "reason",
            "description": "Connection termination reason.",
            "enum": [ "target_closed", "canceled_by_user", "replaced_with_devtools" ]
          }
        ]
      }
    ]
  }
]