diff --git a/newegg-purchaser.js b/newegg-purchaser.js index 2f95e6c..a7fe1a0 100755 --- a/newegg-purchaser.js +++ b/newegg-purchaser.js @@ -44,15 +44,24 @@ async function run() { await page.click("button.btn.btn-orange"); await page.waitForTimeout(1500); - try { - await page.waitForSelector("#labeled-input-password", { timeout: 2500 }); - await page.waitForSelector("button.btn.btn-orange"); - await page.type("#labeled-input-password", config.password); - await page.click("button.btn.btn-orange"); - log("Successfully logged in"); - } catch (err) { - log("Fail: Manual authorization code required by Newegg. This should only happen once."); - success = false; + while (true) { + try { + await page.waitForSelector("#labeled-input-password", { timeout: 2500 }); + await page.waitForSelector("button.btn.btn-orange"); + await page.type("#labeled-input-password", config.password); + await page.click("button.btn.btn-orange"); + log("Successfully logged in"); + break; + } catch (err) { + try { + await page.waitForSelector(".nav-complex-inner .fa-caret-down", { timeout: 2500 }); + log("Successfully logged in"); + break; + } catch (err) { + log("Waiting for authorization"); + await page.waitForTimeout(5000); + } + } } } catch (err) { log("Fail: Login form missing"); @@ -157,7 +166,7 @@ async function run() { } if (!success) { - await browser.close(); + // await browser.close(); } }