Skip to content

Commit

Permalink
feat: 多浏览器间隔启动
Browse files Browse the repository at this point in the history
  • Loading branch information
14790897 committed Apr 5, 2024
1 parent d1df974 commit 0647c0b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require("dotenv").config();
// 从环境变量解析用户名和密码
const usernames = process.env.USERNAMES.split(",");
const passwords = process.env.PASSWORDS.split(",");
// 每个浏览器实例之间的延迟时间(毫秒)
const delayBetweenInstances = 10000;
//随机等待时间
function delayClick(time) {
return new Promise(function (resolve) {
Expand All @@ -23,7 +25,12 @@ function delayClick(time) {
// 并发启动浏览器实例进行登录
const loginPromises = usernames.map((username, index) => {
const password = passwords[index];
return launchBrowserForUser(username, password);
const delay = index * delayBetweenInstances;
return new Promise((resolve) => {
setTimeout(() => {
launchBrowserForUser(username, password).then(resolve);
}, delay);
});
});

// 等待所有登录操作完成
Expand Down

0 comments on commit 0647c0b

Please sign in to comment.