Created
June 8, 2019 15:01
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" }); | |
})(); |
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
Another way of accessing
localStorage
from withinpage.evaluate
actually worked in one of my projects.Discord encapsulates reference to
localStorage
object into a closure, and breaks it in a global execution context, so it is not accessible from scripts running within it anymore.We can actually restrict that by forcibly setting a reference to non-writable. See gist