Skip to content

Commit

Permalink
feat: set timeout page
Browse files Browse the repository at this point in the history
  • Loading branch information
jonalan7 committed Aug 11, 2023
1 parent e692b48 commit 817945f
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,24 @@ export async function initWhatsapp(
}
try {
await waPage.setUserAgent(useragentOverride);
waPage.setDefaultTimeout(60000);

const hasUserPass =
typeof options.userPass === 'string' && options.userPass.length;
const hasUserProxy =
typeof options.userProxy === 'string' && options.userProxy.length;
const hasAddProxy =
Array.isArray(options.addProxy) && options.addProxy.length;

if (hasUserPass && hasUserProxy && hasAddProxy) {
await waPage.authenticate({
username: options.userProxy,
password: options.userPass
});
const { userPass, userProxy, addProxy } = options;

if (
typeof userPass === 'string' &&
userPass.length &&
typeof userProxy === 'string' &&
userProxy.length &&
Array.isArray(addProxy) &&
addProxy.length
) {
await waPage.authenticate(
{
username: userProxy,
password: userPass
}
);
}

await waPage.goto(puppeteerConfig.whatsappUrl, {
Expand Down Expand Up @@ -78,11 +83,7 @@ export async function getWhatsappPage(
): Promise<Page | false> {
try {
const pages: Page[] = await browser.pages();
if (pages.length !== 0) {
return pages[0];
} else {
return await browser.newPage();
}
return pages.length !== 0 ? pages[0] : await browser.newPage();
} catch {
return false;
}
Expand Down

0 comments on commit 817945f

Please sign in to comment.