fix(utility-agent): Wait for navigation and catch goto error
This commit is contained in:
parent
e4a7d07fdf
commit
d57b8cb595
|
|
@ -103,7 +103,10 @@ async function runScrapers(credentials) {
|
||||||
await page.type('#txtLogin', credentials.peoplesGas.username);
|
await page.type('#txtLogin', credentials.peoplesGas.username);
|
||||||
await page.type('#txtpwd', credentials.peoplesGas.password);
|
await page.type('#txtpwd', credentials.peoplesGas.password);
|
||||||
|
|
||||||
await page.click('#btnlogin');
|
await Promise.all([
|
||||||
|
page.waitForNavigation({ waitUntil: 'domcontentloaded', timeout: 30000 }).catch(()=>null),
|
||||||
|
page.click('#btnlogin')
|
||||||
|
]);
|
||||||
|
|
||||||
console.log('[Scraper] Logged into Peoples Gas. Extracting usage via API...');
|
console.log('[Scraper] Logged into Peoples Gas. Extracting usage via API...');
|
||||||
|
|
||||||
|
|
@ -121,7 +124,7 @@ async function runScrapers(credentials) {
|
||||||
{ timeout: 30000 }
|
{ timeout: 30000 }
|
||||||
).catch(() => null);
|
).catch(() => null);
|
||||||
|
|
||||||
await page.goto('https://peopleseaccount.com/Portal/Usages.aspx?type=GU', { waitUntil: 'domcontentloaded', timeout: 60000 });
|
await page.goto('https://peopleseaccount.com/Portal/Usages.aspx?type=GU', { waitUntil: 'domcontentloaded', timeout: 60000 }).catch(e => console.log('[Scraper] PG goto error ignored:', e.message));
|
||||||
|
|
||||||
let pgUsage = 'N/A';
|
let pgUsage = 'N/A';
|
||||||
const apiResponse = await usagePromise;
|
const apiResponse = await usagePromise;
|
||||||
|
|
@ -152,7 +155,10 @@ async function runScrapers(credentials) {
|
||||||
|
|
||||||
report += `\n_Stats pulled automatically by Utility Agent_`;
|
report += `\n_Stats pulled automatically by Utility Agent_`;
|
||||||
|
|
||||||
console.log('[Scraper] Report generated, sending to WhatsApp...');
|
console.log('[Scraper] Report generated:');
|
||||||
|
console.log(report);
|
||||||
|
|
||||||
|
console.log('[Scraper] Sending to WhatsApp...');
|
||||||
try {
|
try {
|
||||||
await fetch(WHATSAPP_GATEWAY_URL, {
|
await fetch(WHATSAPP_GATEWAY_URL, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue