关闭移动壳网页下载路径
移动壳 WebView 注入下载阻断脚本并丢弃 iOS 文件下载事件。 移动壳 Android 包配置阻断外部存储和请求安装包权限。 移动壳配置检查和 Expo public config smoke 锁定下载边界。 新增移动壳 WebView 下载阻断策略测试。 更新宿主壳方案和共享决策日志记录移动端下载只能走 HostBridge 导出。
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { BLOCK_WEBVIEW_DOWNLOAD_SCRIPT } from './mobileShellWebViewPolicy';
|
||||
|
||||
describe('BLOCK_WEBVIEW_DOWNLOAD_SCRIPT', () => {
|
||||
test('阻断 WebView 内的网页下载链接', () => {
|
||||
expect(BLOCK_WEBVIEW_DOWNLOAD_SCRIPT).toContain(
|
||||
"element.tagName === 'A'",
|
||||
);
|
||||
expect(BLOCK_WEBVIEW_DOWNLOAD_SCRIPT).toContain(
|
||||
"element.hasAttribute('download')",
|
||||
);
|
||||
expect(BLOCK_WEBVIEW_DOWNLOAD_SCRIPT).toContain('event.preventDefault()');
|
||||
expect(BLOCK_WEBVIEW_DOWNLOAD_SCRIPT.trim()).toMatch(/true;$/);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
export const BLOCK_WEBVIEW_DOWNLOAD_SCRIPT = `
|
||||
document.addEventListener('click', function(event) {
|
||||
var element = event.target;
|
||||
while (element && element !== document) {
|
||||
if (element.tagName === 'A' && element.hasAttribute('download')) {
|
||||
event.preventDefault();
|
||||
return false;
|
||||
}
|
||||
element = element.parentNode;
|
||||
}
|
||||
}, true);
|
||||
true;
|
||||
`;
|
||||
Reference in New Issue
Block a user