@@ -7,18 +7,36 @@ puppeteer.use(StealthPlugin());
77( async ( ) => {
88 const browser = await puppeteer . launch ( {
99 headless : "new" ,
10- args : [ '--no-sandbox' , '--disable-setuid-sandbox' ]
10+ // Add window size to ensure the page renders properly
11+ args : [ '--no-sandbox' , '--disable-setuid-sandbox' , '--window-size=1280,720' ]
1112 } ) ;
1213
1314 const page = await browser . newPage ( ) ;
15+ await page . setViewport ( { width : 1280 , height : 720 } ) ;
1416 let token = "" ;
1517
1618 await page . setRequestInterception ( true ) ;
1719 page . on ( 'request' , request => {
20+ // 1. Check HTTP Headers
1821 const headers = request . headers ( ) ;
19- if ( headers [ 'authorization' ] && headers [ 'authorization' ] . includes ( 'Bearer' ) ) {
22+ if ( headers [ 'authorization' ] ) {
2023 token = headers [ 'authorization' ] . replace ( 'Bearer ' , '' ) . trim ( ) ;
21- console . log ( 'Token successfully captured!' ) ;
24+ }
25+
26+ // 2. Check POST Body (Form-Data or JSON)
27+ const postData = request . postData ( ) ;
28+ if ( request . method ( ) === 'POST' && postData ) {
29+ if ( postData . includes ( 'authorization=' ) ) {
30+ const params = new URLSearchParams ( postData ) ;
31+ if ( params . get ( 'authorization' ) ) {
32+ token = params . get ( 'authorization' ) ;
33+ }
34+ } else {
35+ try {
36+ const json = JSON . parse ( postData ) ;
37+ if ( json . authorization ) token = json . authorization ;
38+ } catch ( e ) { }
39+ }
2240 }
2341 request . continue ( ) ;
2442 } ) ;
@@ -30,15 +48,22 @@ puppeteer.use(StealthPlugin());
3048 waitUntil : 'networkidle2' ,
3149 timeout : 60000
3250 } ) ;
51+
52+ // Wait an extra 5 seconds to let leviathan.js build and send the token
53+ await new Promise ( r => setTimeout ( r , 5000 ) ) ;
54+
3355 } catch ( e ) {
34- console . log ( 'Navigation timeout (Ignore if token already received) .' ) ;
56+ console . log ( 'Warning: Navigation timeout, checking if token was captured.. .' ) ;
3557 }
3658
37- if ( token ) {
59+ if ( token && token . length > 10 ) {
3860 fs . writeFileSync ( 'kurama_token.txt' , token ) ;
39- console . log ( ' Token successfully saved to kurama_token.txt' ) ;
61+ console . log ( `SUCCESS: Token retrieved -> ${ token . substring ( 0 , 15 ) } ...` ) ;
4062 } else {
4163 console . log ( 'FAIL: Token not found.' ) ;
64+ // Take a screenshot of the browser for debugging purposes
65+ await page . screenshot ( { path : 'error.png' , fullPage : true } ) ;
66+ console . log ( 'Failure screenshot saved as error.png' ) ;
4267 process . exit ( 1 ) ;
4368 }
4469
0 commit comments