@leeguoo/pwtk-network-debugger 1.2.19 → 1.2.21
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.cjs.js +3 -3
- package/dist/index.esm.js +194 -92
- package/dist/index.js +3 -3
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -6608,8 +6608,100 @@ function requireCryptoJs() {
|
|
|
6608
6608
|
}
|
|
6609
6609
|
var cryptoJsExports = requireCryptoJs();
|
|
6610
6610
|
const CryptoJS = /* @__PURE__ */ getDefaultExportFromCjs(cryptoJsExports);
|
|
6611
|
+
class Logger {
|
|
6612
|
+
constructor() {
|
|
6613
|
+
this.panel = null;
|
|
6614
|
+
this.enableBrowserConsole = false;
|
|
6615
|
+
this.logLevel = "debug";
|
|
6616
|
+
this.buffer = [];
|
|
6617
|
+
this.maxBufferSize = 100;
|
|
6618
|
+
this.enableBrowserConsole = false;
|
|
6619
|
+
this.logLevel = "debug";
|
|
6620
|
+
}
|
|
6621
|
+
configure(config) {
|
|
6622
|
+
if (config.enableBrowserConsole !== void 0) {
|
|
6623
|
+
this.enableBrowserConsole = config.enableBrowserConsole;
|
|
6624
|
+
}
|
|
6625
|
+
if (config.logLevel !== void 0) {
|
|
6626
|
+
this.logLevel = config.logLevel;
|
|
6627
|
+
}
|
|
6628
|
+
}
|
|
6629
|
+
setPanel(panel) {
|
|
6630
|
+
this.panel = panel;
|
|
6631
|
+
this.flushBuffer();
|
|
6632
|
+
}
|
|
6633
|
+
flushBuffer() {
|
|
6634
|
+
if (!this.panel) return;
|
|
6635
|
+
this.buffer.forEach(({ message, type }) => {
|
|
6636
|
+
this.panel.logToConsole(message, type);
|
|
6637
|
+
});
|
|
6638
|
+
this.buffer = [];
|
|
6639
|
+
}
|
|
6640
|
+
shouldLog(level) {
|
|
6641
|
+
const levels = ["debug", "info", "warn", "error"];
|
|
6642
|
+
const currentIndex = levels.indexOf(this.logLevel);
|
|
6643
|
+
const messageIndex = levels.indexOf(level);
|
|
6644
|
+
return messageIndex >= currentIndex;
|
|
6645
|
+
}
|
|
6646
|
+
formatMessage(level, message, args) {
|
|
6647
|
+
const argsStr = args.map((arg) => {
|
|
6648
|
+
if (typeof arg === "object") {
|
|
6649
|
+
try {
|
|
6650
|
+
return JSON.stringify(arg, null, 2);
|
|
6651
|
+
} catch {
|
|
6652
|
+
return String(arg);
|
|
6653
|
+
}
|
|
6654
|
+
}
|
|
6655
|
+
return String(arg);
|
|
6656
|
+
}).join(" ");
|
|
6657
|
+
return argsStr ? `${message} ${argsStr}` : message;
|
|
6658
|
+
}
|
|
6659
|
+
output(message, type, browserMethod) {
|
|
6660
|
+
if (this.panel) {
|
|
6661
|
+
this.panel.logToConsole(message, type);
|
|
6662
|
+
} else {
|
|
6663
|
+
this.buffer.push({ message, type, timestamp: /* @__PURE__ */ new Date() });
|
|
6664
|
+
if (this.buffer.length > this.maxBufferSize) {
|
|
6665
|
+
this.buffer.shift();
|
|
6666
|
+
}
|
|
6667
|
+
}
|
|
6668
|
+
if (this.enableBrowserConsole) {
|
|
6669
|
+
console[browserMethod](message);
|
|
6670
|
+
}
|
|
6671
|
+
}
|
|
6672
|
+
debug(message, ...args) {
|
|
6673
|
+
if (!this.shouldLog("debug")) return;
|
|
6674
|
+
const formatted = this.formatMessage("[DEBUG]", message, args);
|
|
6675
|
+
this.output(formatted, "log", "log");
|
|
6676
|
+
}
|
|
6677
|
+
log(message, ...args) {
|
|
6678
|
+
if (!this.shouldLog("info")) return;
|
|
6679
|
+
const formatted = this.formatMessage("", message, args);
|
|
6680
|
+
this.output(formatted, "log", "log");
|
|
6681
|
+
}
|
|
6682
|
+
info(message, ...args) {
|
|
6683
|
+
if (!this.shouldLog("info")) return;
|
|
6684
|
+
const formatted = this.formatMessage("[INFO]", message, args);
|
|
6685
|
+
this.output(formatted, "log", "log");
|
|
6686
|
+
}
|
|
6687
|
+
warn(message, ...args) {
|
|
6688
|
+
if (!this.shouldLog("warn")) return;
|
|
6689
|
+
const formatted = this.formatMessage("[WARN]", message, args);
|
|
6690
|
+
this.output(formatted, "warn", "warn");
|
|
6691
|
+
}
|
|
6692
|
+
error(message, ...args) {
|
|
6693
|
+
if (!this.shouldLog("error")) return;
|
|
6694
|
+
const formatted = this.formatMessage("[ERROR]", message, args);
|
|
6695
|
+
this.output(formatted, "error", "error");
|
|
6696
|
+
}
|
|
6697
|
+
// 特殊方法:仅输出到浏览器控制台(用于重要的初始化信息)
|
|
6698
|
+
consoleDirect(message, ...args) {
|
|
6699
|
+
console.log(message, ...args);
|
|
6700
|
+
}
|
|
6701
|
+
}
|
|
6702
|
+
const logger = new Logger();
|
|
6611
6703
|
function decrypt(encryptedData, keyStr) {
|
|
6612
|
-
|
|
6704
|
+
logger.debug("[PWTK Decrypt] decrypt function called:", {
|
|
6613
6705
|
dataLength: encryptedData?.length,
|
|
6614
6706
|
dataPreview: encryptedData?.substring(0, 50),
|
|
6615
6707
|
keyStr,
|
|
@@ -6617,25 +6709,25 @@ function decrypt(encryptedData, keyStr) {
|
|
|
6617
6709
|
hasWindowEncrypt: typeof window.encrypt === "function"
|
|
6618
6710
|
});
|
|
6619
6711
|
if (!encryptedData || encryptedData.startsWith("{") || encryptedData.startsWith("[")) {
|
|
6620
|
-
|
|
6712
|
+
logger.debug("[PWTK Decrypt] Data looks like JSON, parsing directly");
|
|
6621
6713
|
try {
|
|
6622
6714
|
const parsed = JSON.parse(encryptedData);
|
|
6623
|
-
|
|
6715
|
+
logger.debug("[PWTK Decrypt] Successfully parsed as JSON");
|
|
6624
6716
|
return parsed;
|
|
6625
6717
|
} catch {
|
|
6626
|
-
|
|
6718
|
+
logger.debug("[PWTK Decrypt] Failed to parse as JSON, returning as string");
|
|
6627
6719
|
return encryptedData;
|
|
6628
6720
|
}
|
|
6629
6721
|
}
|
|
6630
6722
|
if (window.decrypt && keyStr) {
|
|
6631
|
-
|
|
6632
|
-
|
|
6723
|
+
logger.debug("[PWTK Decrypt] Trying WebAssembly decrypt");
|
|
6724
|
+
logger.debug("[PWTK Decrypt] Input to window.decrypt:", {
|
|
6633
6725
|
data: encryptedData.substring(0, 100) + "...",
|
|
6634
6726
|
key: keyStr
|
|
6635
6727
|
});
|
|
6636
6728
|
try {
|
|
6637
6729
|
const decrypted = window.decrypt(encryptedData, keyStr);
|
|
6638
|
-
|
|
6730
|
+
logger.debug("[PWTK Decrypt] window.decrypt returned:", {
|
|
6639
6731
|
type: typeof decrypted,
|
|
6640
6732
|
length: decrypted?.length,
|
|
6641
6733
|
preview: decrypted ? decrypted.substring(0, 200) + (decrypted.length > 200 ? "..." : "") : null,
|
|
@@ -6645,22 +6737,22 @@ function decrypt(encryptedData, keyStr) {
|
|
|
6645
6737
|
if (decrypted && decrypted !== encryptedData && !decrypted.includes("�")) {
|
|
6646
6738
|
try {
|
|
6647
6739
|
const parsed = JSON.parse(decrypted);
|
|
6648
|
-
|
|
6740
|
+
logger.debug("[PWTK Decrypt] ✅ WebAssembly decryption successful, parsed as JSON:", parsed);
|
|
6649
6741
|
return parsed;
|
|
6650
6742
|
} catch {
|
|
6651
6743
|
if (decrypted.length > 0) {
|
|
6652
|
-
|
|
6744
|
+
logger.debug("[PWTK Decrypt] ✅ WebAssembly decryption successful, returning as string");
|
|
6653
6745
|
return decrypted;
|
|
6654
6746
|
}
|
|
6655
6747
|
}
|
|
6656
6748
|
} else {
|
|
6657
|
-
|
|
6749
|
+
logger.debug("[PWTK Decrypt] window.decrypt did not change the data or returned invalid result");
|
|
6658
6750
|
}
|
|
6659
6751
|
} catch (e) {
|
|
6660
|
-
|
|
6752
|
+
logger.debug("[PWTK Decrypt] WebAssembly decrypt error:", e);
|
|
6661
6753
|
}
|
|
6662
6754
|
} else {
|
|
6663
|
-
|
|
6755
|
+
logger.debug("[PWTK Decrypt] WebAssembly not available:", {
|
|
6664
6756
|
hasWindowDecrypt: !!window.decrypt,
|
|
6665
6757
|
hasKey: !!keyStr,
|
|
6666
6758
|
windowDecryptType: typeof window.decrypt
|
|
@@ -6701,7 +6793,7 @@ function decrypt(encryptedData, keyStr) {
|
|
|
6701
6793
|
}
|
|
6702
6794
|
} catch {
|
|
6703
6795
|
}
|
|
6704
|
-
|
|
6796
|
+
logger.debug("[PWTK Decrypt] ❌ All decryption methods failed, returning original data");
|
|
6705
6797
|
return encryptedData;
|
|
6706
6798
|
}
|
|
6707
6799
|
class NetworkInterceptor {
|
|
@@ -6754,12 +6846,12 @@ class NetworkInterceptor {
|
|
|
6754
6846
|
try {
|
|
6755
6847
|
listener(request);
|
|
6756
6848
|
} catch (error) {
|
|
6757
|
-
|
|
6849
|
+
logger.warn("NetworkDebugger: Listener error:", error);
|
|
6758
6850
|
}
|
|
6759
6851
|
});
|
|
6760
6852
|
}
|
|
6761
6853
|
async tryDecrypt(data, headers) {
|
|
6762
|
-
|
|
6854
|
+
logger.debug("[PWTK Debug] tryDecrypt called:", {
|
|
6763
6855
|
dataType: typeof data,
|
|
6764
6856
|
dataLength: typeof data === "string" ? data.length : JSON.stringify(data).length,
|
|
6765
6857
|
dataPreview: typeof data === "string" ? data.substring(0, 100) : JSON.stringify(data).substring(0, 100),
|
|
@@ -6768,14 +6860,14 @@ class NetworkInterceptor {
|
|
|
6768
6860
|
hasWindowDecrypt: typeof window.decrypt === "function"
|
|
6769
6861
|
});
|
|
6770
6862
|
if (!this.decryptConfig.enabled || !data) {
|
|
6771
|
-
|
|
6863
|
+
logger.debug("[PWTK Debug] Decrypt disabled or no data");
|
|
6772
6864
|
return null;
|
|
6773
6865
|
}
|
|
6774
6866
|
try {
|
|
6775
6867
|
let key = "";
|
|
6776
6868
|
let slk = "";
|
|
6777
6869
|
if (headers.cid && this.decryptConfig.autoFetchKeys !== false) {
|
|
6778
|
-
|
|
6870
|
+
logger.debug("[PWTK Debug] Trying to fetch key with cid:", headers.cid);
|
|
6779
6871
|
try {
|
|
6780
6872
|
const apiUrl = this.decryptConfig.keyApiUrl || "https://gw-card-pay.buyacard.cc/ip/getSK";
|
|
6781
6873
|
const fetchHeaders = {
|
|
@@ -6784,57 +6876,57 @@ class NetworkInterceptor {
|
|
|
6784
6876
|
device: headers.device || "Web",
|
|
6785
6877
|
language: headers.language || "CN"
|
|
6786
6878
|
};
|
|
6787
|
-
|
|
6879
|
+
logger.debug("[PWTK Debug] Fetching key from:", apiUrl, "with headers:", fetchHeaders);
|
|
6788
6880
|
const originalFetch = window.__originalFetch || window.fetch;
|
|
6789
6881
|
const response = await originalFetch(apiUrl, { headers: fetchHeaders });
|
|
6790
6882
|
const result = await response.json();
|
|
6791
|
-
|
|
6883
|
+
logger.debug("[PWTK Debug] getSK API response:", result);
|
|
6792
6884
|
if (result.success && result.data) {
|
|
6793
6885
|
const num = String(result.data);
|
|
6794
|
-
|
|
6886
|
+
logger.debug("[PWTK Debug] getSK returned num:", num, "length:", num.length);
|
|
6795
6887
|
if (num.length >= 9) {
|
|
6796
6888
|
key = num.charAt(2) + num.charAt(5) + num.charAt(8);
|
|
6797
|
-
|
|
6889
|
+
logger.debug("[PWTK Debug] Extracted key from getSK:", key);
|
|
6798
6890
|
} else {
|
|
6799
|
-
|
|
6891
|
+
logger.debug("[PWTK Debug] getSK num too short:", num);
|
|
6800
6892
|
}
|
|
6801
6893
|
} else {
|
|
6802
|
-
|
|
6894
|
+
logger.debug("[PWTK Debug] getSK failed:", result);
|
|
6803
6895
|
}
|
|
6804
6896
|
} catch (e) {
|
|
6805
|
-
|
|
6897
|
+
logger.warn("[PWTK Debug] getSK API error:", e);
|
|
6806
6898
|
}
|
|
6807
6899
|
} else {
|
|
6808
|
-
|
|
6900
|
+
logger.debug("[PWTK Debug] No cid or autoFetchKeys disabled");
|
|
6809
6901
|
}
|
|
6810
6902
|
if (!key && this.decryptConfig.keyExtractor) {
|
|
6811
6903
|
key = this.decryptConfig.keyExtractor(headers);
|
|
6812
|
-
|
|
6904
|
+
logger.debug("[PWTK Debug] Key from custom extractor:", key);
|
|
6813
6905
|
} else if (!key) {
|
|
6814
6906
|
key = headers.decryptKey || headers.keys || headers.cid || "";
|
|
6815
|
-
|
|
6907
|
+
logger.debug("[PWTK Debug] Key from headers:", key, "from:", headers.decryptKey ? "decryptKey" : headers.keys ? "keys" : headers.cid ? "cid" : "none");
|
|
6816
6908
|
}
|
|
6817
6909
|
if (this.decryptConfig.slkExtractor) {
|
|
6818
6910
|
slk = this.decryptConfig.slkExtractor(headers);
|
|
6819
|
-
|
|
6911
|
+
logger.debug("[PWTK Debug] SLK from custom extractor:", slk);
|
|
6820
6912
|
} else {
|
|
6821
6913
|
slk = headers.decryptSlk || headers.slk || "";
|
|
6822
|
-
|
|
6914
|
+
logger.debug("[PWTK Debug] SLK from headers:", slk, "from:", headers.decryptSlk ? "decryptSlk" : headers.slk ? "slk" : "none");
|
|
6823
6915
|
}
|
|
6824
6916
|
const fullKey = key + slk;
|
|
6825
|
-
|
|
6917
|
+
logger.debug("[PWTK Debug] Full decrypt key:", fullKey ? `"${fullKey}" (length: ${fullKey.length})` : "empty");
|
|
6826
6918
|
if (fullKey) {
|
|
6827
6919
|
let dataToDecrypt = data;
|
|
6828
6920
|
let isWrappedData = false;
|
|
6829
6921
|
if (typeof data === "object" && data !== null && data.data && typeof data.data === "string") {
|
|
6830
|
-
|
|
6922
|
+
logger.debug('[PWTK Debug] Data is wrapped in {"data": "..."} format, extracting inner data');
|
|
6831
6923
|
dataToDecrypt = data.data;
|
|
6832
6924
|
isWrappedData = true;
|
|
6833
6925
|
} else if (typeof data === "string") {
|
|
6834
6926
|
try {
|
|
6835
6927
|
const parsed = JSON.parse(data);
|
|
6836
6928
|
if (parsed.data && typeof parsed.data === "string") {
|
|
6837
|
-
|
|
6929
|
+
logger.debug("[PWTK Debug] Data is JSON string with data field, extracting");
|
|
6838
6930
|
dataToDecrypt = parsed.data;
|
|
6839
6931
|
isWrappedData = true;
|
|
6840
6932
|
}
|
|
@@ -6842,32 +6934,32 @@ class NetworkInterceptor {
|
|
|
6842
6934
|
}
|
|
6843
6935
|
}
|
|
6844
6936
|
const dataStr = typeof dataToDecrypt === "string" ? dataToDecrypt : JSON.stringify(dataToDecrypt);
|
|
6845
|
-
|
|
6937
|
+
logger.debug("[PWTK Debug] Calling decrypt with:", {
|
|
6846
6938
|
dataLength: dataStr.length,
|
|
6847
6939
|
dataPreview: dataStr.substring(0, 50),
|
|
6848
6940
|
key: fullKey,
|
|
6849
6941
|
isWrapped: isWrappedData
|
|
6850
6942
|
});
|
|
6851
6943
|
const decrypted = decrypt(dataStr, fullKey);
|
|
6852
|
-
|
|
6944
|
+
logger.debug("[PWTK Debug] Decrypt result:", {
|
|
6853
6945
|
success: decrypted && decrypted !== dataStr,
|
|
6854
6946
|
decryptedType: typeof decrypted,
|
|
6855
6947
|
decryptedLength: decrypted ? typeof decrypted === "string" ? decrypted.length : JSON.stringify(decrypted).length : 0,
|
|
6856
6948
|
preview: decrypted ? typeof decrypted === "string" ? decrypted.substring(0, 100) : JSON.stringify(decrypted).substring(0, 100) : null
|
|
6857
6949
|
});
|
|
6858
6950
|
if (decrypted && decrypted !== dataStr) {
|
|
6859
|
-
|
|
6951
|
+
logger.debug("[PWTK Debug] ✅ Decryption successful! Result:", decrypted);
|
|
6860
6952
|
return decrypted;
|
|
6861
6953
|
} else {
|
|
6862
|
-
|
|
6954
|
+
logger.debug("[PWTK Debug] ❌ Decryption failed or returned same data");
|
|
6863
6955
|
}
|
|
6864
6956
|
} else {
|
|
6865
|
-
|
|
6957
|
+
logger.debug("[PWTK Debug] No key available, skipping decryption");
|
|
6866
6958
|
}
|
|
6867
6959
|
} catch (error) {
|
|
6868
|
-
|
|
6960
|
+
logger.error("[PWTK Debug] tryDecrypt error:", error);
|
|
6869
6961
|
}
|
|
6870
|
-
|
|
6962
|
+
logger.debug("[PWTK Debug] tryDecrypt returning null");
|
|
6871
6963
|
return null;
|
|
6872
6964
|
}
|
|
6873
6965
|
interceptXHR() {
|
|
@@ -6911,17 +7003,17 @@ class NetworkInterceptor {
|
|
|
6911
7003
|
if (decrypted !== null) {
|
|
6912
7004
|
requestData.decryptedRequest = decrypted;
|
|
6913
7005
|
self2.requests.set(requestId, requestData);
|
|
6914
|
-
|
|
7006
|
+
logger.debug("[PWTK Debug] Request decrypted, notifying UI");
|
|
6915
7007
|
self2.notifyListeners(requestData);
|
|
6916
7008
|
}
|
|
6917
|
-
}).catch((e) =>
|
|
7009
|
+
}).catch((e) => logger.warn("解密请求失败:", e));
|
|
6918
7010
|
}
|
|
6919
7011
|
self2.requests.set(requestId, requestData);
|
|
6920
7012
|
self2.notifyListeners(requestData);
|
|
6921
7013
|
return originalSend.call(this, body);
|
|
6922
7014
|
};
|
|
6923
7015
|
xhr.addEventListener("readystatechange", function() {
|
|
6924
|
-
|
|
7016
|
+
logger.debug("[PWTK Debug] XHR state changed:", {
|
|
6925
7017
|
readyState: xhr.readyState,
|
|
6926
7018
|
readyStateName: ["UNSENT", "OPENED", "HEADERS_RECEIVED", "LOADING", "DONE"][xhr.readyState],
|
|
6927
7019
|
status: xhr.status,
|
|
@@ -6929,7 +7021,7 @@ class NetworkInterceptor {
|
|
|
6929
7021
|
requestId,
|
|
6930
7022
|
url
|
|
6931
7023
|
});
|
|
6932
|
-
|
|
7024
|
+
logger.debug("[PWTK Debug] Checking response condition:", {
|
|
6933
7025
|
readyState: xhr.readyState,
|
|
6934
7026
|
isDone: xhr.readyState === 4,
|
|
6935
7027
|
XMLHttpRequestDONE: typeof XMLHttpRequest !== "undefined" ? XMLHttpRequest.DONE : "undefined",
|
|
@@ -6937,11 +7029,11 @@ class NetworkInterceptor {
|
|
|
6937
7029
|
shouldProcess: xhr.readyState === 4 && !isInternalRequest
|
|
6938
7030
|
});
|
|
6939
7031
|
if (xhr.readyState === 4 && !isInternalRequest) {
|
|
6940
|
-
|
|
7032
|
+
logger.debug("[PWTK Debug] XHR completed, processing response");
|
|
6941
7033
|
const endTime = Date.now();
|
|
6942
7034
|
const requestData = self2.requests.get(requestId);
|
|
6943
7035
|
if (requestData) {
|
|
6944
|
-
|
|
7036
|
+
logger.debug("[PWTK Debug] Found request data, updating with response");
|
|
6945
7037
|
requestData.status = xhr.status;
|
|
6946
7038
|
requestData.statusText = xhr.statusText;
|
|
6947
7039
|
requestData.duration = endTime - startTime;
|
|
@@ -6957,7 +7049,7 @@ class NetworkInterceptor {
|
|
|
6957
7049
|
}
|
|
6958
7050
|
requestData.responseHeaders = responseHeaders;
|
|
6959
7051
|
const hasResponseText = xhr.responseText !== null && xhr.responseText !== void 0 && xhr.responseText !== "";
|
|
6960
|
-
|
|
7052
|
+
logger.debug("[PWTK Debug] XHR Response received:", {
|
|
6961
7053
|
status: requestData.status,
|
|
6962
7054
|
hasResponseText,
|
|
6963
7055
|
responseTextLength: xhr.responseText?.length,
|
|
@@ -6966,16 +7058,16 @@ class NetworkInterceptor {
|
|
|
6966
7058
|
if (hasResponseText) {
|
|
6967
7059
|
try {
|
|
6968
7060
|
requestData.responseBody = JSON.parse(xhr.responseText);
|
|
6969
|
-
|
|
7061
|
+
logger.debug("[PWTK Debug] Response parsed as JSON:", requestData.responseBody);
|
|
6970
7062
|
} catch {
|
|
6971
7063
|
requestData.responseBody = xhr.responseText;
|
|
6972
|
-
|
|
7064
|
+
logger.debug("[PWTK Debug] Response kept as text");
|
|
6973
7065
|
}
|
|
6974
7066
|
} else {
|
|
6975
7067
|
requestData.responseBody = null;
|
|
6976
|
-
|
|
7068
|
+
logger.debug("[PWTK Debug] No response body");
|
|
6977
7069
|
}
|
|
6978
|
-
|
|
7070
|
+
logger.debug("[PWTK Debug] Updating request with response data");
|
|
6979
7071
|
self2.requests.set(requestId, requestData);
|
|
6980
7072
|
self2.notifyListeners(requestData);
|
|
6981
7073
|
if (requestData.responseBody) {
|
|
@@ -6983,13 +7075,13 @@ class NetworkInterceptor {
|
|
|
6983
7075
|
if (decrypted !== null) {
|
|
6984
7076
|
requestData.decryptedResponse = decrypted;
|
|
6985
7077
|
self2.requests.set(requestId, requestData);
|
|
6986
|
-
|
|
7078
|
+
logger.debug("[PWTK Debug] Response decrypted, notifying UI:", decrypted);
|
|
6987
7079
|
self2.notifyListeners(requestData);
|
|
6988
7080
|
}
|
|
6989
|
-
}).catch((e) =>
|
|
7081
|
+
}).catch((e) => logger.warn("解密响应失败:", e));
|
|
6990
7082
|
}
|
|
6991
7083
|
} else {
|
|
6992
|
-
|
|
7084
|
+
logger.debug("[PWTK Debug] WARNING: Request data not found for ID:", requestId);
|
|
6993
7085
|
}
|
|
6994
7086
|
}
|
|
6995
7087
|
});
|
|
@@ -7049,10 +7141,10 @@ class NetworkInterceptor {
|
|
|
7049
7141
|
if (decrypted !== null) {
|
|
7050
7142
|
requestData.decryptedRequest = decrypted;
|
|
7051
7143
|
self2.requests.set(requestId, requestData);
|
|
7052
|
-
|
|
7144
|
+
logger.debug("[PWTK Debug] Fetch request decrypted, notifying UI");
|
|
7053
7145
|
self2.notifyListeners(requestData);
|
|
7054
7146
|
}
|
|
7055
|
-
}).catch((e) =>
|
|
7147
|
+
}).catch((e) => logger.warn("解密请求失败:", e));
|
|
7056
7148
|
}
|
|
7057
7149
|
self2.requests.set(requestId, requestData);
|
|
7058
7150
|
self2.notifyListeners(requestData);
|
|
@@ -7072,7 +7164,7 @@ class NetworkInterceptor {
|
|
|
7072
7164
|
updatedRequestData.responseHeaders = responseHeaders;
|
|
7073
7165
|
try {
|
|
7074
7166
|
const responseText = await responseClone.text();
|
|
7075
|
-
|
|
7167
|
+
logger.debug("[PWTK Debug] Fetch Response received:", {
|
|
7076
7168
|
status: updatedRequestData.status,
|
|
7077
7169
|
textLength: responseText.length,
|
|
7078
7170
|
textPreview: responseText.substring(0, 100)
|
|
@@ -7092,10 +7184,10 @@ class NetworkInterceptor {
|
|
|
7092
7184
|
if (decrypted !== null) {
|
|
7093
7185
|
updatedRequestData.decryptedResponse = decrypted;
|
|
7094
7186
|
self2.requests.set(requestId, updatedRequestData);
|
|
7095
|
-
|
|
7187
|
+
logger.debug("[PWTK Debug] Fetch response decrypted, notifying UI:", decrypted);
|
|
7096
7188
|
self2.notifyListeners(updatedRequestData);
|
|
7097
7189
|
}
|
|
7098
|
-
}).catch((e) =>
|
|
7190
|
+
}).catch((e) => logger.warn("解密响应失败:", e));
|
|
7099
7191
|
}
|
|
7100
7192
|
} catch (error) {
|
|
7101
7193
|
updatedRequestData.error = `Failed to read response: ${error}`;
|
|
@@ -7124,14 +7216,14 @@ class WasmLoader {
|
|
|
7124
7216
|
this.loading = false;
|
|
7125
7217
|
}
|
|
7126
7218
|
async loadWasm(wasmUrl, jsUrl) {
|
|
7127
|
-
|
|
7128
|
-
|
|
7219
|
+
logger.debug("[PWTK WASM] loadWasm called");
|
|
7220
|
+
logger.debug("[PWTK WASM] Current state:", {
|
|
7129
7221
|
hasWindowDecrypt: typeof window.decrypt === "function",
|
|
7130
7222
|
hasWindowEncrypt: typeof window.encrypt === "function",
|
|
7131
7223
|
hasWindowGo: typeof window.Go !== "undefined"
|
|
7132
7224
|
});
|
|
7133
7225
|
if (typeof window.decrypt === "function") {
|
|
7134
|
-
|
|
7226
|
+
logger.debug("[PWTK WASM] window.decrypt already exists, skipping WASM load");
|
|
7135
7227
|
this.loaded = true;
|
|
7136
7228
|
return true;
|
|
7137
7229
|
}
|
|
@@ -7170,11 +7262,11 @@ class WasmLoader {
|
|
|
7170
7262
|
await this.loadScript(jsPath);
|
|
7171
7263
|
if (typeof window.Go !== "undefined") {
|
|
7172
7264
|
jsLoaded = true;
|
|
7173
|
-
|
|
7265
|
+
logger.debug("[PWTK WASM] wasm_exec.js loaded successfully from:", jsPath);
|
|
7174
7266
|
break;
|
|
7175
7267
|
}
|
|
7176
7268
|
} catch (e) {
|
|
7177
|
-
|
|
7269
|
+
logger.warn("NetworkDebugger: 尝试加载", jsPath, "失败:", e);
|
|
7178
7270
|
continue;
|
|
7179
7271
|
}
|
|
7180
7272
|
}
|
|
@@ -7194,23 +7286,23 @@ class WasmLoader {
|
|
|
7194
7286
|
fetch(wasmPath),
|
|
7195
7287
|
go.importObject
|
|
7196
7288
|
);
|
|
7197
|
-
|
|
7289
|
+
logger.info("NetworkDebugger: WebAssembly 加载成功:", wasmPath);
|
|
7198
7290
|
break;
|
|
7199
7291
|
} catch (streamError) {
|
|
7200
|
-
|
|
7292
|
+
logger.warn("instantiateStreaming 失败,尝试传统方式:", streamError);
|
|
7201
7293
|
const wasmBuffer = await fetch(wasmPath).then((response) => response.arrayBuffer());
|
|
7202
7294
|
wasmModule = await WebAssembly.instantiate(wasmBuffer, go.importObject);
|
|
7203
|
-
|
|
7295
|
+
logger.info("NetworkDebugger: WebAssembly 加载成功(传统方式):", wasmPath);
|
|
7204
7296
|
break;
|
|
7205
7297
|
}
|
|
7206
7298
|
} else {
|
|
7207
7299
|
const wasmBuffer = await fetch(wasmPath).then((response) => response.arrayBuffer());
|
|
7208
7300
|
wasmModule = await WebAssembly.instantiate(wasmBuffer, go.importObject);
|
|
7209
|
-
|
|
7301
|
+
logger.info("NetworkDebugger: WebAssembly 加载成功(传统方式):", wasmPath);
|
|
7210
7302
|
break;
|
|
7211
7303
|
}
|
|
7212
7304
|
} catch (error) {
|
|
7213
|
-
|
|
7305
|
+
logger.warn("NetworkDebugger: 尝试加载", wasmPath, "失败:", error);
|
|
7214
7306
|
continue;
|
|
7215
7307
|
}
|
|
7216
7308
|
}
|
|
@@ -7219,25 +7311,25 @@ class WasmLoader {
|
|
|
7219
7311
|
}
|
|
7220
7312
|
go.run(wasmModule.instance);
|
|
7221
7313
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
7222
|
-
|
|
7314
|
+
logger.debug("[PWTK WASM] After WASM load, checking functions:", {
|
|
7223
7315
|
hasDecrypt: typeof window.decrypt === "function",
|
|
7224
7316
|
hasEncrypt: typeof window.encrypt === "function",
|
|
7225
7317
|
windowKeys: Object.keys(window).filter((k) => k.includes("crypt"))
|
|
7226
7318
|
});
|
|
7227
7319
|
if (typeof window.decrypt === "function") {
|
|
7228
7320
|
this.loaded = true;
|
|
7229
|
-
|
|
7321
|
+
logger.debug("[PWTK WASM] ✅ WebAssembly loaded successfully, decrypt function available");
|
|
7230
7322
|
return true;
|
|
7231
7323
|
} else {
|
|
7232
|
-
|
|
7324
|
+
logger.warn("[PWTK WASM] ❌ WebAssembly loaded but decrypt function not available");
|
|
7233
7325
|
return false;
|
|
7234
7326
|
}
|
|
7235
7327
|
} catch (error) {
|
|
7236
|
-
|
|
7328
|
+
logger.error("[PWTK WASM] WebAssembly loading failed:", error);
|
|
7237
7329
|
return false;
|
|
7238
7330
|
} finally {
|
|
7239
7331
|
this.loading = false;
|
|
7240
|
-
|
|
7332
|
+
logger.debug("[PWTK WASM] Load complete, final state:", {
|
|
7241
7333
|
loaded: this.loaded,
|
|
7242
7334
|
hasDecrypt: typeof window.decrypt === "function"
|
|
7243
7335
|
});
|
|
@@ -7900,13 +7992,13 @@ async function createShareLink(requestData) {
|
|
|
7900
7992
|
const result = await response.json();
|
|
7901
7993
|
if (result.shareId) {
|
|
7902
7994
|
const shareUrl = `https://curl.bwg.leeguoo.com/share/${result.shareId}`;
|
|
7903
|
-
|
|
7995
|
+
logger.info(`🔗 分享链接创建成功 (by Leo): ${shareUrl}`);
|
|
7904
7996
|
return shareUrl;
|
|
7905
7997
|
} else {
|
|
7906
7998
|
throw new Error(result.error || "创建分享失败");
|
|
7907
7999
|
}
|
|
7908
8000
|
} catch (error) {
|
|
7909
|
-
|
|
8001
|
+
logger.error("NetworkDebugger: 创建分享链接失败:", error);
|
|
7910
8002
|
throw error;
|
|
7911
8003
|
}
|
|
7912
8004
|
}
|
|
@@ -7927,7 +8019,7 @@ async function copyToClipboard(text) {
|
|
|
7927
8019
|
return success;
|
|
7928
8020
|
}
|
|
7929
8021
|
} catch (error) {
|
|
7930
|
-
|
|
8022
|
+
logger.error("复制到剪贴板失败:", error);
|
|
7931
8023
|
return false;
|
|
7932
8024
|
}
|
|
7933
8025
|
}
|
|
@@ -7966,6 +8058,7 @@ class DebugPanel {
|
|
|
7966
8058
|
this.createPanel();
|
|
7967
8059
|
this.bindEvents();
|
|
7968
8060
|
this.startListening();
|
|
8061
|
+
logger.setPanel(this);
|
|
7969
8062
|
}
|
|
7970
8063
|
createPanel() {
|
|
7971
8064
|
if (!document.getElementById("network-debugger-styles")) {
|
|
@@ -8024,7 +8117,7 @@ class DebugPanel {
|
|
|
8024
8117
|
<div class="about-panel" data-panel="about" style="display: none;">
|
|
8025
8118
|
<div style="padding: 20px; color: #fff; text-align: center;">
|
|
8026
8119
|
<h2 style="margin: 0 0 20px 0;">🔓 PWTK 解密小工具</h2>
|
|
8027
|
-
<p style="margin: 10px 0;">Version: 1.2.
|
|
8120
|
+
<p style="margin: 10px 0;">Version: 1.2.20</p>
|
|
8028
8121
|
<p style="margin: 10px 0;">👨💻 Created by <strong>Leo (@leeguoo)</strong></p>
|
|
8029
8122
|
<p style="margin: 10px 0;">📧 技术支持:请联系 Leo</p>
|
|
8030
8123
|
<p style="margin: 10px 0;">🌐 分享服务:curl.bwg.leeguoo.com</p>
|
|
@@ -8123,7 +8216,7 @@ class DebugPanel {
|
|
|
8123
8216
|
this.renderRequests();
|
|
8124
8217
|
}
|
|
8125
8218
|
addRequestToUI(request) {
|
|
8126
|
-
|
|
8219
|
+
logger.debug("[PWTK UI] Adding/updating request:", {
|
|
8127
8220
|
id: request.id,
|
|
8128
8221
|
url: request.url,
|
|
8129
8222
|
hasResponse: !!request.responseBody,
|
|
@@ -8353,7 +8446,7 @@ Created by Leo (@leeguoo)`);
|
|
|
8353
8446
|
throw new Error("无法创建分享链接");
|
|
8354
8447
|
}
|
|
8355
8448
|
} catch (error) {
|
|
8356
|
-
|
|
8449
|
+
logger.error("分享失败:", error);
|
|
8357
8450
|
this.logToConsole(`❌ 分享失败: ${error}`);
|
|
8358
8451
|
alert("分享失败,请稍后重试");
|
|
8359
8452
|
}
|
|
@@ -8596,7 +8689,7 @@ class NetworkDebugger {
|
|
|
8596
8689
|
}
|
|
8597
8690
|
async init(config = {}) {
|
|
8598
8691
|
if (this.initialized) {
|
|
8599
|
-
|
|
8692
|
+
logger.warn("NetworkDebugger already initialized");
|
|
8600
8693
|
return;
|
|
8601
8694
|
}
|
|
8602
8695
|
this.config = {
|
|
@@ -8615,20 +8708,29 @@ class NetworkDebugger {
|
|
|
8615
8708
|
keyApiUrl: "https://gw-card-pay.buyacard.cc/ip/getSK",
|
|
8616
8709
|
...config.decrypt
|
|
8617
8710
|
},
|
|
8711
|
+
log: {
|
|
8712
|
+
toBrowserConsole: false,
|
|
8713
|
+
level: "info",
|
|
8714
|
+
...config.log
|
|
8715
|
+
},
|
|
8618
8716
|
...config
|
|
8619
8717
|
};
|
|
8718
|
+
logger.configure({
|
|
8719
|
+
enableBrowserConsole: this.config.log?.toBrowserConsole || false,
|
|
8720
|
+
logLevel: this.config.log?.level || "info"
|
|
8721
|
+
});
|
|
8620
8722
|
try {
|
|
8621
8723
|
if (this.config.wasm?.enabled !== false) {
|
|
8622
|
-
|
|
8724
|
+
logger.info("[PWTK Init] Starting WASM initialization");
|
|
8623
8725
|
this.wasmLoader = new WasmLoader();
|
|
8624
8726
|
const wasmLoaded = await this.wasmLoader.loadWasm(this.config.wasm?.wasmUrl, this.config.wasm?.jsUrl);
|
|
8625
8727
|
if (wasmLoaded) {
|
|
8626
|
-
|
|
8728
|
+
logger.info("[PWTK Init] ✅ WASM decrypt function ready");
|
|
8627
8729
|
} else {
|
|
8628
|
-
|
|
8730
|
+
logger.warn("[PWTK Init] ⚠️ WASM load failed or decrypt function unavailable, will rely on page-provided decryption");
|
|
8629
8731
|
}
|
|
8630
8732
|
} else {
|
|
8631
|
-
|
|
8733
|
+
logger.info("[PWTK Init] WASM disabled in config");
|
|
8632
8734
|
}
|
|
8633
8735
|
this.interceptor = new NetworkInterceptor();
|
|
8634
8736
|
if (this.config.decrypt?.enabled) {
|
|
@@ -8643,23 +8745,23 @@ class NetworkDebugger {
|
|
|
8643
8745
|
this.createPanel();
|
|
8644
8746
|
}
|
|
8645
8747
|
this.initialized = true;
|
|
8646
|
-
|
|
8748
|
+
logger.consoleDirect(`
|
|
8647
8749
|
╔════════════════════════════════════════╗
|
|
8648
|
-
║ 🔓 PWTK 解密小工具 v1.2.
|
|
8750
|
+
║ 🔓 PWTK 解密小工具 v1.2.20 ║
|
|
8649
8751
|
║ Created by Leo (@leeguoo) ║
|
|
8650
8752
|
║ 技术支持: 请联系 Leo ║
|
|
8651
8753
|
║ 分享服务: curl.bwg.leeguoo.com ║
|
|
8652
8754
|
╚════════════════════════════════════════╝
|
|
8653
8755
|
`);
|
|
8654
|
-
|
|
8756
|
+
logger.info("🔍 NetworkDebugger initialized successfully");
|
|
8655
8757
|
} catch (error) {
|
|
8656
|
-
|
|
8758
|
+
logger.error("NetworkDebugger initialization failed:", error);
|
|
8657
8759
|
throw error;
|
|
8658
8760
|
}
|
|
8659
8761
|
}
|
|
8660
8762
|
show() {
|
|
8661
8763
|
if (!this.initialized) {
|
|
8662
|
-
|
|
8764
|
+
logger.error("NetworkDebugger not initialized. Call init() first.");
|
|
8663
8765
|
return;
|
|
8664
8766
|
}
|
|
8665
8767
|
if (!this.panel) {
|
|
@@ -8679,7 +8781,7 @@ class NetworkDebugger {
|
|
|
8679
8781
|
this.panel = null;
|
|
8680
8782
|
}
|
|
8681
8783
|
this.initialized = false;
|
|
8682
|
-
|
|
8784
|
+
logger.info("NetworkDebugger destroyed");
|
|
8683
8785
|
}
|
|
8684
8786
|
getRequests() {
|
|
8685
8787
|
return this.interceptor?.getRequests() || [];
|
|
@@ -8711,7 +8813,7 @@ class NetworkDebugger {
|
|
|
8711
8813
|
}
|
|
8712
8814
|
createPanel() {
|
|
8713
8815
|
if (!this.interceptor) {
|
|
8714
|
-
|
|
8816
|
+
logger.error("Cannot create panel: interceptor not initialized");
|
|
8715
8817
|
return;
|
|
8716
8818
|
}
|
|
8717
8819
|
this.panel = new DebugPanel(this.interceptor, {
|
|
@@ -8732,7 +8834,7 @@ let globalInstance = null;
|
|
|
8732
8834
|
const NetworkDebuggerGlobal = {
|
|
8733
8835
|
async init(config) {
|
|
8734
8836
|
if (globalInstance) {
|
|
8735
|
-
|
|
8837
|
+
logger.warn("NetworkDebugger already has a global instance");
|
|
8736
8838
|
return globalInstance;
|
|
8737
8839
|
}
|
|
8738
8840
|
globalInstance = await NetworkDebugger.create(config);
|