记录移动返回栈同步失败
移动 WebView 返回栈注入脚本写入 history state 失败时记录日志 移动壳测试和配置检查拒绝返回栈脚本空 catch 共享决策日志补充移动返回栈同步失败边界
This commit is contained in:
@@ -1520,12 +1520,20 @@ for (const snippet of [
|
||||
'genarrative.mobile.historyState',
|
||||
'__genarrativeMobileHistoryIndex',
|
||||
'__GENARRATIVE_MOBILE_POST_NAVIGATION_STATE__',
|
||||
"console.warn('mobile navigation state sync failed', error)",
|
||||
]) {
|
||||
if (!webViewPolicySource.includes(snippet)) {
|
||||
throw new Error(`mobile shell WebView policy missing ${snippet}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
webViewPolicySource.includes('catch (error) {}') ||
|
||||
webViewPolicySource.includes('catch (_error) {}')
|
||||
) {
|
||||
throw new Error('mobile shell WebView policy must not hide injected script failures');
|
||||
}
|
||||
|
||||
if (
|
||||
webViewPolicySource.includes("['blob:'") ||
|
||||
webViewPolicySource.includes("'filesystem:'")
|
||||
|
||||
@@ -169,6 +169,32 @@ describe('TRACK_MOBILE_WEBVIEW_HISTORY_SCRIPT', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('路由栈状态写入失败时记录日志', () => {
|
||||
const postMessage = vi.fn();
|
||||
const syncError = new Error('history state blocked');
|
||||
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
|
||||
window.ReactNativeWebView = {
|
||||
postMessage,
|
||||
};
|
||||
window.history.replaceState = vi.fn(() => {
|
||||
throw syncError;
|
||||
}) as typeof window.history.replaceState;
|
||||
|
||||
window.eval(TRACK_MOBILE_WEBVIEW_HISTORY_SCRIPT);
|
||||
|
||||
expect(warnSpy).toHaveBeenCalledWith(
|
||||
'mobile navigation state sync failed',
|
||||
syncError,
|
||||
);
|
||||
expect(postMessage).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
type: 'genarrative.mobile.historyState',
|
||||
canGoBack: false,
|
||||
}),
|
||||
);
|
||||
warnSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('重复注入时回放当前 H5 路由栈状态', () => {
|
||||
const postMessage = vi.fn();
|
||||
window.ReactNativeWebView = {
|
||||
|
||||
@@ -176,7 +176,9 @@ export const TRACK_MOBILE_WEBVIEW_HISTORY_SCRIPT = `
|
||||
'',
|
||||
window.location.href
|
||||
);
|
||||
} catch (error) {}
|
||||
} catch (error) {
|
||||
console.warn('mobile navigation state sync failed', error);
|
||||
}
|
||||
}
|
||||
|
||||
window.history.pushState = function(state, title, url) {
|
||||
|
||||
Reference in New Issue
Block a user