Skip to content

Instantly share code, notes, and snippets.

@torounit
Created December 28, 2017 18:59
Show Gist options
  • Save torounit/7ed8b32057f23ab608372410dd74b515 to your computer and use it in GitHub Desktop.
Save torounit/7ed8b32057f23ab608372410dd74b515 to your computer and use it in GitHub Desktop.
get cookie used headless chrome.
const Chromy = require('chromy')
const fs = require('fs')
let chromy = new Chromy()
async function main () {
chromy.chain()
.goto('https://example.com/login.php')
.type('#username', 'username')
.type('#password', 'password')
.click('#submit', {waitLoadEvent: true})
.getCookies()
.result((cookie) => {
fs.writeFileSync('./cookies.json', JSON.stringify(cookie))
console.log("save cookie!")
})
.end()
.then(_ => chromy.close())
.catch(e => {
console.log(e)
chromy.close()
})
}
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment