# Pastebin mNwKPrOR try { // Try and looked for the logout button (login success) await page.waitFor(".logout", { timeout: 7000 }); debug("Login successful."); return { page, browser }; } catch { let exceptionTypeToThrow = new Error( "Unknown login exception. Please run login command in non-headless mode to visually debug." ); await page .waitForFunction( 'document.querySelector(".universal-message-content > .vertical-offset-xs").inner‌​Text.indexOf("942") > -1', { timeout: 1000 } ) .then( () => true, () => { exceptionTypeToThrow = new exceptions.HeadlessBrowserDetectedException( `It is possible the browser has been detected as a bot. Please run login command in non-headless mode to visually debug.` ); } ); await page .waitForFunction( 'document.querySelector(".universal-message-content > .universal-message-heading").inner‌​Text.indexOf("password you entered") > -1', { timeout: 1000 } ) .then( () => true, () => { exceptionTypeToThrow = new exceptions.InvalidUsernamePasswordException( `It is possible the browser has been detected as a bot. Please run login command in non-headless mode to visually debug.` ); } ); throw exceptionTypeToThrow; }