Spaces:
Paused
Paused
Update index.js
Browse files
index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import express from 'express';
|
| 2 |
-
import {
|
|
|
|
| 3 |
import cors from 'cors';
|
| 4 |
import { promises as fs } from 'fs';
|
| 5 |
import path from 'path';
|
|
@@ -8,6 +9,8 @@ import { fileURLToPath } from 'url';
|
|
| 8 |
const __filename = fileURLToPath(import.meta.url);
|
| 9 |
const __dirname = path.dirname(__filename);
|
| 10 |
|
|
|
|
|
|
|
| 11 |
const app = express();
|
| 12 |
const PORT = process.env.PORT || 7860;
|
| 13 |
|
|
@@ -18,15 +21,13 @@ app.use('/files', express.static('public'));
|
|
| 18 |
const publicDir = path.join(__dirname, 'public');
|
| 19 |
await fs.mkdir(publicDir, { recursive: true }).catch(console.error);
|
| 20 |
|
| 21 |
-
function
|
| 22 |
let converted = code;
|
| 23 |
|
| 24 |
const replacements = [
|
| 25 |
-
[/chromium
|
| 26 |
-
[/
|
| 27 |
-
[/
|
| 28 |
-
[/from\s+['"]playwright['"]/gi, 'from "camoufox"'],
|
| 29 |
-
[/import\s+{\s*chromium\s*}\s+from\s+['"]playwright['"]/gi, 'import { Camoufox } from "camoufox"'],
|
| 30 |
];
|
| 31 |
|
| 32 |
replacements.forEach(([pattern, replacement]) => {
|
|
@@ -59,12 +60,33 @@ app.post('/api/s-playwright', async (req, res) => {
|
|
| 59 |
let browser = null;
|
| 60 |
|
| 61 |
try {
|
| 62 |
-
const convertedCode =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
| 65 |
-
const executableCode = new AsyncFunction('
|
| 66 |
|
| 67 |
-
const result = await executableCode(
|
| 68 |
|
| 69 |
const timestamp = Date.now();
|
| 70 |
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
@@ -104,22 +126,22 @@ app.post('/api/s-playwright', async (req, res) => {
|
|
| 104 |
|
| 105 |
app.get('/', (req, res) => {
|
| 106 |
res.json({
|
| 107 |
-
message: '
|
| 108 |
endpoints: {
|
| 109 |
-
'POST /api/s-playwright': 'Execute
|
| 110 |
},
|
| 111 |
features: [
|
| 112 |
'Advanced Anti-Fingerprinting',
|
| 113 |
-
'
|
| 114 |
'Human-like Behavior',
|
| 115 |
'Cloudflare WAF Bypass',
|
| 116 |
-
'Auto Playwright
|
| 117 |
]
|
| 118 |
});
|
| 119 |
});
|
| 120 |
|
| 121 |
app.listen(PORT, '0.0.0.0', () => {
|
| 122 |
-
console.log(`π
|
| 123 |
console.log(`π Endpoint: POST /api/s-playwright`);
|
| 124 |
console.log(`π Features: Anti-fingerprinting, WAF bypass, stealth mode`);
|
| 125 |
});
|
|
|
|
| 1 |
import express from 'express';
|
| 2 |
+
import { chromium } from 'playwright-extra';
|
| 3 |
+
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
|
| 4 |
import cors from 'cors';
|
| 5 |
import { promises as fs } from 'fs';
|
| 6 |
import path from 'path';
|
|
|
|
| 9 |
const __filename = fileURLToPath(import.meta.url);
|
| 10 |
const __dirname = path.dirname(__filename);
|
| 11 |
|
| 12 |
+
chromium.use(StealthPlugin());
|
| 13 |
+
|
| 14 |
const app = express();
|
| 15 |
const PORT = process.env.PORT || 7860;
|
| 16 |
|
|
|
|
| 21 |
const publicDir = path.join(__dirname, 'public');
|
| 22 |
await fs.mkdir(publicDir, { recursive: true }).catch(console.error);
|
| 23 |
|
| 24 |
+
function convertPlaywrightCode(code) {
|
| 25 |
let converted = code;
|
| 26 |
|
| 27 |
const replacements = [
|
| 28 |
+
[/const\s+{\s*chromium\s*}\s*=\s*require\(['"](.*?playwright.*?)['"]\)/gi, 'const chromium = globalThis.chromium'],
|
| 29 |
+
[/from\s+['"]playwright['"]/gi, ''],
|
| 30 |
+
[/import\s+{\s*chromium\s*}\s+from\s+['"]playwright['"]/gi, 'const chromium = globalThis.chromium'],
|
|
|
|
|
|
|
| 31 |
];
|
| 32 |
|
| 33 |
replacements.forEach(([pattern, replacement]) => {
|
|
|
|
| 60 |
let browser = null;
|
| 61 |
|
| 62 |
try {
|
| 63 |
+
const convertedCode = convertPlaywrightCode(code);
|
| 64 |
+
|
| 65 |
+
globalThis.chromium = {
|
| 66 |
+
launch: async (options = {}) => {
|
| 67 |
+
return await chromium.launch({
|
| 68 |
+
headless: options.headless !== false,
|
| 69 |
+
args: [
|
| 70 |
+
'--disable-blink-features=AutomationControlled',
|
| 71 |
+
'--no-sandbox',
|
| 72 |
+
'--disable-setuid-sandbox',
|
| 73 |
+
'--disable-web-security',
|
| 74 |
+
'--disable-features=IsolateOrigins,site-per-process',
|
| 75 |
+
'--disable-dev-shm-usage',
|
| 76 |
+
'--disable-accelerated-2d-canvas',
|
| 77 |
+
'--disable-gpu',
|
| 78 |
+
'--window-size=1920,1080',
|
| 79 |
+
'--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36',
|
| 80 |
+
...(options.args || [])
|
| 81 |
+
]
|
| 82 |
+
});
|
| 83 |
+
}
|
| 84 |
+
};
|
| 85 |
|
| 86 |
const AsyncFunction = Object.getPrototypeOf(async function(){}).constructor;
|
| 87 |
+
const executableCode = new AsyncFunction('chromium', 'publicDir', 'path', 'fs', convertedCode);
|
| 88 |
|
| 89 |
+
const result = await executableCode(globalThis.chromium, publicDir, path, fs);
|
| 90 |
|
| 91 |
const timestamp = Date.now();
|
| 92 |
const baseUrl = `${req.protocol}://${req.get('host')}`;
|
|
|
|
| 126 |
|
| 127 |
app.get('/', (req, res) => {
|
| 128 |
res.json({
|
| 129 |
+
message: 'Playwright Stealth API is running',
|
| 130 |
endpoints: {
|
| 131 |
+
'POST /api/s-playwright': 'Execute playwright code with stealth mode'
|
| 132 |
},
|
| 133 |
features: [
|
| 134 |
'Advanced Anti-Fingerprinting',
|
| 135 |
+
'Stealth Plugin Enabled',
|
| 136 |
'Human-like Behavior',
|
| 137 |
'Cloudflare WAF Bypass',
|
| 138 |
+
'Auto Playwright code execution'
|
| 139 |
]
|
| 140 |
});
|
| 141 |
});
|
| 142 |
|
| 143 |
app.listen(PORT, '0.0.0.0', () => {
|
| 144 |
+
console.log(`π Playwright Stealth API running on port ${PORT}`);
|
| 145 |
console.log(`π Endpoint: POST /api/s-playwright`);
|
| 146 |
console.log(`π Features: Anti-fingerprinting, WAF bypass, stealth mode`);
|
| 147 |
});
|