UNPKG

6.75 kBJavaScriptView Raw
1var NetworkDomainDebugger_1;
2const inspectorCommands = require('./InspectorBackendCommands');
3import * as debuggerDomains from '.';
4const frameId = 'NativeScriptMainFrameIdentifier';
5const loaderId = 'Loader Identifier';
6const resources_datas = [];
7const documentTypeByMimeType = {
8 'text/xml': 'Document',
9 'text/plain': 'Document',
10 'text/html': 'Document',
11 'application/xml': 'Document',
12 'application/xhtml+xml': 'Document',
13 'text/css': 'Stylesheet',
14 'text/javascript': 'Script',
15 'text/ecmascript': 'Script',
16 'application/javascript': 'Script',
17 'application/ecmascript': 'Script',
18 'application/x-javascript': 'Script',
19 'application/json': 'Script',
20 'application/x-json': 'Script',
21 'text/x-javascript': 'Script',
22 'text/x-json': 'Script',
23 'text/typescript': 'Script',
24};
25export class Request {
26 constructor(_networkDomainDebugger, _requestID) {
27 this._networkDomainDebugger = _networkDomainDebugger;
28 this._requestID = _requestID;
29 }
30 get mimeType() {
31 return this._mimeType;
32 }
33 set mimeType(value) {
34 if (this._mimeType !== value) {
35 if (!value) {
36 this._mimeType = 'text/plain';
37 this._resourceType = 'Other';
38 return;
39 }
40 this._mimeType = value;
41 let resourceType = 'Other';
42 if (this._mimeType in documentTypeByMimeType) {
43 resourceType = documentTypeByMimeType[this._mimeType];
44 }
45 if (this._mimeType.indexOf('image/') !== -1) {
46 resourceType = 'Image';
47 }
48 if (this._mimeType.indexOf('font/') !== -1) {
49 resourceType = 'Font';
50 }
51 this._resourceType = resourceType;
52 }
53 }
54 get requestID() {
55 return this._requestID;
56 }
57 get hasTextContent() {
58 return ['Document', 'Stylesheet', 'Script', 'XHR'].indexOf(this._resourceType) !== -1;
59 }
60 get data() {
61 return this._data;
62 }
63 set data(value) {
64 if (this._data !== value) {
65 this._data = value;
66 }
67 }
68 get resourceType() {
69 return this._resourceType;
70 }
71 set resourceType(value) {
72 if (this._resourceType !== value) {
73 this._resourceType = value;
74 }
75 }
76 responseReceived(response) {
77 if (this._networkDomainDebugger.enabled) {
78 this._networkDomainDebugger.events.responseReceived(this.requestID, frameId, loaderId, __inspectorTimestamp(), this.resourceType, response);
79 }
80 }
81 loadingFinished() {
82 if (this._networkDomainDebugger.enabled) {
83 this._networkDomainDebugger.events.loadingFinished(this.requestID, __inspectorTimestamp());
84 }
85 }
86 requestWillBeSent(request) {
87 if (this._networkDomainDebugger.enabled) {
88 this._networkDomainDebugger.events.requestWillBeSent(this.requestID, frameId, loaderId, request.url, request, __inspectorTimestamp(), { type: 'Script' });
89 }
90 }
91}
92let NetworkDomainDebugger = NetworkDomainDebugger_1 = class NetworkDomainDebugger {
93 constructor() {
94 this.events = new inspectorCommands.NetworkDomain.NetworkFrontend();
95 // By default start enabled because we can miss the "enable" event when
96 // running with `--debug-brk` -- the frontend will send it before we've been created
97 this.enable();
98 }
99 get enabled() {
100 return this._enabled;
101 }
102 /**
103 * Enables network tracking, network events will now be delivered to the client.
104 */
105 enable() {
106 if (debuggerDomains.getNetwork()) {
107 throw new Error('One NetworkDomainDebugger may be enabled at a time.');
108 }
109 else {
110 debuggerDomains.setNetwork(this);
111 }
112 this._enabled = true;
113 }
114 /**
115 * Disables network tracking, prevents network events from being sent to the client.
116 */
117 disable() {
118 if (debuggerDomains.getNetwork() === this) {
119 debuggerDomains.setNetwork(null);
120 }
121 this._enabled = false;
122 }
123 /**
124 * Specifies whether to always send extra HTTP headers with the requests from this page.
125 */
126 setExtraHTTPHeaders(params) {
127 //
128 }
129 /**
130 * Returns content served for the given request.
131 */
132 getResponseBody(params) {
133 const resource_data = resources_datas[params.requestId];
134 const body = resource_data.hasTextContent ? NSString.alloc().initWithDataEncoding(resource_data.data, 4).toString() : resource_data.data.base64EncodedStringWithOptions(0);
135 if (resource_data) {
136 return {
137 body: body,
138 base64Encoded: !resource_data.hasTextContent,
139 };
140 }
141 }
142 /**
143 * Tells whether clearing browser cache is supported.
144 */
145 canClearBrowserCache() {
146 return {
147 result: false,
148 };
149 }
150 /**
151 * Clears browser cache.
152 */
153 clearBrowserCache() {
154 //
155 }
156 /**
157 * Tells whether clearing browser cookies is supported.
158 */
159 canClearBrowserCookies() {
160 return {
161 result: false,
162 };
163 }
164 /**
165 * Clears browser cookies.
166 */
167 clearBrowserCookies() {
168 //
169 }
170 /**
171 * Toggles ignoring cache for each request. If <code>true</code>, cache will not be used.
172 */
173 setCacheDisabled(params) {
174 //
175 }
176 /**
177 * Loads a resource in the context of a frame on the inspected page without cross origin checks.
178 */
179 loadResource(params) {
180 const appPath = NSBundle.mainBundle.bundlePath;
181 const pathUrl = params.url.replace('file://', appPath);
182 const fileManager = NSFileManager.defaultManager;
183 const data = fileManager.fileExistsAtPath(pathUrl) ? fileManager.contentsAtPath(pathUrl) : undefined;
184 const content = data ? NSString.alloc().initWithDataEncoding(data, NSUTF8StringEncoding) : '';
185 return {
186 content: content.toString(), // Not sure why however we need to call toString() for NSString
187 mimeType: 'application/octet-stream',
188 status: 200,
189 };
190 }
191 create() {
192 const id = (++NetworkDomainDebugger_1.idSequence).toString();
193 const resourceData = new Request(this, id);
194 resources_datas[id] = resourceData;
195 return resourceData;
196 }
197};
198NetworkDomainDebugger.idSequence = 0;
199NetworkDomainDebugger = NetworkDomainDebugger_1 = __decorate([
200 inspectorCommands.DomainDispatcher('Network'),
201 __metadata("design:paramtypes", [])
202], NetworkDomainDebugger);
203export { NetworkDomainDebugger };
204//# sourceMappingURL=webinspector-network.ios.js.map
\No newline at end of file