import fs from 'fs/promises';
import fetch from 'node-fetch';
(async () => {
const challengeFile = 'input.json';
const engagementType = 'ENGAGEMENT_TYPE_VIDEO_LIKE';
const encryptedVideoId = 'YLFyc00Kg9c';
const raw = await fs.readFile(challengeFile, 'utf-8');
const data = JSON.parse(raw);
const { interpreterUrl, globalName, program } = data.bgChallenge;
const c = data.challenge;
Object.defineProperty(globalThis, 'window', { value: globalThis });
Object.defineProperty(globalThis, 'document', { value: {} });
Object.defineProperty(globalThis, 'navigator',{ value: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)' }, configurable: true });
const vmUrl = interpreterUrl.privateDoNotAccessOrElseTrustedResourceUrlWrappedValue.replace(/^\/\//, 'https://');
const resp = await fetch(vmUrl);
if (!resp.ok) throw new Error(`Fetch VM failed ${vmUrl}: ${resp.status}`);
const vmCode = await resp.text();
new Function(vmCode)();
const vm = globalThis[globalName];
if (!vm) throw new Error(`VM ${globalName} not found`);
await new Promise((resolve, reject) => {
vm.a(
program,
(asyncSnapshotFn, shutdownFn, passEventFn, checkCameraFn) => {
vm._asyncSnapshot = asyncSnapshotFn;
vm._shutdown = shutdownFn;
vm._passEvent = passEventFn;
vm._checkCamera = checkCameraFn;
resolve();
},
true,
undefined,
() => {},
[[], []]
);
});
const webResponse = await new Promise((resolve, reject) => {
const snap = vm._asyncSnapshot;
if (typeof snap !== 'function') return reject(new Error('asyncSnapshotFunction not found'));
snap(
(response) => resolve(response),
[
{ c, e: engagementType, encryptedVideoId },
null,
[],
false
]
);
});
console.log(webResponse);
})().catch(err => {
console.error(err);
process.exit(1);
});
I created such code to generate WebResponse token, which is used by YouTube after request like. But it has different length - 2850 +- 50, while the original (from browser) is always around 1950 +- 50.
Question
I created such code to generate WebResponse token, which is used by YouTube after request like. But it has different length - 2850 +- 50, while the original (from browser) is always around 1950 +- 50.
What did I do wrong?
Other details
No response
Checklist