Introduce DEBUG module
This patch re-introduces the DEBUG module to expose some of the puppeteer's internals. Currently, only the protocol message communication is exposed under the 'puppeteer:protocol' namespace.
This commit is contained in:
parent
4581ada210
commit
0414dfa98b
@ -40,7 +40,7 @@ are used to test `phantom_shim`.
|
||||
|
||||
To run puppeteer tests, use:
|
||||
```
|
||||
npm run test-puppeteer
|
||||
npm run unit
|
||||
```
|
||||
|
||||
To run phantom-shim against phantomjs tests, use:
|
||||
@ -53,3 +53,15 @@ To run both puppeteer and phantom_shim tests, use:
|
||||
npm test
|
||||
```
|
||||
|
||||
## DEBUG module
|
||||
Puppeteer uses [debug](https://github.com/visionmedia/debug) module to expose some of it's inner guts under the `puppeteer` namespace.
|
||||
Try putting the following script in the `script.js` and running it via `DEBUG=* node script.js`:
|
||||
|
||||
```js
|
||||
const {Browser} = require('puppeteer');
|
||||
const browser = new Browser();
|
||||
browser.newPage().then(async page => {
|
||||
await page.navigate('https://example.com');
|
||||
browser.close();
|
||||
});
|
||||
```
|
||||
|
@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
let debug = require('debug')('puppeteer:protocol');
|
||||
|
||||
let EventEmitter = require('events');
|
||||
let WebSocket = require('ws');
|
||||
@ -46,6 +47,7 @@ class Connection extends EventEmitter {
|
||||
send(method, params = {}) {
|
||||
let id = ++this._lastId;
|
||||
let message = JSON.stringify({id, method, params});
|
||||
debug('◀ SEND ' + message);
|
||||
this._ws.send(message);
|
||||
return new Promise((resolve, reject) => {
|
||||
this._callbacks.set(id, {resolve, reject, method});
|
||||
@ -56,6 +58,7 @@ class Connection extends EventEmitter {
|
||||
* @param {string} message
|
||||
*/
|
||||
_onMessage(message) {
|
||||
debug('RECV ► ' + message);
|
||||
let object = JSON.parse(message);
|
||||
if (object.id && this._callbacks.has(object.id)) {
|
||||
let callback = this._callbacks.get(object.id);
|
||||
|
29
package-lock.json
generated
29
package-lock.json
generated
@ -247,11 +247,11 @@
|
||||
}
|
||||
},
|
||||
"debug": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
||||
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
|
||||
"version": "2.6.8",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.8.tgz",
|
||||
"integrity": "sha1-5zFTHKLt4n0YgiJCfaF4IdaP9Pw=",
|
||||
"requires": {
|
||||
"ms": "0.7.1"
|
||||
"ms": "2.0.0"
|
||||
}
|
||||
},
|
||||
"deep-is": {
|
||||
@ -477,6 +477,21 @@
|
||||
"debug": "2.2.0",
|
||||
"mkdirp": "0.5.0",
|
||||
"yauzl": "2.4.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"debug": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/debug/-/debug-2.2.0.tgz",
|
||||
"integrity": "sha1-+HBX6ZWxofauaklgZkE3vFbwOdo=",
|
||||
"requires": {
|
||||
"ms": "0.7.1"
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
|
||||
"integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg="
|
||||
}
|
||||
}
|
||||
},
|
||||
"fast-levenshtein": {
|
||||
@ -973,9 +988,9 @@
|
||||
}
|
||||
},
|
||||
"ms": {
|
||||
"version": "0.7.1",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-0.7.1.tgz",
|
||||
"integrity": "sha1-nNE8A62/8ltl7/3nzoZO6VIBcJg="
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
||||
},
|
||||
"mute-stream": {
|
||||
"version": "0.0.7",
|
||||
|
@ -20,6 +20,7 @@
|
||||
"author": "The Chromium Authors",
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"dependencies": {
|
||||
"debug": "^2.6.8",
|
||||
"extract-zip": "^1.6.5",
|
||||
"mime": "^1.3.4",
|
||||
"progress": "^2.0.0",
|
||||
|
Loading…
Reference in New Issue
Block a user