tuqin
3 天以前 d4c8ef107ad0d0835863b21f240d44402e949584
public/bmap-test.html
@@ -192,5 +192,57 @@
        document.body.appendChild(s);
      })();
    </script>
    <hr style="margin:24px 0" />
    <h3>错误来源抓取(Referer 220 定位)</h3>
    <div style="padding:8px;background:#fff2f0;border-radius:6px;font-size:13px;margin-bottom:8px">
      这一块会拦截百度 SDK 的弹窗告警,并记录所有失败请求,用来定位 220 到底来自哪个域名。
    </div>
    <div id="log4" style="padding:12px;background:#fff7e6;border-radius:6px;font-family:Consolas,monospace;font-size:13px;line-height:1.9;white-space:pre-wrap;word-break:break-all"></div>
    <script>
      (function () {
        var el = document.getElementById('log4');
        function lg(msg, cls) {
          var t = new Date().toLocaleTimeString('zh-CN', { hour12: false });
          var d = document.createElement('div');
          d.className = cls || '';
          d.textContent = '[' + t + '] ' + msg;
          el.appendChild(d);
        }
        // 1) 拦截 alert(百度 SDK 报 220 时是弹 alert)
        var origAlert = window.alert;
        window.alert = function (msg) {
          lg('🚨 百度弹窗: ' + msg, 'bad');
          return origAlert.apply(window, arguments);
        };
        // 2) 记录所有指向 /bmap- 的失败请求
        var origFetch = window.fetch;
        if (origFetch) {
          window.fetch = function (input, init) {
            var url = typeof input === 'string' ? input : (input && input.url);
            return origFetch.apply(this, arguments).then(function (res) {
              if (!res.ok && String(url).indexOf('/bmap-') >= 0) {
                lg('fetch 失败 ' + res.status + ' ' + url, 'bad');
              }
              return res;
            }).catch(function (e) {
              if (String(url).indexOf('/bmap-') >= 0) { lg('fetch 异常 ' + url + ' : ' + e.message, 'bad'); }
              throw e;
            });
          };
        }
        // 3) 记录图片/脚本加载失败(瓦片是 img)
        document.addEventListener('error', function (e) {
          var t = e.target;
          if (!t) { return; }
          var u = t.src || t.href || '';
          if (String(u).indexOf('/bmap-') >= 0) {
            lg('资源加载失败 <' + t.tagName + '> ' + u.slice(0, 120), 'bad');
          }
        }, true);
        lg('已开始监听。现在把上面的地图块加载一遍,这里会记录失败来源。');
        lg('(如果这里没有任何记录,说明 220 来自百度 SDK 内部 alert,请看有没有「百度弹窗」行)');
      })();
    </script>
  </body>
</html>