@skrillex1224/playwright-toolkit 2.0.75 → 2.0.77
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 +90 -78
- package/dist/index.cjs.map +2 -2
- package/dist/index.js +90 -78
- package/dist/index.js.map +2 -2
- package/index.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1097,7 +1097,7 @@ var Sse = {
|
|
|
1097
1097
|
onEnd,
|
|
1098
1098
|
onTimeout,
|
|
1099
1099
|
initialTimeout = 9e4,
|
|
1100
|
-
|
|
1100
|
+
overallTimeout = 18e4
|
|
1101
1101
|
} = options;
|
|
1102
1102
|
let initialTimer = null;
|
|
1103
1103
|
let overallTimer = null;
|
|
@@ -1109,82 +1109,87 @@ var Sse = {
|
|
|
1109
1109
|
overallTimer = null;
|
|
1110
1110
|
};
|
|
1111
1111
|
const workPromise = new Promise(async (resolve, reject) => {
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1112
|
+
try {
|
|
1113
|
+
await page.route(urlPattern, async (route) => {
|
|
1114
|
+
const request = route.request();
|
|
1115
|
+
logger8.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${request.url()}`);
|
|
1116
|
+
try {
|
|
1117
|
+
const headers = await request.allHeaders();
|
|
1118
|
+
const postData = request.postData();
|
|
1119
|
+
const urlObj = new import_url.URL(request.url());
|
|
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: overallTimeout
|
|
1129
|
+
};
|
|
1130
|
+
const req = import_https.default.request(reqOptions, (res) => {
|
|
1131
|
+
const chunks = [];
|
|
1132
|
+
let accumulatedText = "";
|
|
1133
|
+
res.on("data", (chunk) => {
|
|
1134
|
+
if (!hasReceivedInitialData) {
|
|
1135
|
+
hasReceivedInitialData = true;
|
|
1136
|
+
if (initialTimer) {
|
|
1137
|
+
clearTimeout(initialTimer);
|
|
1138
|
+
initialTimer = null;
|
|
1139
|
+
}
|
|
1140
|
+
logger8.debug("[Intercept] \u5DF2\u63A5\u6536\u521D\u59CB\u6570\u636E");
|
|
1141
|
+
}
|
|
1142
|
+
chunks.push(chunk);
|
|
1143
|
+
const textChunk = chunk.toString("utf-8");
|
|
1144
|
+
accumulatedText += textChunk;
|
|
1145
|
+
if (onData) {
|
|
1146
|
+
try {
|
|
1147
|
+
onData(textChunk, resolve, accumulatedText);
|
|
1148
|
+
} catch (e) {
|
|
1149
|
+
logger8.fail(`onData \u9519\u8BEF`, e);
|
|
1150
|
+
}
|
|
1139
1151
|
}
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1152
|
+
});
|
|
1153
|
+
res.on("end", () => {
|
|
1154
|
+
logger8.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F");
|
|
1155
|
+
clearAllTimers();
|
|
1156
|
+
if (onEnd) {
|
|
1157
|
+
try {
|
|
1158
|
+
onEnd(accumulatedText, resolve);
|
|
1159
|
+
} catch (e) {
|
|
1160
|
+
logger8.fail(`onEnd \u9519\u8BEF`, e);
|
|
1161
|
+
}
|
|
1162
|
+
} else if (!onData) {
|
|
1163
|
+
resolve(accumulatedText);
|
|
1151
1164
|
}
|
|
1152
|
-
|
|
1165
|
+
route.fulfill({
|
|
1166
|
+
status: res.statusCode,
|
|
1167
|
+
headers: res.headers,
|
|
1168
|
+
body: Buffer.concat(chunks)
|
|
1169
|
+
}).catch(() => {
|
|
1170
|
+
});
|
|
1171
|
+
});
|
|
1153
1172
|
});
|
|
1154
|
-
|
|
1155
|
-
logger8.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F (Stream End)");
|
|
1173
|
+
req.on("error", (e) => {
|
|
1156
1174
|
clearAllTimers();
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
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}`));
|
|
1175
|
+
route.abort().catch(() => {
|
|
1176
|
+
});
|
|
1177
|
+
reject(e);
|
|
1172
1178
|
});
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1179
|
+
if (postData) req.write(postData);
|
|
1180
|
+
req.end();
|
|
1181
|
+
} catch (e) {
|
|
1176
1182
|
clearAllTimers();
|
|
1177
|
-
route.
|
|
1183
|
+
route.continue().catch(() => {
|
|
1184
|
+
});
|
|
1178
1185
|
reject(e);
|
|
1179
|
-
}
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
}
|
|
1187
|
-
});
|
|
1186
|
+
}
|
|
1187
|
+
});
|
|
1188
|
+
} catch (e) {
|
|
1189
|
+
reject(e);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
workPromise.catch(() => {
|
|
1188
1193
|
});
|
|
1189
1194
|
const timeoutPromise = new Promise((_, reject) => {
|
|
1190
1195
|
initialTimer = setTimeout(() => {
|
|
@@ -1192,26 +1197,33 @@ var Sse = {
|
|
|
1192
1197
|
const error = new InitialTimeoutError(initialTimeout);
|
|
1193
1198
|
clearAllTimers();
|
|
1194
1199
|
if (onTimeout) {
|
|
1195
|
-
|
|
1200
|
+
try {
|
|
1201
|
+
onTimeout(error, reject);
|
|
1202
|
+
} catch (e) {
|
|
1203
|
+
reject(e);
|
|
1204
|
+
}
|
|
1196
1205
|
} else {
|
|
1197
|
-
logger8.fail(`[Intercept] \u521D\u59CB\u6570\u636E\u63A5\u6536\u8D85\u65F6`, error);
|
|
1198
1206
|
reject(error);
|
|
1199
1207
|
}
|
|
1200
1208
|
}
|
|
1201
1209
|
}, initialTimeout);
|
|
1202
1210
|
overallTimer = setTimeout(() => {
|
|
1203
|
-
const error = new OverallTimeoutError(
|
|
1211
|
+
const error = new OverallTimeoutError(overallTimeout);
|
|
1204
1212
|
clearAllTimers();
|
|
1205
1213
|
if (onTimeout) {
|
|
1206
|
-
|
|
1214
|
+
try {
|
|
1215
|
+
onTimeout(error, reject);
|
|
1216
|
+
} catch (e) {
|
|
1217
|
+
reject(e);
|
|
1218
|
+
}
|
|
1207
1219
|
} else {
|
|
1208
|
-
logger8.fail(`[Intercept] \u6574\u4F53\u8BF7\u6C42\u8D85\u65F6`, error);
|
|
1209
1220
|
reject(error);
|
|
1210
1221
|
}
|
|
1211
|
-
},
|
|
1222
|
+
}, overallTimeout);
|
|
1223
|
+
});
|
|
1224
|
+
timeoutPromise.catch(() => {
|
|
1212
1225
|
});
|
|
1213
|
-
|
|
1214
|
-
return racePromise;
|
|
1226
|
+
return Promise.race([workPromise, timeoutPromise]);
|
|
1215
1227
|
}
|
|
1216
1228
|
};
|
|
1217
1229
|
|