@leeguoo/pwtk-network-debugger 1.2.21 → 1.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -7976,19 +7976,40 @@ async function createShareLink(requestData) {
7976
7976
  decryptedResponse: requestData.decryptedResponse,
7977
7977
  error: requestData.error,
7978
7978
  creator: "PWTK Network Debugger by Leo (@leeguoo)",
7979
- version: "1.2.0"
7979
+ version: "1.2.22"
7980
7980
  }
7981
7981
  };
7982
+ const currentDomain = window.location.hostname;
7983
+ const isOnCurlDomain = currentDomain === "curl.bwg.leeguoo.com" || currentDomain === "localhost";
7982
7984
  const originalFetch = window.__originalFetch || window.fetch;
7983
- const response = await originalFetch("https://curl.bwg.leeguoo.com/api/share", {
7984
- method: "POST",
7985
- headers: {
7986
- "Content-Type": "application/json"
7987
- },
7988
- body: JSON.stringify({
7989
- data: shareData
7990
- })
7991
- });
7985
+ let apiUrl;
7986
+ let response;
7987
+ if (isOnCurlDomain) {
7988
+ apiUrl = "/api/share";
7989
+ logger.debug("使用同域API:", apiUrl);
7990
+ } else {
7991
+ apiUrl = "https://curl.bwg.leeguoo.com/api/share";
7992
+ logger.debug("使用跨域API:", apiUrl);
7993
+ }
7994
+ try {
7995
+ response = await originalFetch(apiUrl, {
7996
+ method: "POST",
7997
+ headers: {
7998
+ "Content-Type": "application/json"
7999
+ },
8000
+ body: JSON.stringify({
8001
+ data: shareData
8002
+ })
8003
+ });
8004
+ } catch (fetchError) {
8005
+ if (fetchError.name === "TypeError" && fetchError.message.includes("fetch")) {
8006
+ throw new Error(`网络连接失败: 无法连接到分享服务器 (${apiUrl}). 可能原因: CORS策略限制或网络问题`);
8007
+ }
8008
+ throw fetchError;
8009
+ }
8010
+ if (!response.ok) {
8011
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
8012
+ }
7992
8013
  const result = await response.json();
7993
8014
  if (result.shareId) {
7994
8015
  const shareUrl = `https://curl.bwg.leeguoo.com/share/${result.shareId}`;
@@ -7998,8 +8019,13 @@ async function createShareLink(requestData) {
7998
8019
  throw new Error(result.error || "创建分享失败");
7999
8020
  }
8000
8021
  } catch (error) {
8001
- logger.error("NetworkDebugger: 创建分享链接失败:", error);
8002
- throw error;
8022
+ const errorMessage = error.message || error.toString() || "未知错误";
8023
+ logger.error("NetworkDebugger: 创建分享链接失败:", {
8024
+ message: errorMessage,
8025
+ name: error.name,
8026
+ stack: error.stack?.split("\n")[0]
8027
+ });
8028
+ throw new Error(errorMessage);
8003
8029
  }
8004
8030
  }
8005
8031
  async function copyToClipboard(text) {