Skip to content

Instantly share code, notes, and snippets.

@DevGod100
Last active March 7, 2024 15:01
Show Gist options
  • Save DevGod100/6b1c93379071804b54995e190b99623c to your computer and use it in GitHub Desktop.
Save DevGod100/6b1c93379071804b54995e190b99623c to your computer and use it in GitHub Desktop.
const { launch } = require("puppeteer");
(async () => {
// Launch puppeteer instance
console.log("Launching Puppeteer browser...");
const browser = await launch({
headless: "new"
});
//In the near future `headless: true` will default to the new Headless mode headless: "new"
const page = await browser.newPage();
const discordToken = process.env.DISCORD_TOKEN; // Your Discord Token, How To Get Your Discord Token -> https://www.youtube.com/watch?v=YEgFvgg7ZPI&ab_channel=GaugingGadgets
//Added env variable to secure token
// Local Storage error with Puppeteer, found bypass, CREDIT: https://gist.github.com/zelbov/58e9fbbe5157bf61067d2693118dd09a
const bypassLocalStorageOverride = (page) =>
page.evaluateOnNewDocument(() => {
// Preserve localStorage as separate var to keep it before any overrides
let __ls = localStorage;
// Restrict closure overrides to break global context reference to localStorage
Object.defineProperty(window, "localStorage", {
writable: false,
configurable: false,
value: __ls,
});
});
console.log(
"Redirecting to https://discord.com/app ... (May take a few seconds)"
);
// Calling function before storing token into Discord so that errors don't occur
bypassLocalStorageOverride(page);
await page.goto("https://discord.com/app");
// Setting token into Discord Local Storage (Don't worry it's not being sent/stored anywhere, this is how Discord does it)
await page.evaluate((token) => {
localStorage.setItem("token", `"${token}"`);
}, discordToken);
// Navigate to a page where you want to use the local storage value
await page.goto(""); // The discord channel / App Authorization that you want to log into Discord for...
console.log("Successfully logged in...");
await page.waitForTimeout(5000); // Wait for page to load
// Do whatever you want here afterwards, I just decided to take a screenshot for proof
await page.screenshot({ path: "output.png" });
// Ending proccess
await browser.close();
})();
@hmduc1603
Copy link

Hi, I got an error when applied your code

Redirecting to https://discord.com/app ... (May take a few seconds)
ProtocolError: Protocol error (Page.navigate): Cannot navigate to invalid URL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment