* * @param connection * @param callback * @returns {Promise }
(connection, callback)
| 1478 | * @returns {Promise<void>} |
| 1479 | */ |
| 1480 | async onLogEvent(connection, callback) { |
| 1481 | this._cdpWsConnection.on('message', (message) => { |
| 1482 | const params = JSON.parse(message) |
| 1483 | if (params.method === 'Runtime.consoleAPICalled') { |
| 1484 | const consoleEventParams = params['params'] |
| 1485 | let event = { |
| 1486 | type: consoleEventParams['type'], |
| 1487 | timestamp: new Date(consoleEventParams['timestamp']), |
| 1488 | args: consoleEventParams['args'], |
| 1489 | } |
| 1490 | |
| 1491 | callback(event) |
| 1492 | } |
| 1493 | |
| 1494 | if (params.method === 'Log.entryAdded') { |
| 1495 | const logEventParams = params['params'] |
| 1496 | const logEntry = logEventParams['entry'] |
| 1497 | let event = { |
| 1498 | level: logEntry['level'], |
| 1499 | timestamp: new Date(logEntry['timestamp']), |
| 1500 | message: logEntry['text'], |
| 1501 | } |
| 1502 | |
| 1503 | callback(event) |
| 1504 | } |
| 1505 | }) |
| 1506 | await connection.execute('Runtime.enable', {}, null) |
| 1507 | } |
| 1508 | |
| 1509 | /** |
| 1510 | * |