@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.js
CHANGED
|
@@ -1068,7 +1068,7 @@ var Sse = {
|
|
|
1068
1068
|
onEnd,
|
|
1069
1069
|
onTimeout,
|
|
1070
1070
|
initialTimeout = 9e4,
|
|
1071
|
-
|
|
1071
|
+
overallTimeout = 18e4
|
|
1072
1072
|
} = options;
|
|
1073
1073
|
let initialTimer = null;
|
|
1074
1074
|
let overallTimer = null;
|
|
@@ -1080,82 +1080,87 @@ var Sse = {
|
|
|
1080
1080
|
overallTimer = null;
|
|
1081
1081
|
};
|
|
1082
1082
|
const workPromise = new Promise(async (resolve, reject) => {
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1083
|
+
try {
|
|
1084
|
+
await page.route(urlPattern, async (route) => {
|
|
1085
|
+
const request = route.request();
|
|
1086
|
+
logger8.info(`[MITM] \u5DF2\u62E6\u622A\u8BF7\u6C42: ${request.url()}`);
|
|
1087
|
+
try {
|
|
1088
|
+
const headers = await request.allHeaders();
|
|
1089
|
+
const postData = request.postData();
|
|
1090
|
+
const urlObj = new URL(request.url());
|
|
1091
|
+
delete headers["accept-encoding"];
|
|
1092
|
+
delete headers["content-length"];
|
|
1093
|
+
const reqOptions = {
|
|
1094
|
+
hostname: urlObj.hostname,
|
|
1095
|
+
port: 443,
|
|
1096
|
+
path: urlObj.pathname + urlObj.search,
|
|
1097
|
+
method: request.method(),
|
|
1098
|
+
headers,
|
|
1099
|
+
timeout: overallTimeout
|
|
1100
|
+
};
|
|
1101
|
+
const req = https.request(reqOptions, (res) => {
|
|
1102
|
+
const chunks = [];
|
|
1103
|
+
let accumulatedText = "";
|
|
1104
|
+
res.on("data", (chunk) => {
|
|
1105
|
+
if (!hasReceivedInitialData) {
|
|
1106
|
+
hasReceivedInitialData = true;
|
|
1107
|
+
if (initialTimer) {
|
|
1108
|
+
clearTimeout(initialTimer);
|
|
1109
|
+
initialTimer = null;
|
|
1110
|
+
}
|
|
1111
|
+
logger8.debug("[Intercept] \u5DF2\u63A5\u6536\u521D\u59CB\u6570\u636E");
|
|
1112
|
+
}
|
|
1113
|
+
chunks.push(chunk);
|
|
1114
|
+
const textChunk = chunk.toString("utf-8");
|
|
1115
|
+
accumulatedText += textChunk;
|
|
1116
|
+
if (onData) {
|
|
1117
|
+
try {
|
|
1118
|
+
onData(textChunk, resolve, accumulatedText);
|
|
1119
|
+
} catch (e) {
|
|
1120
|
+
logger8.fail(`onData \u9519\u8BEF`, e);
|
|
1121
|
+
}
|
|
1110
1122
|
}
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1123
|
+
});
|
|
1124
|
+
res.on("end", () => {
|
|
1125
|
+
logger8.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F");
|
|
1126
|
+
clearAllTimers();
|
|
1127
|
+
if (onEnd) {
|
|
1128
|
+
try {
|
|
1129
|
+
onEnd(accumulatedText, resolve);
|
|
1130
|
+
} catch (e) {
|
|
1131
|
+
logger8.fail(`onEnd \u9519\u8BEF`, e);
|
|
1132
|
+
}
|
|
1133
|
+
} else if (!onData) {
|
|
1134
|
+
resolve(accumulatedText);
|
|
1122
1135
|
}
|
|
1123
|
-
|
|
1136
|
+
route.fulfill({
|
|
1137
|
+
status: res.statusCode,
|
|
1138
|
+
headers: res.headers,
|
|
1139
|
+
body: Buffer.concat(chunks)
|
|
1140
|
+
}).catch(() => {
|
|
1141
|
+
});
|
|
1142
|
+
});
|
|
1124
1143
|
});
|
|
1125
|
-
|
|
1126
|
-
logger8.info("[MITM] \u4E0A\u6E38\u54CD\u5E94\u7ED3\u675F (Stream End)");
|
|
1144
|
+
req.on("error", (e) => {
|
|
1127
1145
|
clearAllTimers();
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
onEnd(accumulatedText, resolve);
|
|
1132
|
-
} catch (e) {
|
|
1133
|
-
logger8.fail(`onEnd callback error: ${e.message}`, e);
|
|
1134
|
-
}
|
|
1135
|
-
} else if (!onData) {
|
|
1136
|
-
resolve(accumulatedText);
|
|
1137
|
-
}
|
|
1138
|
-
route.fulfill({
|
|
1139
|
-
status: res.statusCode,
|
|
1140
|
-
headers: res.headers,
|
|
1141
|
-
body: fullBody
|
|
1142
|
-
}).catch((e) => logger8.warn(`Route fulfill failed: ${e.message}`));
|
|
1146
|
+
route.abort().catch(() => {
|
|
1147
|
+
});
|
|
1148
|
+
reject(e);
|
|
1143
1149
|
});
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1150
|
+
if (postData) req.write(postData);
|
|
1151
|
+
req.end();
|
|
1152
|
+
} catch (e) {
|
|
1147
1153
|
clearAllTimers();
|
|
1148
|
-
route.
|
|
1154
|
+
route.continue().catch(() => {
|
|
1155
|
+
});
|
|
1149
1156
|
reject(e);
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
}
|
|
1158
|
-
});
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
} catch (e) {
|
|
1160
|
+
reject(e);
|
|
1161
|
+
}
|
|
1162
|
+
});
|
|
1163
|
+
workPromise.catch(() => {
|
|
1159
1164
|
});
|
|
1160
1165
|
const timeoutPromise = new Promise((_, reject) => {
|
|
1161
1166
|
initialTimer = setTimeout(() => {
|
|
@@ -1163,26 +1168,33 @@ var Sse = {
|
|
|
1163
1168
|
const error = new InitialTimeoutError(initialTimeout);
|
|
1164
1169
|
clearAllTimers();
|
|
1165
1170
|
if (onTimeout) {
|
|
1166
|
-
|
|
1171
|
+
try {
|
|
1172
|
+
onTimeout(error, reject);
|
|
1173
|
+
} catch (e) {
|
|
1174
|
+
reject(e);
|
|
1175
|
+
}
|
|
1167
1176
|
} else {
|
|
1168
|
-
logger8.fail(`[Intercept] \u521D\u59CB\u6570\u636E\u63A5\u6536\u8D85\u65F6`, error);
|
|
1169
1177
|
reject(error);
|
|
1170
1178
|
}
|
|
1171
1179
|
}
|
|
1172
1180
|
}, initialTimeout);
|
|
1173
1181
|
overallTimer = setTimeout(() => {
|
|
1174
|
-
const error = new OverallTimeoutError(
|
|
1182
|
+
const error = new OverallTimeoutError(overallTimeout);
|
|
1175
1183
|
clearAllTimers();
|
|
1176
1184
|
if (onTimeout) {
|
|
1177
|
-
|
|
1185
|
+
try {
|
|
1186
|
+
onTimeout(error, reject);
|
|
1187
|
+
} catch (e) {
|
|
1188
|
+
reject(e);
|
|
1189
|
+
}
|
|
1178
1190
|
} else {
|
|
1179
|
-
logger8.fail(`[Intercept] \u6574\u4F53\u8BF7\u6C42\u8D85\u65F6`, error);
|
|
1180
1191
|
reject(error);
|
|
1181
1192
|
}
|
|
1182
|
-
},
|
|
1193
|
+
}, overallTimeout);
|
|
1194
|
+
});
|
|
1195
|
+
timeoutPromise.catch(() => {
|
|
1183
1196
|
});
|
|
1184
|
-
|
|
1185
|
-
return racePromise;
|
|
1197
|
+
return Promise.race([workPromise, timeoutPromise]);
|
|
1186
1198
|
}
|
|
1187
1199
|
};
|
|
1188
1200
|
|