Spaces:
Runtime error
Runtime error
Update app.js
Browse files
app.js
CHANGED
|
@@ -106,7 +106,7 @@ function loadCookies(cookieFilePath) {
|
|
| 106 |
}
|
| 107 |
|
| 108 |
const browser = await puppeteer.launch({
|
| 109 |
-
headless:
|
| 110 |
args: [
|
| 111 |
'--no-sandbox',
|
| 112 |
'--disable-setuid-sandbox',
|
|
@@ -231,20 +231,30 @@ function loadCookies(cookieFilePath) {
|
|
| 231 |
|
| 232 |
// First, navigate to the domain to establish context
|
| 233 |
try {
|
| 234 |
-
|
|
|
|
| 235 |
waitUntil: 'domcontentloaded',
|
| 236 |
timeout: 15000
|
| 237 |
});
|
| 238 |
-
console.log('β
|
| 239 |
|
| 240 |
// Wait a bit for any Cloudflare JS to run
|
| 241 |
await wait(3000);
|
| 242 |
} catch (baseError) {
|
| 243 |
-
console.log('β οΈ
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
}
|
| 249 |
|
| 250 |
// Now set all cookies
|
|
@@ -476,10 +486,13 @@ function loadCookies(cookieFilePath) {
|
|
| 476 |
console.log('\nπ Navigating to the page...');
|
| 477 |
await randomWait(500, 1500);
|
| 478 |
|
| 479 |
-
// Navigate to
|
|
|
|
|
|
|
|
|
|
| 480 |
let response;
|
| 481 |
try {
|
| 482 |
-
response = await page.goto(
|
| 483 |
waitUntil: ['domcontentloaded', 'networkidle2'],
|
| 484 |
timeout: 45000
|
| 485 |
});
|
|
@@ -698,8 +711,8 @@ function loadCookies(cookieFilePath) {
|
|
| 698 |
}
|
| 699 |
}
|
| 700 |
|
| 701 |
-
console.log('\nβ³ Waiting
|
| 702 |
-
await wait(
|
| 703 |
|
| 704 |
// Take initial screenshot
|
| 705 |
console.log('\nπΈ Taking initial screenshot...');
|
|
@@ -708,69 +721,117 @@ function loadCookies(cookieFilePath) {
|
|
| 708 |
fullPage: true
|
| 709 |
});
|
| 710 |
|
| 711 |
-
console.log('\nπ
|
| 712 |
-
|
| 713 |
-
const buttonSelectors = [
|
| 714 |
-
'button[data-testid="signInButton"]',
|
| 715 |
-
'button#signInButton',
|
| 716 |
-
'button.pill.pill-text.pill-text--inherit.pill--medium.button'
|
| 717 |
-
];
|
| 718 |
|
| 719 |
-
|
| 720 |
-
let
|
| 721 |
-
|
| 722 |
-
|
| 723 |
-
|
| 724 |
-
|
| 725 |
-
|
| 726 |
-
|
| 727 |
-
|
| 728 |
-
|
| 729 |
-
|
| 730 |
-
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
|
| 734 |
-
|
| 735 |
-
|
| 736 |
-
|
| 737 |
-
|
| 738 |
-
|
| 739 |
-
|
| 740 |
-
|
| 741 |
-
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
console.log('β Button clicked after scrolling!');
|
| 747 |
}
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
|
|
|
|
|
|
|
|
|
| 751 |
}
|
| 752 |
-
|
| 753 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 754 |
}
|
|
|
|
|
|
|
| 755 |
}
|
| 756 |
|
| 757 |
-
if
|
| 758 |
-
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 768 |
});
|
| 769 |
-
|
| 770 |
-
console.log(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 771 |
}
|
| 772 |
|
| 773 |
console.log('\nπΈ Taking final screenshot...');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 774 |
await page.screenshot({
|
| 775 |
path: './betking-final.png',
|
| 776 |
fullPage: true
|
|
|
|
| 106 |
}
|
| 107 |
|
| 108 |
const browser = await puppeteer.launch({
|
| 109 |
+
headless: false,
|
| 110 |
args: [
|
| 111 |
'--no-sandbox',
|
| 112 |
'--disable-setuid-sandbox',
|
|
|
|
| 231 |
|
| 232 |
// First, navigate to the domain to establish context
|
| 233 |
try {
|
| 234 |
+
// Try login page directly for cookie context
|
| 235 |
+
await page.goto('https://m.betking.com/en-ng/my-accounts/login', {
|
| 236 |
waitUntil: 'domcontentloaded',
|
| 237 |
timeout: 15000
|
| 238 |
});
|
| 239 |
+
console.log('β Login page loaded for cookie context');
|
| 240 |
|
| 241 |
// Wait a bit for any Cloudflare JS to run
|
| 242 |
await wait(3000);
|
| 243 |
} catch (baseError) {
|
| 244 |
+
console.log('β οΈ Initial login page load issue, trying base domain...');
|
| 245 |
+
try {
|
| 246 |
+
await page.goto('https://m.betking.com/', {
|
| 247 |
+
waitUntil: 'domcontentloaded',
|
| 248 |
+
timeout: 15000
|
| 249 |
+
});
|
| 250 |
+
console.log('β Base domain loaded');
|
| 251 |
+
await wait(3000);
|
| 252 |
+
} catch (fallbackError) {
|
| 253 |
+
console.log('β οΈ Base domain also failed, setting domain manually...');
|
| 254 |
+
await page.evaluateOnNewDocument(() => {
|
| 255 |
+
document.domain = 'betking.com';
|
| 256 |
+
});
|
| 257 |
+
}
|
| 258 |
}
|
| 259 |
|
| 260 |
// Now set all cookies
|
|
|
|
| 486 |
console.log('\nπ Navigating to the page...');
|
| 487 |
await randomWait(500, 1500);
|
| 488 |
|
| 489 |
+
// Navigate directly to login page
|
| 490 |
+
const targetUrl = 'https://m.betking.com/en-ng/my-accounts/login?urlAfterLogin=/en-ng';
|
| 491 |
+
console.log(`Target: ${targetUrl}`);
|
| 492 |
+
|
| 493 |
let response;
|
| 494 |
try {
|
| 495 |
+
response = await page.goto(targetUrl, {
|
| 496 |
waitUntil: ['domcontentloaded', 'networkidle2'],
|
| 497 |
timeout: 45000
|
| 498 |
});
|
|
|
|
| 711 |
}
|
| 712 |
}
|
| 713 |
|
| 714 |
+
console.log('\nβ³ Waiting 10 seconds...');
|
| 715 |
+
await wait(10000);
|
| 716 |
|
| 717 |
// Take initial screenshot
|
| 718 |
console.log('\nπΈ Taking initial screenshot...');
|
|
|
|
| 721 |
fullPage: true
|
| 722 |
});
|
| 723 |
|
| 724 |
+
console.log('\nπ Checking if we bypassed 403 - looking for login input...');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 725 |
|
| 726 |
+
// Check for username input field
|
| 727 |
+
let loginInputFound = false;
|
| 728 |
+
let bypass403Success = false;
|
| 729 |
+
|
| 730 |
+
try {
|
| 731 |
+
const usernameInput = await page.$('#username');
|
| 732 |
+
if (usernameInput) {
|
| 733 |
+
loginInputFound = true;
|
| 734 |
+
bypass403Success = true;
|
| 735 |
+
console.log('β
SUCCESS! Found username input - 403 bypass worked!');
|
| 736 |
+
console.log('β We are on the real login page!');
|
| 737 |
+
|
| 738 |
+
// Check if input is visible
|
| 739 |
+
const isVisible = await usernameInput.isIntersectingViewport();
|
| 740 |
+
console.log(`Username input is visible: ${isVisible}`);
|
| 741 |
+
|
| 742 |
+
// Get input attributes for confirmation
|
| 743 |
+
const inputInfo = await page.evaluate(() => {
|
| 744 |
+
const input = document.querySelector('#username');
|
| 745 |
+
if (input) {
|
| 746 |
+
return {
|
| 747 |
+
id: input.id,
|
| 748 |
+
type: input.type,
|
| 749 |
+
name: input.name,
|
| 750 |
+
placeholder: input.placeholder,
|
| 751 |
+
class: input.className
|
| 752 |
+
};
|
|
|
|
| 753 |
}
|
| 754 |
+
return null;
|
| 755 |
+
});
|
| 756 |
+
|
| 757 |
+
if (inputInfo) {
|
| 758 |
+
console.log('π Input field details:');
|
| 759 |
+
console.log(JSON.stringify(inputInfo, null, 2));
|
| 760 |
}
|
| 761 |
+
|
| 762 |
+
// Check for other login elements
|
| 763 |
+
const otherElements = await page.evaluate(() => {
|
| 764 |
+
return {
|
| 765 |
+
passwordField: !!document.querySelector('#password') || !!document.querySelector('input[type="password"]'),
|
| 766 |
+
loginButton: !!document.querySelector('button[type="submit"]'),
|
| 767 |
+
totalInputs: document.querySelectorAll('input').length,
|
| 768 |
+
totalButtons: document.querySelectorAll('button').length,
|
| 769 |
+
pageTitle: document.title,
|
| 770 |
+
hasLoginForm: !!document.querySelector('form')
|
| 771 |
+
};
|
| 772 |
+
});
|
| 773 |
+
|
| 774 |
+
console.log('π Page structure analysis:');
|
| 775 |
+
console.log(` - Password field found: ${otherElements.passwordField}`);
|
| 776 |
+
console.log(` - Login button found: ${otherElements.loginButton}`);
|
| 777 |
+
console.log(` - Total inputs: ${otherElements.totalInputs}`);
|
| 778 |
+
console.log(` - Total buttons: ${otherElements.totalButtons}`);
|
| 779 |
+
console.log(` - Page title: ${otherElements.pageTitle}`);
|
| 780 |
+
console.log(` - Has form: ${otherElements.hasLoginForm}`);
|
| 781 |
+
|
| 782 |
+
} else {
|
| 783 |
+
console.log('β Username input NOT found - still blocked or wrong page');
|
| 784 |
}
|
| 785 |
+
} catch (error) {
|
| 786 |
+
console.log(`β οΈ Error checking for input: ${error.message}`);
|
| 787 |
}
|
| 788 |
|
| 789 |
+
// Also check if we're still on Cloudflare page
|
| 790 |
+
const stillOnCloudflare = await page.evaluate(() => {
|
| 791 |
+
const body = document.body.innerText;
|
| 792 |
+
const title = document.title;
|
| 793 |
+
return (
|
| 794 |
+
body.includes('Just a moment') ||
|
| 795 |
+
body.includes('Checking your browser') ||
|
| 796 |
+
body.includes('Verify you are human') ||
|
| 797 |
+
title.includes('Just a moment') ||
|
| 798 |
+
body.includes('Cloudflare')
|
| 799 |
+
);
|
| 800 |
+
});
|
| 801 |
+
|
| 802 |
+
if (stillOnCloudflare) {
|
| 803 |
+
console.log('β οΈ Still on Cloudflare challenge page');
|
| 804 |
+
} else if (!loginInputFound) {
|
| 805 |
+
console.log('β οΈ Not on Cloudflare, but also not on login page - checking what page we\'re on...');
|
| 806 |
+
|
| 807 |
+
const pageInfo = await page.evaluate(() => {
|
| 808 |
+
return {
|
| 809 |
+
url: window.location.href,
|
| 810 |
+
title: document.title,
|
| 811 |
+
bodyText: document.body.innerText.substring(0, 500),
|
| 812 |
+
h1: document.querySelector('h1')?.innerText,
|
| 813 |
+
errorMessage: document.querySelector('.error-message')?.innerText ||
|
| 814 |
+
document.querySelector('[class*="error"]')?.innerText
|
| 815 |
+
};
|
| 816 |
});
|
| 817 |
+
|
| 818 |
+
console.log('π Current page info:');
|
| 819 |
+
console.log(` - URL: ${pageInfo.url}`);
|
| 820 |
+
console.log(` - Title: ${pageInfo.title}`);
|
| 821 |
+
console.log(` - H1: ${pageInfo.h1}`);
|
| 822 |
+
if (pageInfo.errorMessage) {
|
| 823 |
+
console.log(` - Error message: ${pageInfo.errorMessage}`);
|
| 824 |
+
}
|
| 825 |
}
|
| 826 |
|
| 827 |
console.log('\nπΈ Taking final screenshot...');
|
| 828 |
+
|
| 829 |
+
if (bypass403Success) {
|
| 830 |
+
console.log('π STATUS: 403 BYPASS SUCCESSFUL - Login page reached!');
|
| 831 |
+
} else {
|
| 832 |
+
console.log('β STATUS: 403 bypass failed or still on challenge page');
|
| 833 |
+
}
|
| 834 |
+
|
| 835 |
await page.screenshot({
|
| 836 |
path: './betking-final.png',
|
| 837 |
fullPage: true
|