Merge pull request #4182 from deepak1556/debugger_api_patch

browser: add webContents.debugger api
This commit is contained in:
Cheng Zhao 2016-01-24 21:43:18 +08:00
commit e1e58b642e
9 changed files with 500 additions and 1 deletions

View file

@ -833,3 +833,73 @@ Get the `WebContents` of DevTools for this `WebContents`.
**Note:** Users should never store this object because it may become `null`
when the DevTools has been closed.
### `webContents.debugger`
Debugger API serves as an alternate transport for [remote debugging protocol][rdp].
```javascript
try {
win.webContents.debugger.attach("1.1");
} catch(err) {
console.log("Debugger attach failed : ", err);
};
win.webContents.debugger.on('detach', function(event, reason) {
console.log("Debugger detached due to : ", reason);
});
win.webContents.debugger.on('message', function(event, method, params) {
if (method == "Network.requestWillBeSent") {
if (params.request.url == "https://www.github.com")
win.webContents.debugger.detach();
}
})
win.webContents.debugger.sendCommand("Network.enable");
```
#### `webContents.debugger.attach([protocolVersion])`
* `protocolVersion` String (optional) - Requested debugging protocol version.
Attaches the debugger to the `webContents`.
#### `webContents.debugger.isAttached()`
Returns a boolean indicating whether a debugger is attached to the `webContents`.
#### `webContents.debugger.detach()`
Detaches the debugger from the `webContents`.
#### `webContents.debugger.sendCommand(method[, commandParams, callback])`
* `method` String - Method name, should be one of the methods defined by the
remote debugging protocol.
* `commandParams` Object (optional) - JSON object with request parameters.
* `callback` Function (optional) - Response
* `error` Object - Error message indicating the failure of the command.
* `result` Object - Response defined by the 'returns' attribute of
the command description in the remote debugging protocol.
Send given command to the debugging target.
#### Event: 'detach'
* `event` Event
* `reason` String - Reason for detaching debugger.
Emitted when debugging session is terminated. This happens either when
`webContents` is closed or devtools is invoked for the attached `webContents`.
#### Event: 'message'
* `event` Event
* `method` String - Method name.
* `params` Object - Event parameters defined by the 'parameters'
attribute in the remote debugging protocol.
Emitted whenever debugging target issues instrumentation event.
[rdp]: https://developer.chrome.com/devtools/docs/debugger-protocol