Dev: Network fetch

This commit is contained in:
surunzi
2018-01-03 20:12:56 +08:00
parent c6e979f052
commit 9babd8addf
5 changed files with 48 additions and 9 deletions

View File

@@ -16,6 +16,8 @@ export default class FetchRequest extends Emitter
{
super();
if (url instanceof window.Request) url = url.url;
this._url = fullUrl(url);
this._id = uniqId('request');
this._options = options;

View File

@@ -1,6 +1,7 @@
import Tool from '../DevTools/Tool';
import XhrRequest from './XhrRequest';
import FetchRequest from './FetchRequest';
import Settings from '../Settings/Settings';
import {evalCss, isNative, defaults, now, extend, isEmpty, $} from '../lib/util';
export default class Network extends Tool
@@ -23,8 +24,8 @@ export default class Network extends Tool
this._container = container;
this._bindEvent();
this._initCfg();
this.overrideXhr();
this.overrideFetch();
}
show()
{
@@ -32,6 +33,11 @@ export default class Network extends Tool
this._render();
}
clear()
{
this._requests = {};
this._render();
}
overrideXhr()
{
let winXhrProto = window.XMLHttpRequest.prototype;
@@ -162,11 +168,7 @@ export default class Network extends Tool
subType: data.subType,
resHeaders: data.resHeaders
});
}).on('click', '.eruda-clear-request', function ()
{
self._requests = {};
self._render();
});
}).on('click', '.eruda-clear-request', () => this.clear());
function showSources(type, data)
{
@@ -186,6 +188,27 @@ export default class Network extends Tool
this.restoreXhr();
this.restoreFetch();
}
_initCfg()
{
let cfg = this.config = Settings.createCfg('network', {
overrideFetch: true
});
if (cfg.get('overrideFetch')) this.overrideFetch();
cfg.on('change', (key, val) =>
{
switch (key)
{
case 'overrideFetch': return val ? this.overrideFetch() : this.restoreFetch();
}
});
let settings = this._container.get('settings');
settings.text('Network')
.switch(cfg, 'overrideFetch', 'Catch Fetch Requests')
.separator();
}
_render()
{
if (!this.active) return;