Skip to content

Instantly share code, notes, and snippets.

@Mathspy
Created June 8, 2019 15:01
Show Gist options
  • Save Mathspy/55614eb2e9b8fc86c1dc814e50470ab1 to your computer and use it in GitHub Desktop.
Save Mathspy/55614eb2e9b8fc86c1dc814e50470ab1 to your computer and use it in GitHub Desktop.
A Discord login workaround that failed but contains many valuable knowledge I guess
const puppeteer = require("puppeteer");
// This works around Discord's security measurements
// to set values on localStorage before we go to discord.com/login
const setDomainLocalStorage = async (browser, url, values) => {
const page = await browser.newPage();
await page.setRequestInterception(true);
page.on("request", r => {
r.respond({
status: 200,
contentType: "text/plain",
body: "tweak me."
});
});
await page.goto(url);
await page.evaluate(values => {
const iframe = document.createElement("iframe");
iframe.onload = () => {
// iframes must be appended to the DOM in order to be loaded
// iframes do not load immediately nor synchronously
// now (after load) we can use iframe.contentWindow:
// window.localStorage = iframe.contentWindow.localStorage; // you can use it, but better is like:
const ifrLocalStorage = iframe.contentWindow.localStorage;
// But DO NOT: "document.body.removeChild(iframe);" because after it access on 'Storage' will be denied
Object.keys(values).forEach(key =>
ifrLocalStorage.setItem(key, values[key])
);
};
iframe.src = "about:blank";
document.body.appendChild(iframe);
}, values);
await page.close();
};
(async () => {
const browser = await puppeteer.launch();
await setDomainLocalStorage(browser, "https://discordapp.com/", {fingerprint: "fingerprint"});
const page = await browser.newPage();
await page.goto("https://discordapp.com/app");
const localStorageData = await page.evaluate(() => {
return new Promise(resolve => {
const iframe = document.createElement("iframe");
iframe.onload = () => {
const ifrLocalStorage = iframe.contentWindow.localStorage;
const json = {};
for (let i = 0; i < ifrLocalStorage.length; i++) {
const key = ifrLocalStorage.key(i);
json[key] = ifrLocalStorage.getItem(key);
}
resolve(json);
};
iframe.src = "about:blank";
document.body.appendChild(iframe);
});
});
console.log(localStorageData);
await page.waitFor(5000);
// await page.waitForSelector('a[href="/channels/@me"]');
await page.screenshot({ path: "screenshot.png" });
})();
@listingclown3
Copy link

This is old as heck but here's an updated version I made that works, puppeteer included

https://gist.github.com/listingclown3/7d5ac6e42a0cdc5ce85f28ededa3106b

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