Skip to content

Instantly share code, notes, and snippets.

@lvaccaro
Created September 4, 2018 22:40
Show Gist options
  • Save lvaccaro/df4e9ca5415615f0764c5cfbfc6ed908 to your computer and use it in GitHub Desktop.
Save lvaccaro/df4e9ca5415615f0764c5cfbfc6ed908 to your computer and use it in GitHub Desktop.
Tweet from Google Headless, example https://twitter.com/0xVaccaro/status/1037107238593339392
const puppeteer = require('puppeteer')
const sleep = require('await-sleep')
const screenshot = 'twitter.png'
const USERNAME = ''
const PASSWORD = ''
const HTMLMESSAGE = 'My first tweet from puppeteer (Headless Chrome Node API)'
;
(async () => {
const browser = await puppeteer.launch({headless: true})
const page = await browser.newPage()
await page.goto('https://twitter.com/login')
await sleep(500)
await page.type('input[name="session[username_or_email]"]', USERNAME)
await page.type('.js-password-field', PASSWORD)
await page.click('button[type="submit"]')
await page.waitForNavigation()
await page.click('#global-new-tweet-button')
await page.type('div[aria-labelledby="Tweetstorm-tweet-box-0-label Tweetstorm-tweet-box-0-text-label"]', HTMLMESSAGE)
await page.click('#Tweetstorm-tweet-box-0 .tweet-box-content .TweetBoxToolbar .TweetBoxToolbar-tweetButton .buttons button.SendTweetsButton')
await page.screenshot({ path: screenshot })
browser.close()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment