| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -557,6 +557,22 @@ This feature is only available with the `--experimental-network-inspection` flag | |||
| 557 | 557 | Broadcasts the `Network.loadingFinished` event to connected frontends. This event indicates that | |
| 558 | 558 | HTTP request has finished loading. | |
| 559 | 559 | ||
| 560 | + ### `inspector.Network.loadingFailed([params])` | ||
| 561 | + | ||
| 562 | + <!-- YAML | ||
| 563 | + added: | ||
| 564 | + - REPLACEME | ||
| 565 | + --> | ||
| 566 | + | ||
| 567 | + > Stability: 1 - Experimental | ||
| 568 | + | ||
| 569 | + * `params` {Object} | ||
| 570 | + | ||
| 571 | + This feature is only available with the `--experimental-network-inspection` flag enabled. | ||
| 572 | + | ||
| 573 | + Broadcasts the `Network.loadingFailed` event to connected frontends. This event indicates that | ||
| 574 | + HTTP request has failed to load. | ||
| 575 | + | ||
| 560 | 576 | ## Support of breakpoints | |
| 561 | 577 | ||
| 562 | 578 | The Chrome DevTools Protocol [`Debugger` domain][] allows an | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,6 +201,7 @@ const Network = { | |||
| 201 | 201 | requestWillBeSent: (params) => broadcastToFrontend('Network.requestWillBeSent', params), | |
| 202 | 202 | responseReceived: (params) => broadcastToFrontend('Network.responseReceived', params), | |
| 203 | 203 | loadingFinished: (params) => broadcastToFrontend('Network.loadingFinished', params), | |
| 204 | + loadingFailed: (params) => broadcastToFrontend('Network.loadingFailed', params), | ||
| 204 | 205 | }; | |
| 205 | 206 | ||
| 206 | 207 | module.exports = { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,6 +49,19 @@ function onClientRequestStart({ request }) { | |||
| 49 | 49 | }); | |
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | + function onClientRequestError({ request, error }) { | ||
| 53 | + if (typeof request._inspectorRequestId !== 'string') { | ||
| 54 | + return; | ||
| 55 | + } | ||
| 56 | + const timestamp = DateNow() / 1000; | ||
| 57 | + Network.loadingFailed({ | ||
| 58 | + requestId: request._inspectorRequestId, | ||
| 59 | + timestamp, | ||
| 60 | + type: 'Other', | ||
| 61 | + errorText: error.message, | ||
| 62 | + }); | ||
| 63 | + } | ||
| 64 | + | ||
| 52 | 65 | function onClientResponseFinish({ request, response }) { | |
| 53 | 66 | if (typeof request._inspectorRequestId !== 'string') { | |
| 54 | 67 | return; | |
@@ -80,11 +93,13 @@ function enable() { | |||
| 80 | 93 | Network = require('inspector').Network; | |
| 81 | 94 | } | |
| 82 | 95 | dc.subscribe('http.client.request.start', onClientRequestStart); | |
| 96 | + dc.subscribe('http.client.request.error', onClientRequestError); | ||
| 83 | 97 | dc.subscribe('http.client.response.finish', onClientResponseFinish); | |
| 84 | 98 | } | |
| 85 | 99 | ||
| 86 | 100 | function disable() { | |
| 87 | 101 | dc.unsubscribe('http.client.request.start', onClientRequestStart); | |
| 102 | + dc.unsubscribe('http.client.request.error', onClientRequestError); | ||
| 88 | 103 | dc.unsubscribe('http.client.response.finish', onClientResponseFinish); | |
| 89 | 104 | } | |
| 90 | 105 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ NetworkAgent::NetworkAgent(NetworkInspector* inspector) | |||
| 33 | 33 | : inspector_(inspector) { | |
| 34 | 34 | event_notifier_map_["requestWillBeSent"] = &NetworkAgent::requestWillBeSent; | |
| 35 | 35 | event_notifier_map_["responseReceived"] = &NetworkAgent::responseReceived; | |
| 36 | + event_notifier_map_["loadingFailed"] = &NetworkAgent::loadingFailed; | ||
| 36 | 37 | event_notifier_map_["loadingFinished"] = &NetworkAgent::loadingFinished; | |
| 37 | 38 | } | |
| 38 | 39 | ||
@@ -117,6 +118,20 @@ void NetworkAgent::responseReceived( | |||
| 117 | 118 | createResponse(url, status, statusText, std::move(headers))); | |
| 118 | 119 | } | |
| 119 | 120 | ||
| 121 | + void NetworkAgent::loadingFailed( | ||
| 122 | + std::unique_ptr<protocol::DictionaryValue> params) { | ||
| 123 | + String request_id; | ||
| 124 | + params->getString("requestId", &request_id); | ||
| 125 | + double timestamp; | ||
| 126 | + params->getDouble("timestamp", ×tamp); | ||
| 127 | + String type; | ||
| 128 | + params->getString("type", &type); | ||
| 129 | + String error_text; | ||
| 130 | + params->getString("errorText", &error_text); | ||
| 131 | + | ||
| 132 | + frontend_->loadingFailed(request_id, timestamp, type, error_text); | ||
| 133 | + } | ||
| 134 | + | ||
| 120 | 135 | void NetworkAgent::loadingFinished( | |
| 121 | 136 | std::unique_ptr<protocol::DictionaryValue> params) { | |
| 122 | 137 | String request_id; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -29,6 +29,8 @@ class NetworkAgent : public Network::Backend { | |||
| 29 | 29 | ||
| 30 | 30 | void responseReceived(std::unique_ptr<protocol::DictionaryValue> params); | |
| 31 | 31 | ||
| 32 | + void loadingFailed(std::unique_ptr<protocol::DictionaryValue> params); | ||
| 33 | + | ||
| 32 | 34 | void loadingFinished(std::unique_ptr<protocol::DictionaryValue> params); | |
| 33 | 35 | ||
| 34 | 36 | private: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -180,6 +180,17 @@ experimental domain Network | |||
| 180 | 180 | # Response data. | |
| 181 | 181 | Response response | |
| 182 | 182 | ||
| 183 | + event loadingFailed | ||
| 184 | + parameters | ||
| 185 | + # Request identifier. | ||
| 186 | + RequestId requestId | ||
| 187 | + # Timestamp. | ||
| 188 | + MonotonicTime timestamp | ||
| 189 | + # Resource type. | ||
| 190 | + ResourceType type | ||
| 191 | + # Error message. | ||
| 192 | + string errorText | ||
| 193 | + | ||
| 183 | 194 | event loadingFinished | |
| 184 | 195 | parameters | |
| 185 | 196 | # Request identifier. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,15 @@ const EXPECTED_EVENTS = { | |||
| 62 | 62 | timestamp: 1000, | |
| 63 | 63 | } | |
| 64 | 64 | }, | |
| 65 | + { | ||
| 66 | + name: 'loadingFailed', | ||
| 67 | + params: { | ||
| 68 | + requestId: 'request-id-1', | ||
| 69 | + timestamp: 1000, | ||
| 70 | + type: 'Document', | ||
| 71 | + errorText: 'Failed to load resource' | ||
| 72 | + } | ||
| 73 | + }, | ||
| 65 | 74 | ] | |
| 66 | 75 | }; | |
| 67 | 76 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,6 +5,7 @@ const common = require('../common'); | |||
| 5 | 5 | common.skipIfInspectorDisabled(); | |
| 6 | 6 | ||
| 7 | 7 | const assert = require('node:assert'); | |
| 8 | + const { addresses } = require('../common/internet'); | ||
| 8 | 9 | const fixtures = require('../common/fixtures'); | |
| 9 | 10 | const http = require('node:http'); | |
| 10 | 11 | const https = require('node:https'); | |
@@ -144,11 +145,50 @@ const testHttpsGet = () => new Promise((resolve, reject) => { | |||
| 144 | 145 | }, common.mustCall()); | |
| 145 | 146 | }); | |
| 146 | 147 | ||
| 148 | + const testHttpError = () => new Promise((resolve, reject) => { | ||
| 149 | + session.on('Network.requestWillBeSent', common.mustCall()); | ||
| 150 | + session.on('Network.loadingFailed', common.mustCall(({ params }) => { | ||
| 151 | + assert.ok(params.requestId.startsWith('node-network-event-')); | ||
| 152 | + assert.strictEqual(typeof params.timestamp, 'number'); | ||
| 153 | + assert.strictEqual(params.type, 'Other'); | ||
| 154 | + assert.strictEqual(typeof params.errorText, 'string'); | ||
| 155 | + resolve(); | ||
| 156 | + })); | ||
| 157 | + session.on('Network.responseReceived', common.mustNotCall()); | ||
| 158 | + session.on('Network.loadingFinished', common.mustNotCall()); | ||
| 159 | + | ||
| 160 | + http.get({ | ||
| 161 | + host: addresses.INVALID_HOST, | ||
| 162 | + }, common.mustNotCall()).on('error', common.mustCall()); | ||
| 163 | + }); | ||
| 164 | + | ||
| 165 | + | ||
| 166 | + const testHttpsError = () => new Promise((resolve, reject) => { | ||
| 167 | + session.on('Network.requestWillBeSent', common.mustCall()); | ||
| 168 | + session.on('Network.loadingFailed', common.mustCall(({ params }) => { | ||
| 169 | + assert.ok(params.requestId.startsWith('node-network-event-')); | ||
| 170 | + assert.strictEqual(typeof params.timestamp, 'number'); | ||
| 171 | + assert.strictEqual(params.type, 'Other'); | ||
| 172 | + assert.strictEqual(typeof params.errorText, 'string'); | ||
| 173 | + resolve(); | ||
| 174 | + })); | ||
| 175 | + session.on('Network.responseReceived', common.mustNotCall()); | ||
| 176 | + session.on('Network.loadingFinished', common.mustNotCall()); | ||
| 177 | + | ||
| 178 | + https.get({ | ||
| 179 | + host: addresses.INVALID_HOST, | ||
| 180 | + }, common.mustNotCall()).on('error', common.mustCall()); | ||
| 181 | + }); | ||
| 182 | + | ||
| 147 | 183 | const testNetworkInspection = async () => { | |
| 148 | 184 | await testHttpGet(); | |
| 149 | 185 | session.removeAllListeners(); | |
| 150 | 186 | await testHttpsGet(); | |
| 151 | 187 | session.removeAllListeners(); | |
| 188 | + await testHttpError(); | ||
| 189 | + session.removeAllListeners(); | ||
| 190 | + await testHttpsError(); | ||
| 191 | + session.removeAllListeners(); | ||
| 152 | 192 | }; | |
| 153 | 193 | ||
| 154 | 194 | httpServer.listen(0, () => { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments