Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/ ixer Public

Automate X (Twitter) posting with Playwright and Node.js

License

Notifications You must be signed in to change notification settings

127/ixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

6 Commits

Repository files navigation

ixer — post to X via Playwright

The tweet.js script opens X (Twitter) in Playwright, logs in (or uses saved state from twitter-auth.json), and posts a tweet. The post text comes from TWEET_TEXT.

Requirements

  • Node.js 18+ and npm
  • Playwright browsers installed: npm install and npx playwright install
  • X account with username/password and optionally a TOTP secret for 2FA

Setup

  1. Install dependencies and browsers:
    npm install
    npx playwright install
  2. Copy and fill env vars:
    cp .env.example .env
    In .env, set TWITTER_USERNAME and TWITTER_PASSWORD. For 2FA you can add TWITTER_2FA_SECRET (TOTP secret) or a one-time TWITTER_2FA_CODE.

Environment variables

  • TWEET_TEXT — post text (default: "Привет, X!").
  • BROWSERchromium (default) or webkit.
  • HEADLESStrue|false; with MANUAL_LOGIN=true the window is always visible.
  • MANUAL_LOGINtrue|false; when true, log in manually in the opened browser, then press Enter in the terminal.
  • TWITTER_USERNAME, TWITTER_PASSWORD — used for automatic login (MANUAL_LOGIN=false).
  • TWITTER_2FA_SECRET or TWITTER_2FA_CODE — pass 2FA without manual input.
  • Session persists to twitter-auth.json next to the script.

Run

Auto-login with creds from .env:

TWEET_TEXT="Post via Playwright" npm run tweet

First run with manual login (if there are captchas/confirmations):

MANUAL_LOGIN=true HEADLESS=false npm run tweet
# log in in the opened browser, return to the terminal and press Enter

Subsequent background run using saved session:

HEADLESS=true TWEET_TEXT="New post" npm run tweet

Reset session

Delete twitter-auth.json to log in again (manual or automatic).

About

Automate X (Twitter) posting with Playwright and Node.js

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /