收口微信页面事件诊断日志

微信 web-view 页面事件日志改为固定阶段标签

原生壳门禁拒绝输出 WebView 原生事件体

同步宿主壳方案和共享决策记录
This commit is contained in:
2026-06-21 15:58:55 +08:00
parent 3991b6cc23
commit 520aa049d3
5 changed files with 100 additions and 17 deletions
+34 -13
View File
@@ -40,6 +40,9 @@ function createPage() {
describe('wechat web-view shell page', () => {
beforeEach(() => {
vi.clearAllMocks();
vi.spyOn(console, 'error').mockImplementation(() => {});
vi.spyOn(console, 'info').mockImplementation(() => {});
globalThis.wx = {
getAccountInfoSync: vi.fn(() => ({
miniProgram: { envVersion: 'release' },
@@ -80,21 +83,23 @@ describe('wechat web-view shell page', () => {
test('stores latest H5 share target for native share menu', () => {
const page = createPage();
page.handleWebViewMessage({
detail: {
data: [
{
data: {
type: 'genarrative:share-target',
payload: {
targetPath: '/works/detail',
work: 'BB-12345678',
title: '汪汪声浪',
},
const webViewDetail = {
data: [
{
data: {
type: 'genarrative:share-target',
payload: {
targetPath: '/works/detail',
work: 'BB-12345678',
title: '汪汪声浪',
},
},
],
},
},
],
};
page.handleWebViewMessage({
detail: webViewDetail,
});
expect(page.onShareAppMessage()).toEqual({
@@ -105,5 +110,21 @@ describe('wechat web-view shell page', () => {
title: '陶泥儿',
query: 'targetPath=%2Fworks%2Fdetail&work=BB-12345678',
});
expect(console.info).toHaveBeenCalledWith('[web-view] message');
expect(console.info.mock.calls.flat()).not.toContain(webViewDetail);
});
test('logs web-view page events without native detail payloads', () => {
const page = createPage();
const loadDetail = { src: 'https://www.genarrative.world/private' };
const errorDetail = { errMsg: 'private native load failed' };
page.handleWebViewLoad({ detail: loadDetail });
page.handleWebViewError({ detail: errorDetail });
expect(console.info).toHaveBeenCalledWith('[web-view] loaded');
expect(console.error).toHaveBeenCalledWith('[web-view] load failed');
expect(console.info.mock.calls.flat()).not.toContain(loadDetail);
expect(console.error.mock.calls.flat()).not.toContain(errorDetail);
});
});