Skip to content

Linux Support - Puppeteer for Token Fetching #35

@Novattz

Description

@Novattz

Collect discord tokens with puppeteer for linux users.

Install these in the same directory as Discord-Backup!

  • npm install puppeteer @gilgames/discord-detours

Make a javascript file in the same directory as Discord-Backup.

  • sudo nano index.js

Initial login script

  • Place this script in index.js and log in to discord via a non-headless browser:
let puppeteer = require('puppeteer');
const detours = require("@gilgames/discord-detours");

(async () => {
    const browser = await puppeteer.launch({ userDataDir: './user_data', headless: false });
    const page = await browser.newPage();
    await page.goto('https://discord.com/channels/@me');
    await page.setViewport({ width: 1080, height: 1024 });
    const serializedAPI = detours.serializeModule(detours.api);
    await page.evaluate(detours.injectModule, serializedAPI);
    const token = await page.evaluate(() => window.discordDetours.findFunctionByName("getToken")());
    console.log(token);
    await browser.close(); 
})();
  • After logging in, replace the initial login script in index.js with this one to automatically fetch the token on subsequent runs:
let puppeteer = require('puppeteer');
const detours = require("@gilgames/discord-detours");

(async () => {
    const browser = await puppeteer.launch({ userDataDir: './user_data' });
    const page = await browser.newPage();
    await page.goto('https://discord.com/channels/@me');
    await page.setViewport({ width: 1080, height: 1024 });
    const serializedAPI = require("@gilgames/discord-detours").serializeModule(require("@gilgames/discord-detours").api);
    await page.evaluate(detours.injectModule, serializedAPI);
    const token = await page.evaluate(() => window.discordDetours.findFunctionByName("getToken")());
    const user_info = await page.evaluate(() => {
        const usernameElement = document.querySelector('span[class="text-gray-400 font-semibold"]');
        const username = usernameElement ? usernameElement.innerText.split('#')[0] : 'Unknown';
        const discriminator = usernameElement ? usernameElement.innerText.split('#')[1] : '0000';
        return { username, discriminator };
    });
    console.log(JSON.stringify({ token, username: user_info.username, discriminator: user_info.discriminator }));
    await browser.close();
})();
  • Modified fetch_tokens.py
import subprocess
import json

def fetch():
    try:
        result = subprocess.run(['node', 'index.js'], capture_output=True, text=True, check=True)
        token_data = json.loads(result.stdout)
        return [[token_data['token'], f"{token_data['username']}#{token_data['discriminator']}", token_data['token'], "Discord"]]
    except subprocess.CalledProcessError as e:
        print(f"Failed to execute script: {e}")
        return []
    except json.JSONDecodeError as e:
        print(f"Error decoding JSON from script output: {e}")
        return []
  • This will now allow you to automatically backup and restore using the built in choices in main.py without having to manually get your token.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions