Skip to content

Commit 1dcdc22

Browse files
authored
Merge pull request #524 from Tencent/dev
v3.14.4
2 parents 5bea445 + c6f908c commit 1dcdc22

File tree

14 files changed

+128
-91
lines changed

14 files changed

+128
-91
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
English | [简体中文](./CHANGELOG_CN.md)
22

3+
## 3.14.4 (2022-03-31)
4+
5+
- `Fix(Network)` Fix CPU high load bug when response is a large string. (issue #515)
6+
- `Fix(Network)` Fix missing Request Headers issue in XHR. (issue #522)
7+
8+
9+
## 3.14.3 (2022-03-28)
10+
11+
- `Fix(Network)` Fix `response.size` error.
12+
13+
314
## 3.14.2 (2022-03-25)
415

516
- `Fix(Network)` Remove debugging console.log.

CHANGELOG_CN.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
[English](./CHANGELOG.md) | 简体中文
22

3+
## 3.14.4 (2022-03-31)
4+
5+
- `Fix(Network)` 修复回包超大时导致的卡死问题。 (issue #515)
6+
- `Fix(Network)` 修复 XHR 中缺失显示 Request Headers 的问题。 (issue #522)
7+
8+
9+
## 3.14.3 (2022-03-28)
10+
11+
- `Fix(Network)` 修复 `response.size` 错误。
12+
13+
314
## 3.14.2 (2022-03-25)
415

516
- `Fix(Network)` 删除调试日志。

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ See [Tutorial](./doc/tutorial.md) for more usage details.
3838

3939
For installation, there are 2 primary ways of adding vConsole to a project:
4040

41-
#### Method 1: Using npm (Suggested)
41+
#### Method 1: Using npm (Recommended)
4242

4343
```bash
4444
$ npm install vconsole

dev/data/massive.json

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

dev/log.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<a onclick="allDataTypes()" href="javascript:;" class="weui_btn weui_btn_default">All Data Types</a>
3030
<a onclick="logTypes()" href="javascript:;" class="weui_btn weui_btn_default">Log/Info/Debug/Warn/Error</a>
3131
<a onclick="differentPanelLog()" href="javascript:;" class="weui_btn weui_btn_default">Output to Different Panels</a>
32+
<a onclick="logTime()" href="javascript:;" class="weui_btn weui_btn_default">console.time</a>
3233
</div>
3334

3435
<div class="section">
@@ -126,6 +127,16 @@
126127
console.log('[foobar]', 'This log should be shown in Log panel. (No "foobar" plugin.)');
127128
}
128129

130+
function logTime() {
131+
vConsole.show();
132+
const label = 'aaa';
133+
console.time(label);
134+
console.log('Wait...');
135+
setTimeout(() => {
136+
console.timeEnd(label);
137+
}, Math.ceil(Math.random() * 2000));
138+
}
139+
129140
function formattingLog() {
130141
console.log('%c red,%c blue, %c bold.', 'color:red', 'color:blue', 'font-weight:bold', '(Use %c format)');
131142
console.log('%c %c Continuous styling, only blue is applied.', 'color:red', 'color:blue', '(Use %c format)');

dev/network.html

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
<a onclick="getAjax()" href="javascript:;" class="weui_btn weui_btn_default">GET XHR</a>
1919
<a onclick="postAjax()" href="javascript:;" class="weui_btn weui_btn_default">POST XHR (Data: Object)</a>
2020
<a onclick="postAjax('json')" href="javascript:;" class="weui_btn weui_btn_default">POST XHR (Data: JSON String)</a>
21+
<a onclick="postAjax('', 'massive.json')" href="javascript:;" class="weui_btn weui_btn_default">POST XHR (Massive Resp)</a>
2122
<a onclick="optionsXHR()" href="javascript:;" class="weui_btn weui_btn_default">OPTIONS XHR</a>
22-
<a onclick="xhrStream()" href="javascript:;" class="weui_btn weui_btn_default">XHR Stream</a>
23+
<a onclick="xhrStream('flv')" href="javascript:;" class="weui_btn weui_btn_default">XHR Chunked: flv</a>
24+
<a onclick="xhrStream('json')" href="javascript:;" class="weui_btn weui_btn_default">XHR Chunked: json</a>
2325
</div>
2426

2527
<div class="section">
@@ -42,6 +44,7 @@
4244

4345
<a onclick="sendBeacon()" href="javascript:;" class="weui_btn weui_btn_default">sendBeacon</a>
4446
<a onclick="axiosRequest('GET')" href="javascript:;" class="weui_btn weui_btn_default">Axios: GET</a>
47+
<a onclick="axiosRequest('POST')" href="javascript:;" class="weui_btn weui_btn_default">Axios: POST</a>
4548
<a onclick="scrolling()" href="javascript:;" class="weui_btn weui_btn_default">Scrolling</a>
4649
<a onclick="crossDomain()" href="javascript:;" class="weui_btn weui_btn_default">Cross Domain</a>
4750
</div>
@@ -70,14 +73,11 @@
7073

7174
<script>
7275
const vConsole = new window.VConsole({
73-
maxLogNumber: 1000,
74-
// defaultPlugins: ['system', 'network'],
76+
// defaultPlugins: ['system'],
7577
// disableLogScrolling: true,
7678
onReady: function() {
7779
console.log('vConsole is ready.');
78-
setTimeout(() => {
79-
vConsole.showPlugin('network');
80-
}, 100);
80+
vConsole.showPlugin('network');
8181
}
8282
});
8383

@@ -90,7 +90,8 @@
9090
vConsole.show();
9191
}
9292

93-
function postAjax(postType) {
93+
function postAjax(postType, file = 'large.json') {
94+
showPanel();
9495
const xhr = new XMLHttpRequest();
9596
xhr.onload = () => {
9697
console.log('post XHR Response:', JSON.parse(xhr.response));
@@ -113,7 +114,7 @@
113114
postData = JSON.stringify(postData);
114115
}
115116
console.log('post data:', postData);
116-
xhr.open('POST', './data/large.json?method=fetchPost&c=中文');
117+
xhr.open('POST', `./data/${file}?method=fetchPost&c=中文`);
117118
xhr.send(postData);
118119
// xhr.send(JSON.stringify({foo: 'bar', id: Math.random(), '<xss0>': '<xss1> XSS Attack!'}));
119120
}
@@ -133,7 +134,7 @@
133134
}
134135

135136
function getFetch() {
136-
vConsole.show();
137+
showPanel();
137138
window.fetch('./data/success.json?method=fetchGet&id=' + Math.random(), {
138139
method: 'GET',
139140
headers: {
@@ -296,9 +297,9 @@
296297
});
297298
}
298299

299-
function xhrStream() {
300+
function xhrStream(format = 'flv') {
300301
vConsole.show();
301-
const url = './data/stream.flv?id=' + Math.random();
302+
const url = `./data/success.${format}?chunked=1&id=` + Math.random();
302303
const xhr = new XMLHttpRequest();
303304
xhr.timeout = 11000;
304305
console.log('xhr type:', typeof xhr, xhr instanceof XMLHttpRequest);
@@ -357,26 +358,7 @@
357358
}
358359

359360
function axiosRequest(method) {
360-
console.info('axiosRequest() Start');
361-
axios({
362-
method,
363-
url: './data/success.json?method=axios&r=' + Math.random(),
364-
headers: { 'content-type': 'application/x-www-form-urlencoded' },
365-
data: {
366-
foo: 'bar'
367-
}
368-
})
369-
.then(function(response) {
370-
console.log('axiosRequest response:', response);
371-
})
372-
.catch(function(error) {
373-
console.log('axiosRequest error:', error);
374-
});
375-
console.info('axiosRequest() End');
376-
}
377-
378-
function axiosRequest(method) {
379-
console.info('axiosRequest() Start');
361+
vConsole.show();
380362
axios({
381363
method,
382364
url: './data/success.json?method=axios&r=' + Math.random(),
@@ -391,7 +373,6 @@
391373
.catch(function(error) {
392374
console.log('axiosRequest error:', error);
393375
});
394-
console.info('axiosRequest() End');
395376
}
396377

397378
function optionsXHR() {

dev/node.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
import VConsole from 'vconsole';
1+
import * as tool from '../src/lib/tool';
2+
const massiveData = require('./data/massive.json');
3+
// console.log('massiveData:', massiveData);
24

3-
const vconsole = new VConsole();
4-
console.log(vconsole.version);
5+
const ret = tool.safeJSONStringify(massiveData, { maxDepth: 10, keyMaxLen: 5000, pretty: true });
6+
console.log(ret);

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vconsole",
3-
"version": "3.14.3",
3+
"version": "3.14.4",
44
"description": "A lightweight, extendable front-end developer tool for mobile web page.",
55
"homepage": "https://github.com/Tencent/vConsole",
66
"files": [

src/lib/tool.ts

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,8 @@ const _safeJSONStringifyCircularFinder = () => {
202202
const _safeJSONStringifyFlatValue = (value: any, maxLen = 0) => {
203203
let str = '';
204204
if (isString(value)) {
205-
const len = value.length;
206-
if (maxLen > 0 && len > maxLen) {
207-
value = subString(value, maxLen) + `...(${getBytesText(getStringBytes(value))})`;
205+
if (maxLen > 0) {
206+
value = getStringWithinLength(value, maxLen);
208207
}
209208
str += '"' + getVisibleText(value) + '"';
210209
} else if (isSymbol(value)) {
@@ -337,6 +336,11 @@ export function JSONStringify(value: any, replacer?: (this: any, key: string, va
337336
return stringifyResult;
338337
}
339338

339+
/**
340+
* Get the bytes of a string.
341+
* @example 'a' = 1
342+
* @example '好' = 3
343+
*/
340344
export function getStringBytes(str: string) {
341345
try {
342346
return encodeURI(str).split(/%(?:u[0-9A-F]{2})?[0-9A-F]{2}|./).length - 1;
@@ -345,6 +349,9 @@ export function getStringBytes(str: string) {
345349
}
346350
}
347351

352+
/**
353+
* Convert bytes number to 'MB' or 'KB' string.
354+
*/
348355
export function getBytesText(bytes: number) {
349356
if (bytes <= 0) {
350357
return '';
@@ -358,31 +365,14 @@ export function getBytesText(bytes: number) {
358365
return bytes + ' B';
359366
}
360367

361-
const _subStringPattern = /[^\x00-\xff]/g
362-
export function subString(str: string, len: number) {
363-
let m: number;
364-
365-
if (str.replace(_subStringPattern, '**').length > len) {
366-
m = Math.floor(len / 2);
367-
368-
for (let i = m, l = str.length; i < l; i++) {
369-
const sub = str.substring(0, i);
370-
if (sub.replace(_subStringPattern, '**').length >= len) {
371-
return sub;
372-
}
373-
}
374-
}
375-
376-
return str;
377-
}
378-
379368
/**
380369
* Get a string within a limited max length.
370+
* The byte size of the string will be appended to the string when reached the limit.
371+
* @return 'some string...(3.1 MB)'
381372
*/
382373
export function getStringWithinLength(str: string, maxLen: number) {
383-
const bytes = getStringBytes(str);
384-
if (bytes > maxLen) {
385-
str = subString(str, maxLen) + `...(${getBytesText(bytes)})`;
374+
if (str.length > maxLen) {
375+
str = str.substring(0, maxLen) + `...(${getBytesText(getStringBytes(str))})`;
386376
}
387377
return str;
388378
}

0 commit comments

Comments
 (0)