Skip to content

Commit b5abb87

Browse files
Siqi LiuFacebook Github Bot 2
authored andcommitted
Fix the potential bug for network inspector when receiving xhr objects without an "_index" property
Summary: It sometimes happens that there are already some existing `XMLHttpRequest` objects before we turn on the network inspector. So it is a must to check whether a `XMLHttpRequest` object has a property `_index` to determine if it should be tracked. Reviewed By: davidaurelio Differential Revision: D3635184 fbshipit-source-id: a5552d7244c994b0fe782ac35baae39ec7488494
1 parent fd48bc3 commit b5abb87

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

Libraries/Inspector/NetworkOverlay.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class NetworkOverlay extends React.Component {
109109
}.bind(this));
110110

111111
XHRInterceptor.setRequestHeaderCallback(function(header, value, xhr) {
112+
if (xhr._index === undefined) {
113+
return;
114+
}
112115
const networkInfo = this._requests[xhr._index];
113116
if (!networkInfo.requestHeaders) {
114117
networkInfo.requestHeaders = {};
@@ -118,12 +121,18 @@ class NetworkOverlay extends React.Component {
118121
}.bind(this));
119122

120123
XHRInterceptor.setSendCallback(function(data, xhr) {
124+
if (xhr._index === undefined) {
125+
return;
126+
}
121127
this._requests[xhr._index].dataSent = data;
122128
this._genDetailViewItem(xhr._index);
123129
}.bind(this));
124130

125131
XHRInterceptor.setHeaderReceivedCallback(
126132
function(type, size, responseHeaders, xhr) {
133+
if (xhr._index === undefined) {
134+
return;
135+
}
127136
const networkInfo = this._requests[xhr._index];
128137
networkInfo.responseContentType = type;
129138
networkInfo.responseSize = size;
@@ -141,6 +150,9 @@ class NetworkOverlay extends React.Component {
141150
responseType,
142151
xhr,
143152
) {
153+
if (xhr._index === undefined) {
154+
return;
155+
}
144156
const networkInfo = this._requests[xhr._index];
145157
networkInfo.status = status;
146158
networkInfo.timeout = timeout;

Libraries/Utilities/XHRInterceptor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const XHRInterceptor = {
8282
};
8383

8484
// Override `setRequestHeader` method for all XHR requests to intercept
85-
// the request headers, then pass them through the `openCallback`.
85+
// the request headers, then pass them through the `requestHeaderCallback`.
8686
XMLHttpRequest.prototype.setRequestHeader = function(header, value) {
8787
requestHeaderCallback(header, value, this);
8888
originalXHRSetRequestHeader.apply(this, arguments);

0 commit comments

Comments
 (0)