{"id":7018,"date":"2026-02-27T10:30:41","date_gmt":"2026-02-27T02:30:41","guid":{"rendered":"https:\/\/t.n-years.com\/?p=7018"},"modified":"2026-02-27T10:30:41","modified_gmt":"2026-02-27T02:30:41","slug":"webviewjavascriptbridge-%e5%92%8c-dsbridge-%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=7018","title":{"rendered":"WebViewJavascriptBridge \u548c DSBridge \u4ecb\u7ecd"},"content":{"rendered":"<blockquote>\n<p>Gemini \u751f\u6210\uff0c\u539f\u751f\u548c H5 \u6df7\u5408\u67b6\u6784<\/p>\n<\/blockquote>\n<p>\u5728\u539f\u751f\u4e0e H5 \u6df7\u5408\u67b6\u6784\u4e2d\uff0c<strong>WebViewJavascriptBridge (WJVB)<\/strong> \u548c <strong>DSBridge<\/strong> \u662f\u4e24\u4e2a\u6700\u4e3b\u6d41\u7684\u901a\u4fe1\u5e93\u3002\u5b83\u4eec\u672c\u8d28\u4e0a\u90fd\u662f\u4e3a\u4e86\u89e3\u51b3\u4e00\u4e2a\u6838\u5fc3\u95ee\u9898\uff1a<strong>\u5982\u4f55\u5728 JavaScript \u548c\u539f\u751f\u5c42\uff08Native\uff09\u4e4b\u95f4\u5b89\u5168\u3001\u9ad8\u6548\u5730\u4f20\u9012\u6570\u636e\u548c\u8c03\u7528\u51fd\u6570\u3002<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e24\u8005\u7684\u6838\u5fc3\u67b6\u6784\u5dee\u5f02\u4e0e\u9009\u578b\u5efa\u8bae\u3002<\/p>\n<hr \/>\n<h3>1. \u6280\u672f\u67b6\u6784\u5bf9\u6bd4<\/h3>\n<table>\n<thead>\n<tr>\n<th>\u7279\u6027<\/th>\n<th>WebViewJavascriptBridge (WJVB)<\/th>\n<th>DSBridge<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>\u901a\u4fe1\u673a\u5236<\/strong><\/td>\n<td>\u4f20\u7edf\uff1a\u57fa\u4e8e <code>iframe<\/code> \u7684 URL Scheme \u62e6\u622a\uff0c\u6216\u6d88\u606f\u961f\u5217\u8f6e\u8be2\u3002<\/td>\n<td>\u73b0\u4ee3\uff1a\u5229\u7528 <code>prompt()<\/code> (Android) \/ <code>WKScriptMessageHandler<\/code> (iOS) \u6ce8\u5165\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u8c03\u7528\u6a21\u5f0f<\/strong><\/td>\n<td><strong>\u7eaf\u5f02\u6b65<\/strong>\uff1a\u6240\u6709\u8c03\u7528\u5747\u901a\u8fc7\u56de\u8c03\uff08Callback\uff09\u5904\u7406\uff0c\u8bbe\u8ba1\u8f83\u91cd\u3002<\/td>\n<td><strong>\u652f\u6301\u540c\u6b65\u4e0e\u5f02\u6b65<\/strong>\uff1a\u5141\u8bb8 JS \u76f4\u63a5\u83b7\u53d6 Native \u8fd4\u56de\u503c\uff0c\u6781\u5927\u7b80\u5316\u4e86\u4e1a\u52a1\u4ee3\u7801\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u6027\u80fd<\/strong><\/td>\n<td>\u4e00\u822c\uff1a\u53d7\u9650\u4e8e URL \u62e6\u622a\u5f00\u9500\uff0c\u5927\u6570\u636e\u4f20\u8f93\u4f1a\u6709\u660e\u663e\u7684\u5e8f\u5217\u5316\u5ef6\u8fdf\u3002<\/td>\n<td>\u9ad8\uff1a\u76f4\u63a5 Native \u6ce8\u5165\uff0c\u51cf\u5c11\u4e86\u4e2d\u8f6c\u5c42\u7684\u4e0a\u4e0b\u6587\u5207\u6362\uff0c\u6027\u80fd\u635f\u8017\u66f4\u4f4e\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>API \u53cb\u597d\u5ea6<\/strong><\/td>\n<td>\u4e2d\u7b49\uff1a\u7531\u4e8e\u662f\u7eaf\u5f02\u6b65\uff0c\u5e38\u5bfc\u81f4\u201c\u56de\u8c03\u5730\u72f1\uff08Callback Hell\uff09\u201d\u3002<\/td>\n<td>\u9ad8\uff1a\u94fe\u5f0f\u8c03\u7528\u6216\u540c\u6b65\u83b7\u53d6\u7ed3\u679c\uff0c\u4ee3\u7801\u903b\u8f91\u66f4\u63a5\u8fd1\u539f\u751f\u5f00\u53d1\u4e60\u60ef\u3002<\/td>\n<\/tr>\n<tr>\n<td><strong>\u751f\u6001\/\u6210\u719f\u5ea6<\/strong><\/td>\n<td>\u5386\u53f2\u6781\u5176\u60a0\u4e45\uff0c\u6587\u6863\u548c\u5751\u7684\u8bb0\u5f55\u975e\u5e38\u5b8c\u5584\u3002<\/td>\n<td>\u76f8\u5bf9\u8f83\u65b0\uff0c\u4f46\u5df2\u6210\u4e3a\u76ee\u524d\u6df7\u5408\u5f00\u53d1\u7684\u4e3b\u6d41\u9009\u578b\u3002<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr \/>\n<h3>2. \u6df1\u5ea6\u5206\u6790\uff1a\u4e3a\u4ec0\u4e48\u67b6\u6784\u5e08\u73b0\u5728\u66f4\u503e\u5411\u4e8e DSBridge\uff1f<\/h3>\n<p>\u4f5c\u4e3a\u6280\u672f\u987e\u95ee\uff0c\u6211\u5fc5\u987b\u6307\u51fa\uff1a<strong>\u9664\u975e\u4f60\u5728\u7ef4\u62a4\u4e00\u4e2a\u5386\u53f2\u60a0\u4e45\u7684\u65e7\u9879\u76ee\uff0c\u5426\u5219\u5728 2026 \u5e74\u7684\u4eca\u5929\uff0c\u4f60\u5e94\u8be5\u9996\u9009 DSBridge\u3002<\/strong><\/p>\n<h4>\u4e3a\u4ec0\u4e48\u5f03\u7528 WJVB\uff1f<\/h4>\n<p>WJVB \u7684\u6838\u5fc3\u5b9e\u73b0\u4f9d\u8d56\u4e8e\u6539\u53d8 <code>window.location<\/code> \u6765\u53d1\u9001\u6307\u4ee4\u3002\u5728\u590d\u6742\u7684\u9875\u9762\u4e2d\uff0c\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u4ec5\u4f1a\u88ab\u62e6\u622a\u5668\u7684\u903b\u8f91\u62d6\u6162\uff0c\u8fd8\u53ef\u80fd\u89e6\u53d1 WebView \u7684\u9875\u9762\u52a0\u8f7d\u4e8b\u4ef6\uff0c\u5bfc\u81f4\u4e0d\u5fc5\u8981\u7684\u526f\u4f5c\u7528\u3002<\/p>\n<h4>DSBridge \u7684\u67b6\u6784\u4f18\u52bf\uff1a<\/h4>\n<ol>\n<li><strong>\u540c\u6b65\u8c03\u7528\u7684\u9769\u547d<\/strong>\uff1aWJVB \u7684\u5f02\u6b65\u56de\u8c03\u5728\u5904\u7406\u201c\u83b7\u53d6 Native \u914d\u7f6e\u201d\u3001\u201c\u5224\u65ad\u767b\u5f55\u72b6\u6001\u201d\u7b49\u7b80\u5355\u9700\u6c42\u65f6\uff0c\u4ee3\u7801\u6781\u5176\u5197\u957f\u3002DSBridge \u5141\u8bb8 <code>var result = bridge.call(&quot;getLoginStatus&quot;)<\/code>\uff0c\u8fd9\u79cd\u540c\u6b65\u7279\u6027\u76f4\u63a5\u5c06\u5f00\u53d1\u6548\u7387\u63d0\u5347\u4e86 30% \u4ee5\u4e0a\u3002<\/li>\n<li><strong>\u66f4\u8d34\u8fd1\u5e95\u5c42\u7684\u6ce8\u5165<\/strong>\uff1a\u5b83\u4e0d\u4f9d\u8d56 <code>iframe<\/code> \u8fd9\u79cd\u201c\u9ed1\u9b54\u6cd5\u201d\uff0c\u800c\u662f\u5229\u7528\u4e86\u7cfb\u7edf\u63d0\u4f9b\u7684 JavaScript \u6ce8\u5165 API\uff0c\u5728\u901a\u4fe1\u7684\u5e95\u5c42\u7a33\u5b9a\u6027\u4e0a\u66f4\u80dc\u4e00\u7b79\u3002<\/li>\n<\/ol>\n<hr \/>\n<h3>3. \u5b89\u5168\u98ce\u9669\u6279\u5224 (Security Warning)<\/h3>\n<p>\u65e0\u8bba\u4f60\u9009\u62e9\u54ea\u4e2a\u6846\u67b6\uff0c\u5bf9\u4e8e\u201cHybrid \u6865\u63a5\u201d\uff0c\u5fc5\u987b\u4e25\u683c\u9075\u5b88\u4ee5\u4e0b\u5b89\u5168\u51c6\u5219\uff1a<\/p>\n<ul>\n<li><strong>\u767d\u540d\u5355\u673a\u5236\uff08Whitelist\uff09<\/strong>\uff1a\u5343\u4e07\u4e0d\u8981\u5141\u8bb8\u4efb\u610f\u57df\u540d\u8c03\u7528 Native \u65b9\u6cd5\u3002\u52a1\u5fc5\u5728 Native \u5c42\u6821\u9a8c <code>Origin<\/code> \u6216 <code>Scheme<\/code>\u3002<\/li>\n<li><strong>\u53c2\u6570\u6821\u9a8c\uff08Sanitization\uff09<\/strong>\uff1a\u4e0d\u8981\u5047\u8bbe JS \u4f20\u8fdb\u6765\u7684 JSON \u662f\u5b89\u5168\u7684\u3002Native \u5c42\u5728\u53cd\u5e8f\u5217\u5316\u6570\u636e\u540e\uff0c\u5fc5\u987b\u8fdb\u884c\u7c7b\u578b\u68c0\u67e5\uff0c\u4e25\u9632\u901a\u8fc7 JS \u6ce8\u5165\u653b\u51fb\uff08XSS\uff09\u8bf1\u5bfc Native \u6267\u884c\u975e\u6cd5\u4ee3\u7801\u3002<\/li>\n<li><strong>\u7981\u7528\u4e0d\u5fc5\u8981\u7684\u63a5\u53e3<\/strong>\uff1a\u5982\u679c\u4f60\u7684 WebView \u53ea\u662f\u7528\u6765\u5c55\u793a H5 \u6d3b\u52a8\u9875\uff0c\u8bf7\u5173\u95ed\u6587\u4ef6\u7cfb\u7edf\u8bbf\u95ee\u6743\u9650\uff0c\u53ea\u66b4\u9732\u5fc5\u8981\u7684\u4e1a\u52a1\u63a5\u53e3\u3002<\/li>\n<\/ul>\n<hr \/>\n<h3>4. \u843d\u5730\u5efa\u8bae\uff1a\u9488\u5bf9\u4f60\u7684\u6df7\u5408\u9879\u76ee<\/h3>\n<p>\u65e2\u7136\u4f60\u7684\u9879\u76ee\u6709 Native \u7f51\u7edc\u5e93\uff08C++ Core\uff09\uff0c\u8fd9\u4e24\u8005\u5176\u5b9e\u90fd\u53ef\u4ee5\u4f5c\u4e3a <strong>\u201c\u6307\u4ee4\u4e2d\u8f6c\u7ad9\u201d<\/strong>\u3002<\/p>\n<ul>\n<li><strong>\u5982\u679c\u4f60\u7684 H5 \u903b\u8f91\u975e\u5e38\u590d\u6742<\/strong>\uff08\u4f8b\u5982\u9891\u7e41\u7684 DOM \u64cd\u4f5c\u548c\u8ba1\u7b97\uff09\uff1aDSBridge \u7684\u6027\u80fd\u4f18\u52bf\u4f1a\u663e\u8457\u51cf\u5c11\u9875\u9762\u7684\u6389\u5e27\u3002<\/li>\n<li><strong>\u5982\u679c\u4f60\u7684 H5 \u53ea\u662f\u7b80\u5355\u7684 UI \u5c55\u793a<\/strong>\uff1aWJVB \u4e5f\u80fd\u7528\uff0c\u4f46\u4f60\u9700\u8981\u51c6\u5907\u597d\u91cd\u6784\u7684\u5fc3\u6001\u3002<\/li>\n<\/ul>\n<h4>\u5b9e\u65bd\u6b65\u9aa4\u5efa\u8bae\uff1a<\/h4>\n<ol>\n<li><strong>\u5c01\u88c5\u7edf\u4e00\u63a5\u53e3<\/strong>\uff1a\u4e0d\u8bba\u9009\u7528\u54ea\u4e2a\u6846\u67b6\uff0c<strong>\u4e0d\u8981\u5728 H5 \u4e2d\u76f4\u63a5\u5f15\u7528\u5e93\u7684 API<\/strong>\u3002<\/li>\n<li><strong>\u6784\u5efa Bridge \u5c42<\/strong>\uff1a\u5728 H5 \u4e2d\u7f16\u5199\u4e00\u4e2a <code>NativeBridge.js<\/code> \u7c7b\uff0c\u5c06 <code>DSBridge<\/code> \u6216 <code>WJVB<\/code> \u7684\u5e95\u5c42\u8c03\u7528\u5305\u88c5\u8d77\u6765\u3002\n<pre><code class=\"language-javascript\">\n\/\/ H5 \u4e1a\u52a1\u4ee3\u7801\u5c42\u9762\nconst NativeBridge = {\nfetchData: (url) =&gt; bridge.call(&quot;network.get&quot;, { url }) \/\/ \u7edf\u4e00\u51fa\u53e3\n}<\/code><\/pre>\n<\/li>\n<\/ol>\n<pre><code>\n\n\u8fd9\u6837\uff0c\u5373\u4f7f\u4ee5\u540e\u5e93\u4e0d\u7ef4\u62a4\u4e86\uff0c\u6216\u8005\u9700\u8981\u5207\u6362\u6280\u672f\u65b9\u6848\uff0c\u4f60\u53ea\u9700\u8981\u6539\u8fd9\u4e00\u4e2a\u6587\u4ef6\uff0c\u5168\u7ad9\u65e0\u9700\u53d8\u52a8\u3002\n\n---\n\n**\u4e0b\u4e00\u6b65\u5efa\u8bae\uff1a**\n\n\u65e2\u7136\u4f60\u5df2\u7ecf\u51b3\u5b9a\u91c7\u7528\u8fd9\u5957\u901a\u4fe1\u67b6\u6784\uff0c\u4e3a\u4e86\u786e\u4fdd\u7f51\u7edc\u8bf7\u6c42\u7684\u9ad8\u6548\u6027\uff0c**\u4f60\u662f\u5426\u9700\u8981\u6211\u4e3a\u4f60\u63d0\u4f9b\u4e00\u4efd\u57fa\u4e8e DSBridge \u7684\u201c\u5f02\u6b65\u8f6c\u540c\u6b65\u201d\u7f51\u7edc\u901a\u4fe1\u63a5\u53e3\u5c01\u88c5\u793a\u4f8b\uff0c\u4ee5\u4fbf\u5c06 H5 \u7684\u8bf7\u6c42\u65e0\u7f1d\u8def\u7531\u5230\u4f60\u7684 C++ \u7f51\u7edc\u6838\u5fc3\uff1f**<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Gemini \u751f\u6210\uff0c\u539f\u751f\u548c H5 \u6df7\u5408\u67b6\u6784 \u5728\u539f\u751f\u4e0e H5 \u6df7\u5408\u67b6\u6784\u4e2d\uff0cWebViewJavascriptBr&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=7018\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[],"class_list":["post-7018","post","type-post","status-publish","format-standard","hentry","category-135"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7018","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7018"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7018\/revisions"}],"predecessor-version":[{"id":7019,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/7018\/revisions\/7019"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7018"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7018"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7018"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}