Support loading source maps

Reviewed By: davidaurelio

Differential Revision: D4121492

fbshipit-source-id: e2f9c42de3e28cd231580d8b7d3230d47e300d2e
This commit is contained in:
Alexander Blom 2016-11-15 08:55:41 -08:00 committed by Facebook Github Bot
parent f571d28e68
commit 2cc57d05a4

View File

@ -131,6 +131,13 @@ class Device {
return;
}
// TODO: This should be handled way earlier, preferably in the inspector itself.
// That is how it works it newer versions but it requires installing hooks.
if (message.indexOf('Network.loadResourceForFrontend') !== -1) {
this._loadResourceForFrontend(socket, JSON.parse(message));
return;
}
this._send({
event: 'wrappedEvent',
payload: {
@ -224,6 +231,36 @@ class Device {
this._removeConnection(pageId);
}
}
_loadResourceForFrontend(socket: WebSocket, event: Object) {
const id: number = nullthrows(event.id);
const url: string = nullthrows(nullthrows(event.params).url);
debug('loadResourceForFrontend:', url);
http.get(this._normalizeUrl(url), (response) => {
// $FlowFixMe callback is optional
response.setTimeout(0);
let data = '';
response.on('data', (chunk) => { data += chunk; });
response.on('end', () => {
socket.send(JSON.stringify({
id: id,
result: {
statusCode: response.statusCode,
content: data,
responseHeaders: response.headers,
},
}));
});
response.on('error', (error) => {
console.error('Failed to get resource', error);
});
});
}
_normalizeUrl(url: string): string {
return url.replace('http://10.0.3.2', 'http://localhost')
.replace('http://10.0.2.2', 'http://localhost');
}
}
class InspectorProxy {