Skip to content

Commit

Permalink
throw tosblock on first detection #103
Browse files Browse the repository at this point in the history
  • Loading branch information
smashah committed Feb 14, 2020
1 parent e85f7be commit c088a76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,14 @@ create('session',
'--disable-offline-load-stale-cache',
'--disk-cache-size=0'
]
}
},
tosBlockGuaranteed
)
// create()
.then(async client => await start(client))
.catch(e=>{
console.log(e);
// process.exit();
console.log('Error',e.message);
process.exit();
});

//or you can set a 'session id'
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/initializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function create(sessionId?: string, puppeteerConfigOverride?:any, c
spinner.start('Initializing whatsapp');
waPage = await initWhatsapp(sessionId, puppeteerConfigOverride, customUserAgent);
spinner.succeed();
const throwOnError=puppeteerConfigOverride&&puppeteerConfigOverride.throwErrorOnTosBlock==true;

const PAGE_UA = await waPage.evaluate('navigator.userAgent');
const BROWSER_VERSION = await waPage.browser().version();
Expand All @@ -39,6 +40,7 @@ export async function create(sessionId?: string, puppeteerConfigOverride?:any, c
waPage = await injectApi(waPage);
spinner.start('WAPI injected');
} else {
if(throwOnError) throw Error('TOSBLOCK');
console.log('Possilby TOS_BLOCKed')
}

Expand All @@ -49,7 +51,7 @@ export async function create(sessionId?: string, puppeteerConfigOverride?:any, c
const qrLoop = async () => {
if(!shouldLoop) return;
console.log(' ')
await retrieveQR(waPage,sessionId,autoRefresh,puppeteerConfigOverride&&puppeteerConfigOverride.throwErrorOnTosBlock==true);
await retrieveQR(waPage,sessionId,autoRefresh,throwOnError);
console.log(' ')
qrTimeout = timeout((puppeteerConfigOverride?(puppeteerConfigOverride.qrRefreshS || 10):10)*1000);
await qrTimeout;
Expand Down

0 comments on commit c088a76

Please sign in to comment.