add wbstream auth support
This commit is contained in:
1 parent
221c4f595f
commit
b341370904
18 files changed
+373
-77
No files matched your search
@@ -12,6 +12,7 @@
|
||||
<div class="tab-action-btn" id="btnVkCookies" title="Export VK cookies to vk-cookies.json for headless mode">VK Cookies</div>
|
||||
<div class="tab-action-btn" id="btnYandexCookies" title="Export Yandex cookies to cookies-yandex.json for headless mode">Yandex Cookies</div>
|
||||
<div class="tab-action-btn" id="btnDionCookies" title="Export DION cookies to cookies-dion.json for headless mode">DION Cookies</div>
|
||||
<div class="tab-action-btn" id="btnWBStreamCookies" title="Export WB Stream cookies to cookies-wbstream.json for headless mode">WB Cookies</div>
|
||||
<div class="tab-action-btn settings" id="btnSettings" title="Settings">Settings</div>
|
||||
<div class="tab-action-btn bot" id="tabBot">Bot: Off</div>
|
||||
</div>
|
||||
|
||||
@@ -17,21 +17,24 @@ export const DION_URL = 'https://dion.vc/';
|
||||
export const VK_LOGIN_URL = 'https://vk.com/';
|
||||
export const YANDEX_LOGIN_URL = 'https://passport.yandex.ru/auth?retpath=https%3A%2F%2Ftelemost.yandex.ru%2F';
|
||||
export const DION_LOGIN_URL = 'https://dion.vc/login';
|
||||
export const WBSTREAM_LOGIN_URL = 'https://stream.wb.ru/login';
|
||||
export const VK_AUTH_COOKIE = 'remixsid';
|
||||
export const YANDEX_AUTH_COOKIE = 'Session_id';
|
||||
export const DION_AUTH_COOKIE = 'vc-refresh-token';
|
||||
export const WBSTREAM_AUTH_COOKIE = 'x_wbaas_token';
|
||||
|
||||
export const SESSION_PARTITION = 'persist:creator';
|
||||
export const WINDOW_WIDTH = 1200;
|
||||
export const WINDOW_HEIGHT = 800;
|
||||
|
||||
export const USER_AGENT =
|
||||
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) ' +
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
||||
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ' +
|
||||
'AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36';
|
||||
|
||||
export const VK_COOKIE_DOMAINS = ['vk.com', 'vk.ru'];
|
||||
export const YANDEX_COOKIE_DOMAINS = ['yandex.ru', 'yandex.net', 'ya.ru'];
|
||||
export const DION_COOKIE_DOMAINS = ['dion.vc'];
|
||||
export const WBSTREAM_COOKIE_DOMAINS = ['stream.wb.ru', 'wb.ru', 'wildberries.ru'];
|
||||
|
||||
export enum Selector {
|
||||
VK_ADMIT = '[data-testid="calls_waiting_hall_promote"]',
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { app } from 'electron';
|
||||
import { app, protocol } from 'electron';
|
||||
import { TabManager } from './tab-manager';
|
||||
import { createWindow } from './window';
|
||||
import { registerIpcHandlers } from './ipc';
|
||||
@@ -7,7 +7,12 @@ const tabManager = new TabManager();
|
||||
|
||||
registerIpcHandlers(tabManager);
|
||||
|
||||
protocol.registerSchemesAsPrivileged([
|
||||
{ scheme: 'wbstream', privileges: { standard: true, secure: true, supportFetchAPI: true } },
|
||||
]);
|
||||
|
||||
app.whenReady().then(() => {
|
||||
protocol.handle('wbstream', () => new Response(null, { status: 204 }));
|
||||
const win = createWindow(tabManager);
|
||||
tabManager.mainWindow = win;
|
||||
});
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
} from '../constants';
|
||||
import { TunnelMode, Platform, BotSettings, HeadlessStartArgs } from '../types';
|
||||
|
||||
@@ -101,6 +102,7 @@ export function registerIpcHandlers(tabManager: TabManager): void {
|
||||
let domains: string[];
|
||||
if (domain === 'yandex') domains = YANDEX_COOKIE_DOMAINS;
|
||||
else if (domain === 'dion') domains = DION_COOKIE_DOMAINS;
|
||||
else if (domain === 'wbstream') domains = WBSTREAM_COOKIE_DOMAINS;
|
||||
else domains = VK_COOKIE_DOMAINS;
|
||||
const filtered = all.filter((cookie) => {
|
||||
return cookie.domain != null && domains.some((d) => cookie.domain!.includes(d));
|
||||
|
||||
@@ -23,12 +23,15 @@ import {
|
||||
VK_COOKIE_DOMAINS,
|
||||
YANDEX_COOKIE_DOMAINS,
|
||||
DION_COOKIE_DOMAINS,
|
||||
WBSTREAM_COOKIE_DOMAINS,
|
||||
VK_LOGIN_URL,
|
||||
YANDEX_LOGIN_URL,
|
||||
DION_LOGIN_URL,
|
||||
WBSTREAM_LOGIN_URL,
|
||||
VK_AUTH_COOKIE,
|
||||
YANDEX_AUTH_COOKIE,
|
||||
DION_AUTH_COOKIE,
|
||||
WBSTREAM_AUTH_COOKIE,
|
||||
LOG_CAPTURE_SNIPPET,
|
||||
} from '../constants';
|
||||
import { BotManager } from '../bot/bot-manager';
|
||||
@@ -278,6 +281,16 @@ export class TabManager {
|
||||
binaryPath: this.headlessVKPath,
|
||||
getCookies: () => this.getVKCookies(),
|
||||
};
|
||||
case Platform.WBStream:
|
||||
return {
|
||||
tunnelMode: TunnelMode.HeadlessWBStream,
|
||||
authCookie: WBSTREAM_AUTH_COOKIE,
|
||||
loginUrl: WBSTREAM_LOGIN_URL,
|
||||
cookieDomains: WBSTREAM_COOKIE_DOMAINS,
|
||||
platformName: 'WB Stream',
|
||||
binaryPath: this.headlessWBStreamPath,
|
||||
getCookies: () => this.getWBStreamCookies(),
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
@@ -306,22 +319,6 @@ export class TabManager {
|
||||
return;
|
||||
}
|
||||
|
||||
if (platform === Platform.WBStream) {
|
||||
tab.tunnelMode = TunnelMode.HeadlessWBStream;
|
||||
this.killRelay(tabId, tab);
|
||||
const wbArgs = ['--resources', 'default'];
|
||||
if (joinTarget) wbArgs.push('--room', joinTarget);
|
||||
const proc = spawn(this.headlessWBStreamPath, wbArgs, {
|
||||
stdio: ['ignore', 'pipe', 'pipe'],
|
||||
});
|
||||
tab.relay = proc;
|
||||
this.attachProcessOutput(proc, tabId);
|
||||
proc.on('close', (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const config = this.headlessConfig(platform);
|
||||
if (!config) {
|
||||
this.sendLog(tabId, `Unsupported headless platform: ${platform}`);
|
||||
@@ -329,12 +326,19 @@ export class TabManager {
|
||||
}
|
||||
tab.tunnelMode = config.tunnelMode;
|
||||
let cookies = await config.getCookies();
|
||||
if (!cookies.some((c) => c.name === config.authCookie)) {
|
||||
const refreshCookie = platform === Platform.WBStream ? 'wbx-refresh' : config.authCookie;
|
||||
const needsLogin = !cookies.some((c) => c.name === refreshCookie);
|
||||
if (needsLogin) {
|
||||
this.sendLog(tabId, `No ${config.platformName} session found, opening login.`);
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_REQUIRED, { tabId, url: config.loginUrl });
|
||||
}
|
||||
await this.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
if (platform === Platform.WBStream) {
|
||||
this.sendLog(tabId, 'Waiting for x_wbaas_token, wbx-refresh, wbx-validation-key...');
|
||||
await this.waitForCookies(['x_wbaas_token', 'wbx-refresh', 'wbx-validation-key']);
|
||||
} else {
|
||||
await this.waitForLogin(config.cookieDomains, config.authCookie);
|
||||
}
|
||||
if (this._mainWindow && !this._mainWindow.isDestroyed()) {
|
||||
this._mainWindow.webContents.send(IPC.LOGIN_DONE, { tabId });
|
||||
}
|
||||
@@ -363,11 +367,8 @@ export class TabManager {
|
||||
proc.on('close', async (code) => {
|
||||
this.sendLog(tabId, `Headless exited with code ${code}`);
|
||||
if (sawAuthFailure) {
|
||||
this.sendLog(tabId, `${config.platformName} session rejected (401), clearing and re-prompting login.`);
|
||||
await this.clearAuthCookies(config.cookieDomains, config.authCookie);
|
||||
if (this.tabs.get(tabId) === tab) {
|
||||
this.startHeadless(tabId, platform, args);
|
||||
}
|
||||
if (this.tabs.get(tabId) === tab) this.startHeadless(tabId, platform, args);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -483,4 +484,63 @@ export class TabManager {
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
private waitForCookies(names: string[]): Promise<void> {
|
||||
return new Promise((resolve) => {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const remaining = new Set(names);
|
||||
const finish = () => {
|
||||
ses.cookies.removeListener('changed', onChanged);
|
||||
resolve();
|
||||
};
|
||||
const onChanged = (
|
||||
_e: Electron.Event,
|
||||
cookie: Electron.Cookie,
|
||||
_cause: string,
|
||||
removed: boolean,
|
||||
) => {
|
||||
if (removed) return;
|
||||
if (!remaining.has(cookie.name)) return;
|
||||
remaining.delete(cookie.name);
|
||||
if (remaining.size === 0) finish();
|
||||
};
|
||||
ses.cookies.on('changed', onChanged);
|
||||
Promise.all(names.map((name) => ses.cookies.get({ name }))).then((results) => {
|
||||
results.forEach((found, i) => {
|
||||
if (found.length > 0) remaining.delete(names[i]);
|
||||
});
|
||||
if (remaining.size === 0) finish();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async getWBStreamCookies(): Promise<{ name: string; value: string }[]> {
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const all = await ses.cookies.get({});
|
||||
return all
|
||||
.filter((c) => c.domain != null && WBSTREAM_COOKIE_DOMAINS.some((d) => c.domain!.includes(d)))
|
||||
.map((c) => ({ name: c.name, value: c.value }));
|
||||
}
|
||||
|
||||
async setWBStreamDeviceId(id: string): Promise<void> {
|
||||
if (!id) return;
|
||||
const ses = session.fromPartition(SESSION_PARTITION);
|
||||
const existing = await ses.cookies.get({ url: 'https://stream.wb.ru/', name: '__wb_device_id' });
|
||||
if (existing.length > 0 && existing[0].value === id) return;
|
||||
try {
|
||||
await ses.cookies.set({
|
||||
url: 'https://stream.wb.ru/',
|
||||
name: '__wb_device_id',
|
||||
value: id,
|
||||
domain: 'stream.wb.ru',
|
||||
path: '/',
|
||||
secure: true,
|
||||
httpOnly: false,
|
||||
expirationDate: Math.floor(Date.now() / 1000) + 60 * 60 * 24 * 365 * 5,
|
||||
});
|
||||
console.log(`[wb-device-id] persisted ${id}`);
|
||||
} catch (err) {
|
||||
console.log(`[wb-device-id] failed to persist:`, err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -67,11 +67,39 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
|
||||
const autoclickers = new Map<number, { telemost: TelemostAutoclick; vk: VkAutoclick }>();
|
||||
|
||||
const wbDeviceIdHook = `(function(){
|
||||
try {
|
||||
var key = 'wb_auth_api_device_id';
|
||||
var existing = localStorage.getItem(key);
|
||||
if (existing) console.log('[WB_DEVICE_ID]', existing);
|
||||
var orig = Storage.prototype.setItem;
|
||||
Storage.prototype.setItem = function(k, v) {
|
||||
if (k === key) console.log('[WB_DEVICE_ID]', v);
|
||||
return orig.apply(this, arguments);
|
||||
};
|
||||
} catch (e) {}
|
||||
})();`;
|
||||
|
||||
win.webContents.on('did-attach-webview', (_e, wvContents) => {
|
||||
wvContents.on('before-input-event', (_e, input) => {
|
||||
if (input.key === 'F12') wvContents.openDevTools();
|
||||
});
|
||||
|
||||
wvContents.on('will-navigate', (event, url) => {
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) event.preventDefault();
|
||||
});
|
||||
wvContents.setWindowOpenHandler(({ url }) => {
|
||||
if (!url.startsWith('http://') && !url.startsWith('https://')) return { action: 'deny' };
|
||||
return { action: 'allow' };
|
||||
});
|
||||
|
||||
wvContents.on('dom-ready', () => {
|
||||
const url = wvContents.getURL();
|
||||
if (url.includes('stream.wb.ru')) {
|
||||
wvContents.executeJavaScript(wbDeviceIdHook, true).catch(() => {});
|
||||
}
|
||||
});
|
||||
|
||||
wvContents.on('did-navigate', (_e, url) => {
|
||||
const wcId = wvContents.id;
|
||||
if (!autoclickers.has(wcId)) {
|
||||
@@ -102,6 +130,11 @@ export function createWindow(tabManager: TabManager): BrowserWindow {
|
||||
handleBotCallLink(tabManager, msg, Platform.VK);
|
||||
handleBotCallLink(tabManager, msg, Platform.Telemost);
|
||||
|
||||
const deviceIdMatch = msg.match(/\[WB_DEVICE_ID\]\s+(\S+)/);
|
||||
if (deviceIdMatch) {
|
||||
tabManager.setWBStreamDeviceId(deviceIdMatch[1]).catch(() => {});
|
||||
}
|
||||
|
||||
const callStatus = parseCallStatus(msg);
|
||||
if (callStatus) {
|
||||
console.log('[MAIN] Cached status for', callStatus.tabId, ':', callStatus.status);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Platform, Bridge, LogPanel, TunnelMode, Webview } from '../types';
|
||||
import { SESSION_PARTITION, HOOK_POLL_INTERVAL_MS, CALL_CREATOR_INJECT_DELAY_MS } from '../constants';
|
||||
import { SESSION_PARTITION, HOOK_POLL_INTERVAL_MS, CALL_CREATOR_INJECT_DELAY_MS, USER_AGENT } from '../constants';
|
||||
import { RendererTabManager } from './tab-manager';
|
||||
|
||||
declare const window: Window & { bridge: Bridge };
|
||||
@@ -40,9 +40,9 @@ export function renderContent(tm: RendererTabManager): void {
|
||||
}
|
||||
|
||||
welcome.style.display = 'none';
|
||||
logsPanel.style.display = 'flex';
|
||||
|
||||
const activeTab = tm.tabs[tm.activeTabId];
|
||||
logsPanel.style.display = activeTab.loginWebview ? 'none' : 'flex';
|
||||
hookPanel.style.display = activeTab.headless ? 'none' : 'flex';
|
||||
logsPanel.classList.toggle('relay-only', activeTab.headless === true);
|
||||
if (activeTab.loginWebview) {
|
||||
@@ -152,7 +152,7 @@ export function attachLoginWebview(tm: RendererTabManager, tabId: string, url: s
|
||||
const webview = document.createElement('webview') as unknown as Webview;
|
||||
webview.setAttribute('src', url);
|
||||
webview.setAttribute('partition', SESSION_PARTITION);
|
||||
webview.setAttribute('useragent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36');
|
||||
webview.setAttribute('useragent', USER_AGENT);
|
||||
webview.classList.add('webview-full');
|
||||
webview.dataset.tabId = tabId;
|
||||
document.getElementById('content')!.appendChild(webview);
|
||||
@@ -185,7 +185,7 @@ export function loadURL(tm: RendererTabManager, url: string): void {
|
||||
webview.setAttribute('partition', SESSION_PARTITION);
|
||||
webview.setAttribute('nodeintegration', '');
|
||||
webview.setAttribute('nodeintegrationinsubframes', '');
|
||||
webview.setAttribute('useragent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36');
|
||||
webview.setAttribute('useragent', USER_AGENT);
|
||||
webview.classList.add('webview-full');
|
||||
webview.dataset.tabId = tm.activeTabId;
|
||||
document.getElementById('content')!.appendChild(webview);
|
||||
|
||||
@@ -83,6 +83,13 @@ function bindActionBarEvents(): void {
|
||||
'No DION cookies found.\nPlease log into DION (dion.vc) first.',
|
||||
);
|
||||
});
|
||||
document.getElementById('btnWBStreamCookies')!.addEventListener('click', () => {
|
||||
exportCookies(
|
||||
'wbstream',
|
||||
'cookies-wbstream.json',
|
||||
'No WB Stream cookies found.\nPlease log into stream.wb.ru first.',
|
||||
);
|
||||
});
|
||||
document.getElementById('btnSettings')!.addEventListener('click', openSettings);
|
||||
document.getElementById('tabBot')!.addEventListener('click', () => {
|
||||
if (!tm.botSettings.token || !tm.botSettings.groupId) {
|
||||
|
||||
Reference in new issue
Block a user