Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule NetworkOverlay
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2016-07-27 19:17:07 +00:00
|
|
|
const ListView = require('ListView');
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
const React = require('React');
|
2016-07-27 19:17:07 +00:00
|
|
|
const RecyclerViewBackedScrollView = require('RecyclerViewBackedScrollView');
|
2016-07-27 19:17:08 +00:00
|
|
|
const ScrollView = require('ScrollView');
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
2016-07-27 19:17:07 +00:00
|
|
|
const Text = require('Text');
|
|
|
|
const TouchableHighlight = require('TouchableHighlight');
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
const View = require('View');
|
2016-08-02 15:23:54 +00:00
|
|
|
const WebSocketInterceptor = require('WebSocketInterceptor');
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
const XHRInterceptor = require('XHRInterceptor');
|
|
|
|
|
2016-07-27 19:17:07 +00:00
|
|
|
const LISTVIEW_CELL_HEIGHT = 15;
|
|
|
|
const SEPARATOR_THICKNESS = 2;
|
|
|
|
|
2016-08-02 15:23:53 +00:00
|
|
|
// Global id for the intercepted XMLHttpRequest objects.
|
|
|
|
let nextXHRId = 0;
|
|
|
|
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
type NetworkRequestInfo = {
|
2016-08-02 15:23:54 +00:00
|
|
|
type?: string,
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
url?: string,
|
|
|
|
method?: string,
|
|
|
|
status?: number,
|
|
|
|
dataSent?: any,
|
|
|
|
responseContentType?: string,
|
|
|
|
responseSize?: number,
|
|
|
|
requestHeaders?: Object,
|
|
|
|
responseHeaders?: string,
|
|
|
|
response?: Object | string,
|
|
|
|
responseURL?: string,
|
|
|
|
responseType?: string,
|
|
|
|
timeout?: number,
|
2016-08-02 15:23:54 +00:00
|
|
|
closeReason?: string,
|
|
|
|
messages?: string,
|
|
|
|
serverClose?: Object,
|
|
|
|
serverError?: Object,
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show all the intercepted network requests over the InspectorPanel.
|
|
|
|
*/
|
|
|
|
class NetworkOverlay extends React.Component {
|
|
|
|
_requests: Array<NetworkRequestInfo>;
|
2016-07-27 19:17:07 +00:00
|
|
|
_listViewDataSource: ListView.DataSource;
|
|
|
|
_listView: ?ListView;
|
|
|
|
_listViewHighlighted: bool;
|
2016-07-27 19:17:08 +00:00
|
|
|
_listViewHeight: number;
|
|
|
|
_scrollView: ?ScrollView;
|
|
|
|
_detailViewItems: Array<Array<ReactElement<any>>>;
|
2016-07-27 19:17:07 +00:00
|
|
|
_listViewOnLayout: (event: Event) => void;
|
2016-07-27 19:17:08 +00:00
|
|
|
_captureRequestListView: (listRef: ?ListView) => void;
|
|
|
|
_captureDetailScrollView: (scrollRef: ?ScrollView) => void;
|
2016-07-27 19:17:07 +00:00
|
|
|
_renderRow: (
|
|
|
|
rowData: NetworkRequestInfo,
|
|
|
|
sectionID: number,
|
|
|
|
rowID: number,
|
|
|
|
highlightRow: (sectionID: number, rowID: number) => void,
|
|
|
|
) => ReactElement<any>;
|
|
|
|
_renderScrollComponent: (props: Object) => ReactElement<any>;
|
2016-07-27 19:17:08 +00:00
|
|
|
_closeButtonClicked: () => void;
|
2016-08-02 15:23:54 +00:00
|
|
|
// Map of `socketId` -> `index in `_requests``.
|
|
|
|
_socketIdMap: Object;
|
2016-08-02 15:23:53 +00:00
|
|
|
// Map of `xhr._index` -> `index in `_requests``.
|
|
|
|
_xhrIdMap: {[key: number]: number};
|
2016-07-27 19:17:07 +00:00
|
|
|
|
|
|
|
state: {
|
|
|
|
dataSource: ListView.DataSource,
|
2016-07-27 19:17:08 +00:00
|
|
|
newDetailInfo: bool,
|
|
|
|
detailRowID: ?number,
|
2016-07-27 19:17:07 +00:00
|
|
|
};
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
|
|
|
|
constructor(props: Object) {
|
|
|
|
super(props);
|
|
|
|
this._requests = [];
|
2016-07-27 19:17:08 +00:00
|
|
|
this._detailViewItems = [];
|
2016-07-27 19:17:07 +00:00
|
|
|
this._listViewDataSource =
|
|
|
|
new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
|
|
|
|
this.state = {
|
|
|
|
dataSource: this._listViewDataSource.cloneWithRows([]),
|
2016-07-27 19:17:08 +00:00
|
|
|
newDetailInfo: false,
|
|
|
|
detailRowID: null,
|
2016-07-27 19:17:07 +00:00
|
|
|
};
|
|
|
|
this._listViewHighlighted = false;
|
2016-07-27 19:17:08 +00:00
|
|
|
this._listViewHeight = 0;
|
|
|
|
this._captureRequestListView = this._captureRequestListView.bind(this);
|
|
|
|
this._captureDetailScrollView = this._captureDetailScrollView.bind(this);
|
2016-07-27 19:17:07 +00:00
|
|
|
this._listViewOnLayout = this._listViewOnLayout.bind(this);
|
|
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
|
this._renderScrollComponent = this._renderScrollComponent.bind(this);
|
2016-07-27 19:17:08 +00:00
|
|
|
this._closeButtonClicked = this._closeButtonClicked.bind(this);
|
2016-08-02 15:23:54 +00:00
|
|
|
this._socketIdMap = {};
|
2016-08-02 15:23:53 +00:00
|
|
|
this._xhrIdMap = {};
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
_enableXHRInterception(): void {
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
if (XHRInterceptor.isInterceptorEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:23:54 +00:00
|
|
|
// Show the XHR request item in listView as soon as it was opened.
|
|
|
|
XHRInterceptor.setOpenCallback((method, url, xhr) => {
|
2016-08-02 15:23:53 +00:00
|
|
|
// Generate a global id for each intercepted xhr object, add this id
|
|
|
|
// to the xhr object as a private `_index` property to identify it,
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
// so that we can distinguish different xhr objects in callbacks.
|
2016-08-02 15:23:53 +00:00
|
|
|
xhr._index = nextXHRId++;
|
|
|
|
const xhrIndex = this._requests.length;
|
|
|
|
this._xhrIdMap[xhr._index] = xhrIndex;
|
|
|
|
|
|
|
|
const _xhr: NetworkRequestInfo = {
|
2016-08-02 15:23:54 +00:00
|
|
|
'type': 'XMLHttpRequest',
|
2016-08-02 15:23:53 +00:00
|
|
|
'method': method,
|
|
|
|
'url': url
|
|
|
|
};
|
2016-07-27 19:17:08 +00:00
|
|
|
this._requests.push(_xhr);
|
|
|
|
this._detailViewItems.push([]);
|
2016-08-02 15:23:53 +00:00
|
|
|
this._genDetailViewItem(xhrIndex);
|
2016-07-27 19:17:07 +00:00
|
|
|
this.setState(
|
|
|
|
{dataSource: this._listViewDataSource.cloneWithRows(this._requests)},
|
|
|
|
this._scrollToBottom(),
|
|
|
|
);
|
2016-08-02 15:23:54 +00:00
|
|
|
});
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
XHRInterceptor.setRequestHeaderCallback((header, value, xhr) => {
|
2016-08-02 15:23:53 +00:00
|
|
|
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
|
|
|
|
if (xhrIndex === -1) {
|
2016-07-28 21:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:23:53 +00:00
|
|
|
const networkInfo = this._requests[xhrIndex];
|
2016-07-27 19:17:08 +00:00
|
|
|
if (!networkInfo.requestHeaders) {
|
|
|
|
networkInfo.requestHeaders = {};
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
}
|
2016-07-27 19:17:08 +00:00
|
|
|
networkInfo.requestHeaders[header] = value;
|
2016-08-02 15:23:53 +00:00
|
|
|
this._genDetailViewItem(xhrIndex);
|
2016-08-02 15:23:54 +00:00
|
|
|
});
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
XHRInterceptor.setSendCallback((data, xhr) => {
|
2016-08-02 15:23:53 +00:00
|
|
|
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
|
|
|
|
if (xhrIndex === -1) {
|
2016-07-28 21:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:23:53 +00:00
|
|
|
this._requests[xhrIndex].dataSent = data;
|
|
|
|
this._genDetailViewItem(xhrIndex);
|
2016-08-02 15:23:54 +00:00
|
|
|
});
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
|
|
|
|
XHRInterceptor.setHeaderReceivedCallback(
|
2016-08-02 15:23:54 +00:00
|
|
|
(type, size, responseHeaders, xhr) => {
|
2016-08-02 15:23:53 +00:00
|
|
|
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
|
|
|
|
if (xhrIndex === -1) {
|
2016-07-28 21:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:23:53 +00:00
|
|
|
const networkInfo = this._requests[xhrIndex];
|
2016-07-27 19:17:08 +00:00
|
|
|
networkInfo.responseContentType = type;
|
|
|
|
networkInfo.responseSize = size;
|
|
|
|
networkInfo.responseHeaders = responseHeaders;
|
2016-08-02 15:23:53 +00:00
|
|
|
this._genDetailViewItem(xhrIndex);
|
2016-08-02 15:23:54 +00:00
|
|
|
}
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
);
|
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
XHRInterceptor.setResponseCallback((
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
status,
|
|
|
|
timeout,
|
|
|
|
response,
|
|
|
|
responseURL,
|
|
|
|
responseType,
|
|
|
|
xhr,
|
2016-08-02 15:23:54 +00:00
|
|
|
) => {
|
2016-08-02 15:23:53 +00:00
|
|
|
const xhrIndex = this._getRequestIndexByXHRID(xhr._index);
|
|
|
|
if (xhrIndex === -1) {
|
2016-07-28 21:01:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-02 15:23:53 +00:00
|
|
|
const networkInfo = this._requests[xhrIndex];
|
2016-07-27 19:17:08 +00:00
|
|
|
networkInfo.status = status;
|
|
|
|
networkInfo.timeout = timeout;
|
|
|
|
networkInfo.response = response;
|
|
|
|
networkInfo.responseURL = responseURL;
|
|
|
|
networkInfo.responseType = responseType;
|
2016-08-02 15:23:53 +00:00
|
|
|
this._genDetailViewItem(xhrIndex);
|
2016-08-02 15:23:54 +00:00
|
|
|
}
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Fire above callbacks.
|
|
|
|
XHRInterceptor.enableInterception();
|
|
|
|
}
|
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
_enableWebSocketInterception(): void {
|
|
|
|
if (WebSocketInterceptor.isInterceptorEnabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Show the WebSocket request item in listView when 'connect' is called.
|
|
|
|
WebSocketInterceptor.setConnectCallback(
|
|
|
|
(url, protocols, options, socketId) => {
|
|
|
|
const socketIndex = this._requests.length;
|
|
|
|
this._socketIdMap[socketId] = socketIndex;
|
|
|
|
const _webSocket: NetworkRequestInfo = {
|
|
|
|
'type': 'WebSocket',
|
|
|
|
'url': url,
|
|
|
|
'protocols': protocols,
|
|
|
|
};
|
|
|
|
this._requests.push(_webSocket);
|
|
|
|
this._detailViewItems.push([]);
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
this.setState(
|
|
|
|
{dataSource: this._listViewDataSource.cloneWithRows(this._requests)},
|
|
|
|
this._scrollToBottom(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
WebSocketInterceptor.setCloseCallback(
|
|
|
|
(statusCode, closeReason, socketId) => {
|
|
|
|
const socketIndex = this._socketIdMap[socketId];
|
|
|
|
if (socketIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (statusCode !== null && closeReason !== null) {
|
|
|
|
this._requests[socketIndex].status = statusCode;
|
|
|
|
this._requests[socketIndex].closeReason = closeReason;
|
|
|
|
}
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
WebSocketInterceptor.setSendCallback((data, socketId) => {
|
|
|
|
const socketIndex = this._socketIdMap[socketId];
|
|
|
|
if (socketIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this._requests[socketIndex].messages) {
|
|
|
|
this._requests[socketIndex].messages = '';
|
|
|
|
}
|
|
|
|
this._requests[socketIndex].messages +=
|
|
|
|
'Sent: ' + JSON.stringify(data) + '\n';
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
WebSocketInterceptor.setOnMessageCallback((socketId, message) => {
|
|
|
|
const socketIndex = this._socketIdMap[socketId];
|
|
|
|
if (socketIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!this._requests[socketIndex].messages) {
|
|
|
|
this._requests[socketIndex].messages = '';
|
|
|
|
}
|
|
|
|
this._requests[socketIndex].messages +=
|
|
|
|
'Received: ' + JSON.stringify(message) + '\n';
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
WebSocketInterceptor.setOnCloseCallback((socketId, message) => {
|
|
|
|
const socketIndex = this._socketIdMap[socketId];
|
|
|
|
if (socketIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._requests[socketIndex].serverClose = message;
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
WebSocketInterceptor.setOnErrorCallback((socketId, message) => {
|
|
|
|
const socketIndex = this._socketIdMap[socketId];
|
|
|
|
if (socketIndex === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this._requests[socketIndex].serverError = message;
|
|
|
|
this._genDetailViewItem(socketIndex);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Fire above callbacks.
|
|
|
|
WebSocketInterceptor.enableInterception();
|
|
|
|
}
|
|
|
|
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
componentDidMount() {
|
2016-08-02 15:23:54 +00:00
|
|
|
this._enableXHRInterception();
|
|
|
|
this._enableWebSocketInterception();
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
XHRInterceptor.disableInterception();
|
2016-08-02 15:23:54 +00:00
|
|
|
WebSocketInterceptor.disableInterception();
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
}
|
|
|
|
|
2016-07-27 19:17:07 +00:00
|
|
|
_renderRow(
|
|
|
|
rowData: NetworkRequestInfo,
|
|
|
|
sectionID: number,
|
|
|
|
rowID: number,
|
|
|
|
highlightRow: (sectionID: number, rowID: number) => void,
|
|
|
|
): ReactElement<any> {
|
|
|
|
let urlCellViewStyle = styles.urlEvenCellView;
|
|
|
|
let methodCellViewStyle = styles.methodEvenCellView;
|
|
|
|
if (rowID % 2 === 1) {
|
|
|
|
urlCellViewStyle = styles.urlOddCellView;
|
|
|
|
methodCellViewStyle = styles.methodOddCellView;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<TouchableHighlight onPress={() => {
|
|
|
|
this._pressRow(rowID);
|
|
|
|
highlightRow(sectionID, rowID);
|
|
|
|
}}>
|
|
|
|
<View>
|
|
|
|
<View style={styles.tableRow}>
|
|
|
|
<View style={urlCellViewStyle}>
|
|
|
|
<Text style={styles.cellText} numberOfLines={1}>
|
|
|
|
{rowData.url}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
<View style={methodCellViewStyle}>
|
|
|
|
<Text style={styles.cellText} numberOfLines={1}>
|
2016-08-02 15:23:54 +00:00
|
|
|
{this._getTypeShortName(rowData.type)}
|
2016-07-27 19:17:07 +00:00
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderSeperator(
|
|
|
|
sectionID: number,
|
|
|
|
rowID: number,
|
|
|
|
adjacentRowHighlighted: bool): ReactElement<any> {
|
|
|
|
return (
|
|
|
|
<View
|
|
|
|
key={`${sectionID}-${rowID}`}
|
|
|
|
style={{
|
|
|
|
height: adjacentRowHighlighted ? SEPARATOR_THICKNESS : 0,
|
|
|
|
backgroundColor: adjacentRowHighlighted ? '#3B5998' : '#CCCCCC',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_scrollToBottom(): void {
|
2016-07-27 19:17:08 +00:00
|
|
|
if (this._listView) {
|
2016-07-27 19:17:07 +00:00
|
|
|
const scrollResponder = this._listView.getScrollResponder();
|
|
|
|
if (scrollResponder) {
|
|
|
|
const scrollY = Math.max(
|
|
|
|
this._requests.length * LISTVIEW_CELL_HEIGHT +
|
|
|
|
(this._listViewHighlighted ? 2 * SEPARATOR_THICKNESS : 0) -
|
|
|
|
this._listViewHeight,
|
|
|
|
0,
|
|
|
|
);
|
|
|
|
scrollResponder.scrollResponderScrollTo({
|
|
|
|
x: 0,
|
|
|
|
y: scrollY,
|
|
|
|
animated: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:17:08 +00:00
|
|
|
_captureRequestListView(listRef: ?ListView): void {
|
2016-07-27 19:17:07 +00:00
|
|
|
this._listView = listRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
_listViewOnLayout(event: any): void {
|
|
|
|
const {height} = event.nativeEvent.layout;
|
|
|
|
this._listViewHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
_renderScrollComponent(props: Object): ReactElement<any> {
|
|
|
|
return (
|
|
|
|
<RecyclerViewBackedScrollView {...props} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-07-27 19:17:08 +00:00
|
|
|
* Popup a scrollView to dynamically show detailed information of
|
|
|
|
* the request, when pressing a row in the network flow listView.
|
2016-07-27 19:17:07 +00:00
|
|
|
*/
|
|
|
|
_pressRow(rowID: number): void {
|
|
|
|
this._listViewHighlighted = true;
|
2016-07-27 19:17:08 +00:00
|
|
|
this.setState(
|
|
|
|
{detailRowID: rowID},
|
|
|
|
this._scrollToTop(),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
_scrollToTop(): void {
|
|
|
|
if (this._scrollView) {
|
|
|
|
this._scrollView.scrollTo({
|
|
|
|
y: 0,
|
|
|
|
animated: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_captureDetailScrollView(scrollRef: ?ScrollView): void {
|
|
|
|
this._scrollView = scrollRef;
|
|
|
|
}
|
|
|
|
|
|
|
|
_closeButtonClicked() {
|
|
|
|
this.setState({detailRowID: null});
|
|
|
|
}
|
|
|
|
|
|
|
|
_getStringByValue(value: any): string {
|
|
|
|
if (value === undefined) {
|
|
|
|
return 'undefined';
|
|
|
|
}
|
|
|
|
if (typeof value === 'object') {
|
|
|
|
return JSON.stringify(value);
|
|
|
|
}
|
|
|
|
if (typeof value === 'string' && value.length > 500) {
|
2016-08-02 15:23:53 +00:00
|
|
|
return String(value).substr(0, 500).concat(
|
|
|
|
'\n***TRUNCATED TO 500 CHARACTERS***');
|
2016-07-27 19:17:08 +00:00
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2016-08-02 15:23:53 +00:00
|
|
|
_getRequestIndexByXHRID(index: number): number {
|
|
|
|
if (index === undefined) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
const xhrIndex = this._xhrIdMap[index];
|
|
|
|
if (xhrIndex === undefined) {
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
return xhrIndex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 15:23:54 +00:00
|
|
|
_getTypeShortName(type: any): string {
|
|
|
|
if (type === 'XMLHttpRequest') {
|
|
|
|
return 'XHR';
|
|
|
|
} else if (type === 'WebSocket') {
|
|
|
|
return 'WS';
|
|
|
|
}
|
|
|
|
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2016-07-27 19:17:08 +00:00
|
|
|
/**
|
|
|
|
* Generate a list of views containing network request information for
|
|
|
|
* a XHR object, to be shown in the detail scrollview. This function
|
|
|
|
* should be called every time there is a new update of the XHR object,
|
|
|
|
* in order to show network request/response information in real time.
|
|
|
|
*/
|
|
|
|
_genDetailViewItem(index: number): void {
|
|
|
|
this._detailViewItems[index] = [];
|
|
|
|
const detailViewItem = this._detailViewItems[index];
|
|
|
|
const requestItem = this._requests[index];
|
|
|
|
for (let key in requestItem) {
|
|
|
|
detailViewItem.push(
|
|
|
|
<View style={styles.detailViewRow} key={key}>
|
|
|
|
<Text style={[styles.detailViewText, styles.detailKeyCellView]}>
|
|
|
|
{key}
|
|
|
|
</Text>
|
|
|
|
<Text style={[styles.detailViewText, styles.detailValueCellView]}>
|
|
|
|
{this._getStringByValue(requestItem[key])}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
// Re-render if this network request is showing in the detail view.
|
2016-08-02 15:23:54 +00:00
|
|
|
if (this.state.detailRowID != null &&
|
|
|
|
Number(this.state.detailRowID) === index) {
|
2016-07-27 19:17:08 +00:00
|
|
|
this.setState({newDetailInfo: true});
|
|
|
|
}
|
2016-07-27 19:17:07 +00:00
|
|
|
}
|
|
|
|
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View style={styles.container}>
|
2016-07-27 19:17:08 +00:00
|
|
|
{this.state.detailRowID != null &&
|
|
|
|
<TouchableHighlight
|
|
|
|
style={styles.closeButton}
|
|
|
|
onPress={this._closeButtonClicked}>
|
|
|
|
<View>
|
|
|
|
<Text style={styles.clostButtonText}>v</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>}
|
|
|
|
{this.state.detailRowID != null &&
|
|
|
|
<ScrollView
|
|
|
|
style={styles.detailScrollView}
|
|
|
|
ref={this._captureDetailScrollView}>
|
|
|
|
{this._detailViewItems[this.state.detailRowID]}
|
|
|
|
</ScrollView>}
|
|
|
|
<View style={styles.listViewTitle}>
|
|
|
|
{this._requests.length > 0 &&
|
2016-07-27 19:17:07 +00:00
|
|
|
<View style={styles.tableRow}>
|
|
|
|
<View style={styles.urlTitleCellView}>
|
|
|
|
<Text style={styles.cellText} numberOfLines={1}>URL</Text>
|
|
|
|
</View>
|
|
|
|
<View style={styles.methodTitleCellView}>
|
2016-08-02 15:23:54 +00:00
|
|
|
<Text style={styles.cellText} numberOfLines={1}>Type</Text>
|
2016-07-27 19:17:07 +00:00
|
|
|
</View>
|
2016-07-27 19:17:08 +00:00
|
|
|
</View>}
|
|
|
|
</View>
|
2016-07-27 19:17:07 +00:00
|
|
|
<ListView
|
|
|
|
style={styles.listView}
|
2016-07-27 19:17:08 +00:00
|
|
|
ref={this._captureRequestListView}
|
2016-07-27 19:17:07 +00:00
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={this._renderRow}
|
|
|
|
renderScrollComponent={this._renderScrollComponent}
|
|
|
|
enableEmptySections={true}
|
|
|
|
renderSeparator={this._renderSeperator}
|
|
|
|
onLayout={this._listViewOnLayout}
|
|
|
|
/>
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
paddingTop: 10,
|
|
|
|
paddingBottom: 10,
|
|
|
|
paddingLeft: 5,
|
|
|
|
paddingRight: 5,
|
|
|
|
},
|
2016-07-27 19:17:08 +00:00
|
|
|
listViewTitle: {
|
|
|
|
height: 20,
|
|
|
|
},
|
2016-07-27 19:17:07 +00:00
|
|
|
listView: {
|
|
|
|
flex: 1,
|
2016-07-27 19:17:08 +00:00
|
|
|
height: 60,
|
2016-07-27 19:17:07 +00:00
|
|
|
},
|
|
|
|
tableRow: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
cellText: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 12,
|
|
|
|
},
|
|
|
|
methodTitleCellView: {
|
|
|
|
height: 18,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderTopWidth: 1,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderRightWidth: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#444',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
urlTitleCellView: {
|
|
|
|
height: 18,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderTopWidth: 1,
|
|
|
|
borderBottomWidth: 1,
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
borderRightWidth: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#444',
|
|
|
|
flex: 5,
|
|
|
|
paddingLeft: 3,
|
|
|
|
},
|
|
|
|
methodOddCellView: {
|
|
|
|
height: 15,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderRightWidth: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#000',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
urlOddCellView: {
|
|
|
|
height: 15,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
borderRightWidth: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#000',
|
|
|
|
flex: 5,
|
|
|
|
paddingLeft: 3,
|
|
|
|
},
|
|
|
|
methodEvenCellView: {
|
|
|
|
height: 15,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderRightWidth: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#888',
|
|
|
|
flex: 1,
|
|
|
|
},
|
|
|
|
urlEvenCellView: {
|
|
|
|
height: 15,
|
|
|
|
borderColor: '#DCD7CD',
|
|
|
|
borderLeftWidth: 1,
|
|
|
|
borderRightWidth: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
backgroundColor: '#888',
|
|
|
|
flex: 5,
|
|
|
|
paddingLeft: 3,
|
|
|
|
},
|
2016-07-27 19:17:08 +00:00
|
|
|
detailScrollView: {
|
|
|
|
flex: 1,
|
|
|
|
height: 180,
|
|
|
|
marginTop: 5,
|
|
|
|
marginBottom: 5,
|
|
|
|
},
|
|
|
|
detailKeyCellView: {
|
|
|
|
flex: 1.3,
|
|
|
|
},
|
|
|
|
detailValueCellView: {
|
|
|
|
flex: 2,
|
|
|
|
},
|
|
|
|
detailViewRow: {
|
|
|
|
flexDirection: 'row',
|
|
|
|
paddingHorizontal: 3,
|
|
|
|
},
|
|
|
|
detailViewText: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 11,
|
|
|
|
},
|
|
|
|
clostButtonText: {
|
|
|
|
color: 'white',
|
|
|
|
fontSize: 10,
|
|
|
|
},
|
|
|
|
closeButton: {
|
2016-08-02 15:23:54 +00:00
|
|
|
marginTop: 5,
|
2016-07-27 19:17:08 +00:00
|
|
|
backgroundColor: '#888',
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
},
|
Intercept XMLHttpRequest network operations and gather their information in inspector tool
Summary:
This diff
- creates `XHRInterceptor` to intercept all XMLHttpRequest network operations in React Native by monkey-patching.
- enables `XHRInterceptor` in RN development tool "inspector".
This interception and inspector tool work well on both Android and iOS. And this supports interception on any network API based on XMLHttpRequest, especially the Fetch API.
By now, we can intercept 12 information fields of a XMLHttpRequest including method, url, data sent, status, response type, response size, requestHeaders, responseHeaders, response, responseURL, responseType and timeout.
Follow-up:
- Will add UIs in the inspector on top of this diff, to display all the network operation information. (Not in this diff just to make this shorter)
- Will extend this to gather other valuable information towards one XMLHttpRequest.
- Should support other network request APIs like WebSocket.
Reviewed By: davidaurelio
Differential Revision: D3598873
fbshipit-source-id: 3221050ab2ebd876a718fc326646c344d0944a5f
2016-07-27 19:17:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = NetworkOverlay;
|