Skip to content

Commit

Permalink
Implemented: screenshotOnInitializationBrowserError #1141
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Dec 5, 2020
1 parent f5e032f commit e79bb0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/api/model/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export enum QRFormat{
}

/**
* The set values of quality you can set for the qquality of the qr code output. Ten being the highest quality.
* The set values of quality you can set for the quality of the qr code output. Ten being the highest quality.
*/
export enum QRQuality {
ONE = 0.1,
Expand Down Expand Up @@ -382,7 +382,7 @@ export interface ConfigObject {
*/
legacy ?: boolean;
/**
* Deletes the session data file (if found) on logout event. This results in a quickler login when you restart the process.
* Deletes the session data file (if found) on logout event. This results in a quicker login when you restart the process.
* @default `false`
*/
deleteSessionDataOnLogout ?: boolean;
Expand All @@ -395,7 +395,12 @@ export interface ConfigObject {
* Setting this to true will bypass web security. DO NOT DO THIS IF YOU DO NOT HAVE TO. CORS issue may arise when using a proxy.
* @default `false`
*/
corsFix ?: boolean
corsFix ?: boolean;
/**
* When true, this option will take a screenshot of the browser when an unexpected error occurs within the browser during `create` initialization. The path will be `[working directory]/logs/[session ID]/[start timestamp]/[timestamp].jpg`
* @default `true`
*/
screenshotOnInitializationBrowserError ?: boolean;
/**@internal */
[x: string]: any
}
3 changes: 2 additions & 1 deletion src/api/model/sessionInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ export interface SessionInfo {
BROWSER_VERSION: string;
LAUNCH_TIME_MS ?: number;
NUM ?: string;
OS ?: string
OS ?: string;
START_TS ?: number;
}
22 changes: 20 additions & 2 deletions src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ import CFonts from 'cfonts';
import { popup } from './popup';
import { getConfigFromProcessEnv } from '../utils/tools';
import { SessionInfo } from '../api/model/sessionInfo';
import { Page } from 'puppeteer';
/** @ignore */
// let shouldLoop = true,
let axios;
export let screenshot;


/**
* Used to initialize the client session.
Expand Down Expand Up @@ -116,18 +119,33 @@ export async function create(config: ConfigObject = {}): Promise<Client> {
const PAGE_UA = await waPage.evaluate('navigator.userAgent');
const BROWSER_VERSION = await waPage.browser().version();
const OS = osName();
const START_TS = Date.now();
const screenshotPath = `./logs/${config.sessionId || 'session'}/${START_TS}`
screenshot = (page: Page) => page.screenshot({
path:`${screenshotPath}/${Date.now()}.jpg`
}).catch(_=>{
fs.mkdirSync(screenshotPath, {recursive: true});
return screenshot(page)
})

if(config?.screenshotOnInitializationBrowserError) waPage.on('console', async msg => {
for (let i = 0; i < msg.args().length; ++i)
console.log(`${i}: ${msg.args()[i]}`);
if(msg.type() === 'error' && !msg.text().includes('apify') && !msg.text().includes('crashlogs')) await screenshot(waPage)
});

const WA_AUTOMATE_VERSION = `${pkg.version}${notifier?.update ? ` UPDATE AVAILABLE: ${notifier?.update.latest}` : ''}`;
//@ts-ignore
const WA_VERSION = await waPage.evaluate(() => window.Debug ? window.Debug.VERSION : 'I think you have been TOS_BLOCKed')
const WA_VERSION = await waPage.evaluate(() => window.Debug ? window.Debug.VERSION || window.Debug : 'I think you have been TOS_BLOCKed')
//@ts-ignore
const canInjectEarly = await waPage.evaluate(() => { return (typeof webpackJsonp !== "undefined") });
let debugInfo : SessionInfo = {
WA_VERSION,
PAGE_UA,
WA_AUTOMATE_VERSION,
BROWSER_VERSION,
OS
OS,
START_TS
};
console.table(debugInfo);

Expand Down

0 comments on commit e79bb0f

Please sign in to comment.