Skip to content

Commit 5933fb4

Browse files
authored
Merge pull request #568 from Tencent/dev
v3.14.7
2 parents e56370c + 61c7061 commit 5933fb4

26 files changed

+278
-142
lines changed

CHANGELOG.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
English | [简体中文](./CHANGELOG_CN.md)
22

3+
## 3.14.7 (2022-09-23)
4+
5+
- `Perf(Log)` Optimize rendering performance when adding logs. (PR #567)
6+
- `Fix(Core)` Fix plugin panel sorting error when setting `pluginOrder` option. (issue #559)
7+
- `Fix(Core)` Fix intervention error caused by `preventDefault` in `Touch` events. (issue #546)
8+
- `Fix(Log)` Fix `window.onerror` missing line breaks.
9+
- `Fix(Log)` Fix unclickable `vc-cmd-clear-btn` on iOS Safari. (PR #564)
10+
- `Fix(Log)` Fix a typo that misjudged circular reference objects. (issue #566)
11+
- `Fix(Log|Network)` Copy objects or arrays as standard JSON format. (issue #547)
12+
- `Fix(Network)` Fix `Fetch` stays in pending status when `window` is proxied. (issue #556)
13+
- `Fix(Storage)` Fix storage pannel sorting error when setting `storage.defaultStorages` option. (issue #560)
14+
- `Chore` Add option `env['no-core-js']` to disable core-js polyfill. (PR #562)
15+
16+
317
## 3.14.6 (2022-04-14)
418

519
- `Fix(Log)` Fix logs lost tracking when adding a new vConsole after destroying the old one.

CHANGELOG_CN.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
[English](./CHANGELOG.md) | 简体中文
22

3+
## 3.14.7 (2022-09-23)
4+
5+
- `Perf(Log)` 优化打印日志时的性能。 (PR #567)
6+
- `Fix(Core)` 修复因设置 `pluginOrder` 导致插件面板排序错误的问题。 (issue #559)
7+
- `Fix(Core)` 修复因 `Touch` 事件中的 `preventDefault` 导致的 intervention 错误。 (issue #546)
8+
- `Fix(Log)` 修复 `window.onerror` 丢失换行的问题。
9+
- `Fix(Log)` 修复清除命令行按钮在 iOS Safari 中无法点击的问题。 (PR #564)
10+
- `Fix(Log)` 修复一处误判循环引用对象的笔误。 (issue #566)
11+
- `Fix(Log|Network)` 以标准 JSON 格式复制对象或数组。 (issue #547)
12+
- `Fix(Network)` 修复因 `window` 对象被代理导致 `Fetch` 一直为 pending 状态的问题。 (issue #556)
13+
- `Fix(Storage)` 修复因设置 `storage.defaultStorages` 导致 Storage 面板排序错误的问题。 (issue #560)
14+
- `Chore` 添加 `env['no-core-js']` 选项来停用构建时使用 core-js polyfill。 (PR #562)
15+
16+
317
## 3.14.6 (2022-04-14)
418

519
- `Fix(Log)` 修复当销毁后再次初始化 vConsole 时失去追踪 logs 的问题。

build/dummy.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default {}

dev/common.html

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// maxLogNumber: 1000,
3333
// disableLogScrolling: true,
3434
// theme: 'dark',
35+
// pluginOrder: ['network'],
3536
onReady: function() {
3637
console.log('vConsole: onReady');
3738
},

dev/log.html

+27-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@
1313
</head>
1414
<body ontouchstart>
1515
<div id="page" class="page">
16+
<div class="section">
17+
<div class="hd">String</div>
18+
19+
<a onclick="simpleStrings()" href="javascript:;" class="weui_btn weui_btn_default">Simple Strings</a>
20+
<a onclick="printf()" href="javascript:;" class="weui_btn weui_btn_default">Printf</a>
21+
<a onclick="styling()" href="javascript:;" class="weui_btn weui_btn_default">Styling</a>
22+
</div>
23+
1624
<div class="section">
1725
<div class="hd">Object</div>
1826

19-
<a onclick="(() => console.log('Hello vConsole!'))()" href="javascript:;" class="weui_btn weui_btn_default">A Simple String</a>
2027
<a onclick="normalObject()" href="javascript:;" class="weui_btn weui_btn_default">Common Object</a>
2128
<a onclick="largeObject()" href="javascript:;" class="weui_btn weui_btn_default">Large Object</a>
2229
<a onclick="circularObject()" href="javascript:;" class="weui_btn weui_btn_default">Circular Object & Array</a>
@@ -120,6 +127,24 @@
120127
bc: [1, 2, 3],
121128
};
122129

130+
function simpleStrings() {
131+
console.log('Hello vConsole!');
132+
console.log(`Line 1,
133+
Line 2`);
134+
}
135+
136+
function printf() {
137+
console.log('Hi %s, Im %s', 'Foo', 'Bar'); // Hi Foo, Im Bar
138+
console.log('I had %d cakes', 3); // I had 3 cakes
139+
console.log('The %o is large', aa); // The [[aa]] is large
140+
}
141+
142+
function styling() {
143+
console.log('%c blue %c red', 'color:blue', 'color:red'); // blue red
144+
console.log('%c FOO', 'font-weight:bold', 'bar'); // FOO bar
145+
console.log('%c Foo %c bar', 'color:red'); // Foo %c bar
146+
}
147+
123148
function differentPanelLog() {
124149
console.log('[default]', 'This log should be shown in Log panel.');
125150
console.log('[DEFAULT]', 'Switch to System tab to see next log.');
@@ -298,7 +323,7 @@
298323
'key': 'foo\nbar\tyoo',
299324
"-->\tyo\n'\"/><div>": "-->\n'\"/><iframe>"
300325
};
301-
console.log('XSS str:', "-->\tyo\n'\"/><iframe>");
326+
console.log('XSS str:', "-->\tyo\n'\"/><iframe><i>");
302327
console.log(arr);
303328
console.log(obj);
304329
}

dev/storage.html

+6-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<a onclick="xssStorage()" href="javascript:;" class="weui_btn weui_btn_default">XSS</a>
1919
<a onclick="defaultStoragesClear()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: clear</a>
2020
<a onclick="defaultStoragesAdd()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: add</a>
21+
<a onclick="defaultStoragesUpdate()" href="javascript:;" class="weui_btn weui_btn_default">defaultStorages: update</a>
2122
</div>
2223
</body>
2324
</html>
@@ -28,7 +29,7 @@
2829
window.vConsole = new window.VConsole({
2930
// disableLogScrolling: true,
3031
storage: {
31-
// defaultStorages: [],
32+
// defaultStorages: ['sessionStorage', 'cookies', 'localStorage'],
3233
},
3334
onReady: function() {
3435
console.log('vConsole is ready.');
@@ -140,4 +141,8 @@
140141
window.wx = {};
141142
vConsole.setOption('storage.defaultStorages', ['wxStorage', 'localStorage']);
142143
}
144+
145+
function defaultStoragesUpdate() {
146+
vConsole.setOption('storage.defaultStorages', ['localStorage', 'unknownStorage', 'sessionStorage']);
147+
}
143148
</script>

doc/tutorial.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ console.log('%c FOO', 'font-weight:bold', 'bar'); // FOO bar
127127
console.log('%c Foo %c bar', 'color:red'); // Foo %c bar
128128
```
129129

130-
> Note that only first parameter support `%c` format, and the following parameter(s) will be used as HTML style to fill `%c`, and the remain `%c` or parameters will be shown as normal string.
130+
> Note that only the first parameter support `%c` format, and the `%c` must be followed by a space. The following parameter(s) will be used as HTML style to fill `%c`, and the remain `%c` or parameters will be shown as normal string.
131131
132132
---
133133

134134
### Using string substitutions
135135

136-
Use `%s, %d, %o` to output log with formatting.
136+
Use `%s, %d, %o` to output a log with formatting. The pattern must be followed by a space.
137137

138138
- `%s`: Output as a string. Non-string objects will be converted into strings.
139139
- `%d`: Output as a number.

doc/tutorial_CN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ console.log('%c FOO', 'font-weight:bold', 'bar'); // FOO bar
123123
console.log('%c Foo %c bar', 'color:red'); // Foo %c bar
124124
```
125125

126-
> 只有第一个参数支持 `%c` 格式,一旦出现 `%c` 格式,后续的字符串参数将作为 HTML style 样式来替换 `%c`;未被替换的 `%c`、剩余的参数,将作为默认日志照常输出。
126+
> 只有第一个参数支持 `%c` 格式,`%c` 后必须带空格。一旦出现 `%c` 格式,后续的字符串参数将作为 HTML style 样式来替换 `%c`;未被替换的 `%c`、剩余的参数,将作为默认日志照常输出。
127127
128128

129129
---
130130

131131

132132
### 使用字符串替换
133133

134-
可使用 `%s, %d, %o` 来格式化输出。
134+
可使用 `%s, %d, %o` 来格式化输出,关键字后必须带空格
135135

136136
- `%s`:输出为字符串。非字符串对象会被转换成字符串。
137137
- `%d`:输出为数字。

package.json

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

src/component/iconCopy.svelte

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
text = handler(content) || '';
1616
} else {
1717
if (tool.isObject(content) || tool.isArray(content)) {
18-
text = tool.safeJSONStringify(content);
18+
text = tool.safeJSONStringify(content, {
19+
maxDepth: 10,
20+
keyMaxLen: 10000,
21+
pretty: false,
22+
standardJSON: true,
23+
});
1924
} else {
2025
text = content;
2126
}

src/core/core.svelte

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
export let switchButtonPosition = { x: 0, y: 0 };
2626
export let activedPluginId = '';
2727
export let pluginList: { [id: string]: IPlugin } = {};
28-
export let divContentInner: HTMLElement = undefined;
28+
export let divContent: HTMLElement;
2929
3030
3131
/*************************************
@@ -34,7 +34,6 @@
3434
3535
const dispatch = createEventDispatcher();
3636
let preventContentMove = false;
37-
let divContent: HTMLElement;
3837
let unsubscribe: ReturnType<typeof contentStore.subscribe>;
3938
let fontSize = '';
4039
let showMain = false;
@@ -294,9 +293,9 @@
294293
class:vc-toggle={showMain}
295294
style="{fontSize ? 'font-size:' + fontSize + ';' : ''}"
296295
data-theme={theme}
297-
on:touchstart|capture={mockTapEvent.touchStart}
298-
on:touchmove|capture={mockTapEvent.touchMove}
299-
on:touchend|capture={mockTapEvent.touchEnd}
296+
on:touchstart|capture|nonpassive={mockTapEvent.touchStart}
297+
on:touchmove|capture|nonpassive={mockTapEvent.touchMove}
298+
on:touchend|capture|nonpassive={mockTapEvent.touchEnd}
300299
>
301300
<SwitchButton
302301
bind:show={showSwitchButton}
@@ -347,7 +346,6 @@
347346
id="__vc_plug_{plugin.id}"
348347
class="vc-plugin-box"
349348
class:vc-actived="{plugin.id === activedPluginId}"
350-
bind:this={divContentInner}
351349
></div>
352350
{/each}
353351
</div>

src/core/core.ts

+14-7
Original file line numberDiff line numberDiff line change
@@ -302,13 +302,20 @@ export class VConsole {
302302
this.compInstance.pluginList[plugin.id].hasTabPanel = true;
303303
// render tabbox
304304
if (!!tabboxHTML) {
305-
if (tool.isString(tabboxHTML)) {
306-
this.compInstance.divContentInner.innerHTML += tabboxHTML;
307-
} else if (tool.isFunction(tabboxHTML.appendTo)) {
308-
tabboxHTML.appendTo(this.compInstance.divContentInner);
309-
} else if (tool.isElement(tabboxHTML)) {
310-
this.compInstance.divContentInner.insertAdjacentElement('beforeend', tabboxHTML);
311-
}
305+
// when built-in plugins are initializing in the same time,
306+
// plugin's `.vc-plugin-box` element will be re-order by `pluginOrder` option,
307+
// so the innerHTML should be inserted with a delay
308+
// to make sure getting the right `.vc-plugin-box`. (issue #559)
309+
setTimeout(() => {
310+
const divContentInner = document.querySelector('#__vc_plug_' + plugin.id);
311+
if (tool.isString(tabboxHTML)) {
312+
divContentInner.innerHTML += tabboxHTML;
313+
} else if (tool.isFunction(tabboxHTML.appendTo)) {
314+
tabboxHTML.appendTo(divContentInner);
315+
} else if (tool.isElement(tabboxHTML)) {
316+
divContentInner.insertAdjacentElement('beforeend', tabboxHTML);
317+
}
318+
}, 0);
312319
}
313320
this.compInstance.pluginList = this.compInstance.pluginList;
314321
});

src/core/switchButton.svelte

+3-3
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@
123123
class="vc-switch"
124124
style="right: {btnSwitchPos.x}px; bottom: {btnSwitchPos.y}px; display: {show ? 'block' : 'none'};"
125125
bind:this={btnSwitch}
126-
on:touchstart={onTouchStart}
127-
on:touchend={onTouchEnd}
128-
on:touchmove={onTouchMove}
126+
on:touchstart|nonpassive={onTouchStart}
127+
on:touchend|nonpassive={onTouchEnd}
128+
on:touchmove|nonpassive={onTouchMove}
129129
on:click
130130
>vConsole</div>

src/lib/tool.ts

+21-5
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ type ISafeJSONStringifyOption = {
185185
maxDepth: number,
186186
keyMaxLen: number,
187187
pretty: boolean,
188+
standardJSON: boolean,
188189
circularFinder: (val: any) => any,
189190
};
190191
const _safeJSONStringifyCircularFinder = () => {
@@ -227,11 +228,13 @@ const _safeJSONStringify = (obj, opt: ISafeJSONStringifyOption, _curDepth = 0) =
227228

228229
const isCircular = opt.circularFinder(obj);
229230
if (isCircular) {
231+
let circularText = '';
230232
if (isArray(obj)) {
231-
opt.ret += '(Circular Array)';
232-
} else if (isObject) {
233-
opt.ret += `(Circular ${obj.constructor?.name || 'Object'})`;
233+
circularText = '(Circular Array)';
234+
} else if (isObject(obj)) {
235+
circularText = `(Circular ${obj.constructor?.name || 'Object'})`;
234236
}
237+
opt.ret += opt.standardJSON ? `"${circularText}"` : circularText;
235238
return;
236239
}
237240

@@ -261,6 +264,8 @@ const _safeJSONStringify = (obj, opt: ISafeJSONStringifyOption, _curDepth = 0) =
261264
if (!isArray(obj)) {
262265
if (isObject(key) || isArray(key) || isSymbol(key)) {
263266
opt.ret += Object.prototype.toString.call(key);
267+
} else if (isString(key) && opt.standardJSON) {
268+
opt.ret += '"' + key + '"';
264269
} else {
265270
opt.ret += key;
266271
}
@@ -294,7 +299,7 @@ const _safeJSONStringify = (obj, opt: ISafeJSONStringifyOption, _curDepth = 0) =
294299

295300
} catch (e) {
296301
// cannot stringify `value`, use a default text
297-
opt.ret += '(...)';
302+
opt.ret += opt.standardJSON ? '"(PARSE_ERROR)"' : '(PARSE_ERROR)';
298303
}
299304

300305
if (opt.keyMaxLen > 0 && opt.ret.length >= opt.keyMaxLen * 10) {
@@ -311,12 +316,23 @@ const _safeJSONStringify = (obj, opt: ISafeJSONStringifyOption, _curDepth = 0) =
311316
/**
312317
* A safe `JSON.stringify` method.
313318
*/
314-
export function safeJSONStringify(obj, opt: { maxDepth?: number, keyMaxLen?: number, pretty?: boolean } = { maxDepth: -1, keyMaxLen: -1, pretty: false, }) {
319+
export function safeJSONStringify(obj, opt: {
320+
maxDepth?: number,
321+
keyMaxLen?: number,
322+
pretty?: boolean,
323+
standardJSON?: boolean,
324+
} = {
325+
maxDepth: -1,
326+
keyMaxLen: -1,
327+
pretty: false,
328+
standardJSON: false,
329+
}) {
315330
const option: ISafeJSONStringifyOption = Object.assign({
316331
ret: '',
317332
maxDepth: -1,
318333
keyMaxLen: -1,
319334
pretty: false,
335+
standardJSON: false,
320336
circularFinder: _safeJSONStringifyCircularFinder(),
321337
}, opt);
322338
_safeJSONStringify(obj, option);

src/log/default.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,18 @@ export class VConsoleDefaultPlugin extends VConsoleLogPlugin {
4848
this.onErrorHandler = this.onErrorHandler ? this.onErrorHandler : (event) => {
4949
let msg = event.message;
5050
if (event.filename) {
51-
msg += '\n' + event.filename.replace(location.origin, '');
52-
}
53-
if (event.lineno || event.colno) {
54-
msg += ':' + event.lineno + ':' + event.colno;
51+
msg += '\\n\\t' + event.filename.replace(location.origin, '');
52+
if (event.lineno || event.colno) {
53+
msg += ':' + event.lineno + ':' + event.colno;
54+
}
5555
}
5656
// print error stack info
5757
const hasStack = !!event.error && !!event.error.stack;
5858
const stackInfo = (hasStack && event.error.stack.toString()) || '';
59+
msg += '\\n' + stackInfo;
5960
this.model.addLog({
6061
type: 'error',
61-
origData: [msg, stackInfo],
62+
origData: [msg],
6263
}, { noOrig: true });
6364
};
6465
window.removeEventListener('error', this.onErrorHandler);

0 commit comments

Comments
 (0)