Rayrun
← Back to Discord Forum

Auth/Persistent Sessions/Forever watching a page for changes

Hey guys! I have a few questions. I'm looking to automate certain tasks I do for a volunteer position I have. I'm a total beginner to this and I've tried to do some of these things myself but I keep running into walls (I'm actually not sure how to start/structure my file either)

The community has it's own site, which only uses discord auth, as well as a discord server.

  • I'd like to be able to log into discord once (since I use 2FA on my account) and ideally have playwright remembers it. (or it would be nice if playwright could use my main browser for it's tasks, instead of it's own chromium install)

  • Is it possible to watch a discord channel indefinitely, and grab message's and store their data in a csv/google sheet/online postgres db?

This thread is trying to answer question "Is it possible to use Playwright to automate tasks on Discord, including logging in once and remembering the session, and monitoring a channel indefinitely?"

4 replies
refactoreric

Hi, as much as I love Playwright, I'd suggest using APIs instead of browser automation. Browser automation is controlling software through the least programming-friendly interface. A (web) user interface is not intended to be used by automated processes. Small changes in the user interface can break your automation.

Also authentication providers will actively work against using browser automation to log in, to combat security issues/abuse.

Therefore, I would only use browser automation for testing the frontend of our own product, a product we are in control of, and where we can configure the security measures in our own test environment.

Instead of browser automation/Playwright, I'd suggest using the Discord API to automate processes revolving around a Discord channel.

Hi! Thank you so much for your thoughtful and detailed response! It's so nice when community members take the time to help newbies through stuff like this! I appreciate it, sincerely!

I would prefer to use an API as well but I just wanted to get a demo going of how things would work/the benefits/increase in productivity we'd see if I automated certain systems, I'm hoping they'll give me permissions to make a bot/integrate it into the server once I show them the demo!

Even though it's not an ideal solution, or the right way to do it, it does give me the oppurtunity to work with playwright and get a feel for it, so even though its likely to get replaced very quickly by a discord bot (if they feel like what I'm doing is cool!) -- I'd still like to try and give it a shot this way for the reasons mentioned above (Proof of concept + learning project)

So even though right now I'm learning to do it with discord, I think its super useful to learn how to manage sessions as well as see if its possible to watch for changes.

refactoreric

OK for a proof of concept, it could work. There's an answer here for connecting to an already running browser: https://stackoverflow.com/a/75431084/17402583

Alternatively you could probably use a persistent context in a self-defined location, which you always use to launch the browser for the Discord PoC 'bot': https://playwright.dev/python/docs/api/class-browsertype#browser-type-launch-persistent-context (then you only have to log it in once in a while)

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].