browser: add webContents.debugger api

This commit is contained in:
Robo 2016-01-21 23:52:23 +05:30
parent 2e8a2c3a7f
commit 0e2323c9c8
6 changed files with 311 additions and 1 deletions

View file

@ -833,3 +833,66 @@ 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.
```javascript
try {
win.webContents.debugger.attach("1.1");
} catch(err) {
console.log("Debugger attach failed : ", err);
};
win.webContents.debugger.onDetach(function(reason) {
console.log("Debugger detached due to : ", reason);
});
win.webContents.debugger.onEvent(function(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 - Required debugging protocol version.
Attaches the debugger 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 - JSON object with request parameters.
* `callback` Function - Response
* `result` Object - Response defined by the 'returns' attribute of
the command description in the remote debugging protocol.
Send given command to the debugging target.
#### `webContents.debugger.onDetach(callback)`
* `callback` Function
* `reason` String - Reason for detaching debugger.
`callback` is fired when debugging session is terminated. This happens either when
`webContents` is closed or devtools is invoked for the attached `webContents`.
#### `webContents.debugger.onEvent(callback)`
* `callback` Function
* `method` String - Method name.
* `params` Object - Event parameters defined by the 'parameters'
attribute in the remote debugging protocol.
`callback` is fired whenever debugging target issues instrumentation event.