-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinject.js
More file actions
87 lines (72 loc) · 2.93 KB
/
inject.js
File metadata and controls
87 lines (72 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// @ts-check
import puppeteer from 'puppeteer-core';
import axios from 'axios';
import fs from 'fs/promises';
import assert from 'assert';
const BOTBROWSER_EXEC_PATH = process.env.BOTBROWSER_EXEC_PATH;
const BOT_PROFILE_PATH = process.env.BOT_PROFILE_PATH;
assert(BOTBROWSER_EXEC_PATH, 'BOTBROWSER_EXEC_PATH environment variable is not set');
assert(BOT_PROFILE_PATH, 'BOT_PROFILE_PATH environment variable is not set');
const browser = await puppeteer.launch({
browser: 'chrome',
executablePath: BOTBROWSER_EXEC_PATH,
headless: false, // Set to true for production
ignoreDefaultArgs: [
'--no-startup-window',
'--disable-crash-reporter',
'--disable-crashpad-for-testing',
'--disable-gpu-watchdog',
],
args: [
'--no-sandbox',
'--disable-blink-features=AutomationControlled',
'--disable-audio-output',
`--bot-profile=${BOT_PROFILE_PATH}`,
],
});
const page = (await browser.pages())[0];
await page.setRequestInterception(true);
let payloads = [];
await page.exposeFunction('__get_payloads', (key, value) => {
payloads.push({ a: key, b: value });
payloads.sort((x, y) => x.a.localeCompare(y.a));
});
page.on('request', async (request) => {
const url = request.url();
if (!url.startsWith('https://geo.captcha-delivery.com/interstitial/?initialCid=')) {
request.continue();
return;
}
const response = await axios.get(url, {
headers: {
'User-Agent': request.headers()['user-agent'],
'Accept-Language': request.headers()['accept-language'],
'Accept-Encoding': request.headers()['accept-encoding'],
Referer: request.headers()['referer'],
},
});
let { data } = response;
// Modify the response data
const match = data.match(
/\bfunction\s+([a-zA-Z_$][\w$]*)\(\s*([a-zA-Z_$][\w$]*)\s*,\s*([a-zA-Z_$][\w$]*)\s*\)\{if\("string"==typeof\s*\2\s*&&/
);
const fnName = match?.[1];
if (!fnName) {
throw new Error('Function name not found');
}
// inject the code after "}}"
const functionEndIndex = data.indexOf('}}', match.index + match[0].length);
if (functionEndIndex === -1) {
throw new Error('Function end not found');
}
const injectCode = `;window.__fn_${fnName}_backup = ${fnName};${fnName} = function(a,b) {window.__get_payloads(a,b);return window.__fn_${fnName}_backup(a, b);};`;
data = data.slice(0, functionEndIndex + 2) + injectCode + data.slice(functionEndIndex + 2);
await request.respond({ status: 200, contentType: 'text/html', body: data });
});
await page.goto(
'https://seatgeek.com/ncaa-mens-basketball-tournament-tickets/ncaa-basketball/2025-04-07-7-50-pm/16852258'
);
await new Promise((resolve) => setTimeout(resolve, 10000)); // Wait for 10 seconds
await browser.close();
await fs.writeFile('payloads.json', JSON.stringify(payloads, null, 2));
console.log('Payloads saved to payloads.json');