@skrillex1224/playwright-toolkit 2.0.70 → 2.0.72
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 +101 -107
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +101 -107
- package/dist/index.js.map +2 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1099,127 +1099,121 @@ var Sse = {
|
|
|
1099
1099
|
firstDataTimeout = 9e4,
|
|
1100
1100
|
timeout = 18e4
|
|
1101
1101
|
} = options;
|
|
1102
|
-
let streamResolve, streamReject;
|
|
1103
|
-
const capturePromise = new Promise((resolve, reject) => {
|
|
1104
|
-
streamResolve = resolve;
|
|
1105
|
-
streamReject = reject;
|
|
1106
|
-
});
|
|
1107
|
-
capturePromise.catch(() => {
|
|
1108
|
-
});
|
|
1109
1102
|
let firstDataTimer = null;
|
|
1110
1103
|
let overallTimer = null;
|
|
1111
1104
|
let hasReceivedFirstData = false;
|
|
1112
1105
|
const clearAllTimers = () => {
|
|
1113
|
-
if (firstDataTimer)
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
if (overallTimer) {
|
|
1118
|
-
clearTimeout(overallTimer);
|
|
1119
|
-
overallTimer = null;
|
|
1120
|
-
}
|
|
1106
|
+
if (firstDataTimer) clearTimeout(firstDataTimer);
|
|
1107
|
+
if (overallTimer) clearTimeout(overallTimer);
|
|
1108
|
+
firstDataTimer = null;
|
|
1109
|
+
overallTimer = null;
|
|
1121
1110
|
};
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
const
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
delete headers["accept-encoding"];
|
|
1153
|
-
delete headers["content-length"];
|
|
1154
|
-
const reqOptions = {
|
|
1155
|
-
hostname: urlObj.hostname,
|
|
1156
|
-
port: 443,
|
|
1157
|
-
path: urlObj.pathname + urlObj.search,
|
|
1158
|
-
method: request.method(),
|
|
1159
|
-
headers,
|
|
1160
|
-
timeout
|
|
1161
|
-
};
|
|
1162
|
-
const req = import_https.default.request(reqOptions, (res) => {
|
|
1163
|
-
const chunks = [];
|
|
1164
|
-
let accumulatedText = "";
|
|
1165
|
-
res.on("data", (chunk) => {
|
|
1166
|
-
if (!hasReceivedFirstData) {
|
|
1167
|
-
hasReceivedFirstData = true;
|
|
1168
|
-
if (firstDataTimer) {
|
|
1169
|
-
clearTimeout(firstDataTimer);
|
|
1170
|
-
firstDataTimer = null;
|
|
1111
|
+
const workPromise = new Promise(async (resolve, reject) => {
|
|
1112
|
+
await page.route(urlPattern, async (route) => {
|
|
1113
|
+
const request = route.request();
|
|
1114
|
+
const requestUrl = request.url();
|
|
1115
|
+
logger8.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${requestUrl}`);
|
|
1116
|
+
try {
|
|
1117
|
+
const headers = await request.allHeaders();
|
|
1118
|
+
const postData = request.postData();
|
|
1119
|
+
const urlObj = new import_url.URL(requestUrl);
|
|
1120
|
+
delete headers["accept-encoding"];
|
|
1121
|
+
delete headers["content-length"];
|
|
1122
|
+
const reqOptions = {
|
|
1123
|
+
hostname: urlObj.hostname,
|
|
1124
|
+
port: 443,
|
|
1125
|
+
path: urlObj.pathname + urlObj.search,
|
|
1126
|
+
method: request.method(),
|
|
1127
|
+
headers,
|
|
1128
|
+
timeout
|
|
1129
|
+
};
|
|
1130
|
+
const req = import_https.default.request(reqOptions, (res) => {
|
|
1131
|
+
const chunks = [];
|
|
1132
|
+
let accumulatedText = "";
|
|
1133
|
+
res.on("data", (chunk) => {
|
|
1134
|
+
if (!hasReceivedFirstData) {
|
|
1135
|
+
hasReceivedFirstData = true;
|
|
1136
|
+
if (firstDataTimer) {
|
|
1137
|
+
clearTimeout(firstDataTimer);
|
|
1138
|
+
firstDataTimer = null;
|
|
1139
|
+
}
|
|
1140
|
+
logger8.debug("[Intercept] \u5DF2\u63A5\u6536\u9996\u6B21\u6570\u636E");
|
|
1171
1141
|
}
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
logger8.fail(`onData callback error: ${e.message}`, e);
|
|
1142
|
+
chunks.push(chunk);
|
|
1143
|
+
const textChunk = chunk.toString("utf-8");
|
|
1144
|
+
accumulatedText += textChunk;
|
|
1145
|
+
logger8.debug(`[CHUNK] ${textChunk.length} bytes`);
|
|
1146
|
+
if (onData) {
|
|
1147
|
+
try {
|
|
1148
|
+
onData(textChunk, resolve, accumulatedText);
|
|
1149
|
+
} catch (e) {
|
|
1150
|
+
logger8.fail(`onData callback error: ${e.message}`, e);
|
|
1151
|
+
}
|
|
1183
1152
|
}
|
|
1184
|
-
}
|
|
1153
|
+
});
|
|
1154
|
+
res.on("end", () => {
|
|
1155
|
+
logger8.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F (Stream End)");
|
|
1156
|
+
clearAllTimers();
|
|
1157
|
+
const fullBody = Buffer.concat(chunks);
|
|
1158
|
+
if (onEnd) {
|
|
1159
|
+
try {
|
|
1160
|
+
onEnd(accumulatedText, resolve);
|
|
1161
|
+
} catch (e) {
|
|
1162
|
+
logger8.fail(`onEnd callback error: ${e.message}`, e);
|
|
1163
|
+
}
|
|
1164
|
+
} else if (!onData) {
|
|
1165
|
+
resolve(accumulatedText);
|
|
1166
|
+
}
|
|
1167
|
+
route.fulfill({
|
|
1168
|
+
status: res.statusCode,
|
|
1169
|
+
headers: res.headers,
|
|
1170
|
+
body: fullBody
|
|
1171
|
+
}).catch((e) => logger8.warn(`Route fulfill failed: ${e.message}`));
|
|
1172
|
+
});
|
|
1185
1173
|
});
|
|
1186
|
-
|
|
1187
|
-
logger8.
|
|
1174
|
+
req.on("error", (e) => {
|
|
1175
|
+
logger8.fail(`[MITM] Upstream request error: ${e.message}`, e);
|
|
1188
1176
|
clearAllTimers();
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
try {
|
|
1192
|
-
onEnd(accumulatedText, streamResolve);
|
|
1193
|
-
} catch (e) {
|
|
1194
|
-
logger8.fail(`onEnd callback error: ${e.message}`, e);
|
|
1195
|
-
}
|
|
1196
|
-
} else if (!onData) {
|
|
1197
|
-
streamResolve(accumulatedText);
|
|
1198
|
-
}
|
|
1199
|
-
route.fulfill({
|
|
1200
|
-
status: res.statusCode,
|
|
1201
|
-
headers: res.headers,
|
|
1202
|
-
body: fullBody
|
|
1203
|
-
}).catch((e) => logger8.warn(`Route fulfill failed: ${e.message}`));
|
|
1177
|
+
route.abort();
|
|
1178
|
+
reject(e);
|
|
1204
1179
|
});
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1180
|
+
if (postData) req.write(postData);
|
|
1181
|
+
req.end();
|
|
1182
|
+
} catch (e) {
|
|
1183
|
+
logger8.fail(`[MITM] Setup error: ${e.message}`, e);
|
|
1208
1184
|
clearAllTimers();
|
|
1209
|
-
route.
|
|
1210
|
-
streamReject(e);
|
|
1211
|
-
});
|
|
1212
|
-
if (postData) {
|
|
1213
|
-
req.write(postData);
|
|
1185
|
+
route.continue();
|
|
1214
1186
|
}
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1187
|
+
});
|
|
1188
|
+
});
|
|
1189
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
1190
|
+
firstDataTimer = setTimeout(() => {
|
|
1191
|
+
if (!hasReceivedFirstData) {
|
|
1192
|
+
const error = new FirstDataTimeoutError(firstDataTimeout);
|
|
1193
|
+
clearAllTimers();
|
|
1194
|
+
if (onTimeout) {
|
|
1195
|
+
onTimeout(error, reject);
|
|
1196
|
+
} else {
|
|
1197
|
+
logger8.fail(`[Intercept] \u9996\u6B21\u6570\u636E\u63A5\u6536\u8D85\u65F6`, error);
|
|
1198
|
+
reject(error);
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
}, firstDataTimeout);
|
|
1202
|
+
overallTimer = setTimeout(() => {
|
|
1203
|
+
const error = new OverallTimeoutError(timeout);
|
|
1218
1204
|
clearAllTimers();
|
|
1219
|
-
|
|
1220
|
-
|
|
1205
|
+
if (onTimeout) {
|
|
1206
|
+
onTimeout(error, reject);
|
|
1207
|
+
} else {
|
|
1208
|
+
logger8.fail(`[Intercept] \u6574\u4F53\u8BF7\u6C42\u8D85\u65F6`, error);
|
|
1209
|
+
reject(error);
|
|
1210
|
+
}
|
|
1211
|
+
}, timeout);
|
|
1212
|
+
});
|
|
1213
|
+
const racePromise = Promise.race([workPromise, timeoutPromise]);
|
|
1214
|
+
racePromise.catch(() => {
|
|
1221
1215
|
});
|
|
1222
|
-
return
|
|
1216
|
+
return racePromise;
|
|
1223
1217
|
}
|
|
1224
1218
|
};
|
|
1225
1219
|
|