Spaces:
Paused
Paused
Create app.js
Browse files
app.js
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const express = require('express');
|
| 2 |
+
const puppeteer = require('puppeteer-extra');
|
| 3 |
+
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
|
| 4 |
+
const randomUseragent = require('random-useragent');
|
| 5 |
+
|
| 6 |
+
puppeteer.use(StealthPlugin());
|
| 7 |
+
|
| 8 |
+
const app = express();
|
| 9 |
+
app.use(express.json());
|
| 10 |
+
|
| 11 |
+
app.post('/login', async (req, res) => {
|
| 12 |
+
const { email, password } = req.body;
|
| 13 |
+
|
| 14 |
+
if (!email || !password) {
|
| 15 |
+
return res.status(400).json({ error: 'Missing email or password' });
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
let browser;
|
| 19 |
+
|
| 20 |
+
try {
|
| 21 |
+
browser = await puppeteer.launch({
|
| 22 |
+
headless: true,
|
| 23 |
+
defaultViewport: null,
|
| 24 |
+
args: [
|
| 25 |
+
'--no-sandbox',
|
| 26 |
+
'--disable-setuid-sandbox',
|
| 27 |
+
'--disable-blink-features=AutomationControlled',
|
| 28 |
+
'--disable-dev-shm-usage',
|
| 29 |
+
'--disable-infobars',
|
| 30 |
+
'--window-size=1920,1080'
|
| 31 |
+
]
|
| 32 |
+
});
|
| 33 |
+
|
| 34 |
+
const page = await browser.newPage();
|
| 35 |
+
|
| 36 |
+
// π Rotate realistic user-agent
|
| 37 |
+
const userAgent = randomUseragent.getRandom();
|
| 38 |
+
await page.setUserAgent(userAgent || 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)');
|
| 39 |
+
|
| 40 |
+
// π‘οΈ Set spoofed headers
|
| 41 |
+
await page.setExtraHTTPHeaders({
|
| 42 |
+
'Accept-Language': 'en-US,en;q=0.9',
|
| 43 |
+
});
|
| 44 |
+
|
| 45 |
+
// π« Block unnecessary resources
|
| 46 |
+
await page.setRequestInterception(true);
|
| 47 |
+
page.on('request', (req) => {
|
| 48 |
+
const type = req.resourceType();
|
| 49 |
+
if (['image', 'stylesheet', 'font', 'media'].includes(type)) {
|
| 50 |
+
req.abort();
|
| 51 |
+
} else {
|
| 52 |
+
req.continue();
|
| 53 |
+
}
|
| 54 |
+
});
|
| 55 |
+
|
| 56 |
+
// π Spoof browser fingerprints
|
| 57 |
+
await page.evaluateOnNewDocument(() => {
|
| 58 |
+
Object.defineProperty(navigator, 'webdriver', { get: () => false });
|
| 59 |
+
Object.defineProperty(navigator, 'languages', { get: () => ['en-US', 'en'] });
|
| 60 |
+
Object.defineProperty(navigator, 'plugins', { get: () => [1, 2, 3] });
|
| 61 |
+
Object.defineProperty(navigator, 'platform', { get: () => 'Win32' });
|
| 62 |
+
});
|
| 63 |
+
|
| 64 |
+
// π Go to login page
|
| 65 |
+
await page.goto('https://sso.crunchyroll.com/login', {
|
| 66 |
+
waitUntil: 'networkidle2',
|
| 67 |
+
timeout: 60000,
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
await page.waitForSelector('input[name="email"]');
|
| 71 |
+
await page.type('input[name="email"]', email, { delay: 80 });
|
| 72 |
+
|
| 73 |
+
await page.waitForSelector('input[name="password"]');
|
| 74 |
+
await page.type('input[name="password"]', password, { delay: 80 });
|
| 75 |
+
|
| 76 |
+
await page.waitForFunction(() => {
|
| 77 |
+
const btn = document.querySelector('button[data-t="login-button"]');
|
| 78 |
+
return btn && btn.getAttribute('aria-disabled') === 'false';
|
| 79 |
+
}, { timeout: 10000 });
|
| 80 |
+
|
| 81 |
+
await page.click('button[data-t="login-button"]');
|
| 82 |
+
|
| 83 |
+
await page.waitForNavigation({ waitUntil: 'networkidle2', timeout: 60000 });
|
| 84 |
+
|
| 85 |
+
const url = page.url();
|
| 86 |
+
const loginSuccess = !url.includes('/login');
|
| 87 |
+
|
| 88 |
+
res.json({
|
| 89 |
+
success: loginSuccess,
|
| 90 |
+
currentUrl: url,
|
| 91 |
+
userAgent: userAgent
|
| 92 |
+
});
|
| 93 |
+
|
| 94 |
+
} catch (err) {
|
| 95 |
+
console.error('β Error during login:', err);
|
| 96 |
+
res.status(500).json({ error: 'Login failed', details: err.message });
|
| 97 |
+
} finally {
|
| 98 |
+
if (browser) await browser.close();
|
| 99 |
+
}
|
| 100 |
+
});
|
| 101 |
+
|
| 102 |
+
const PORT = process.env.PORT || 7860;
|
| 103 |
+
app.listen(PORT, () => console.log(`π Server running on port ${PORT}`));
|