Last active
March 22, 2021 16:02
-
-
Save mandadimuralidharreddy/eaf36204443b44e7c4ccc4fe356460f5 to your computer and use it in GitHub Desktop.
Facebook login using google chrome headless browser
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
//install dev vesrion of google chrome form https://www.chromium.org/getting-involved/dev-channel | |
//install chrome-remote-interface from npm npm install chrome-remote-interface | |
const CDP = require('chrome-remote-interface'); | |
CDP((protocol) => { | |
const {Page, Runtime} = protocol; | |
// First, need to enable the domains we're going to use. | |
Promise.all([ | |
Page.enable(), | |
Runtime.enable() | |
]).then(() => { | |
Page.navigate({url: 'https://www.facebook.com'}); | |
// Wait for window.onload before doing stuff. | |
Page.loadEventFired(() => { | |
const js = 'document.getElementById("email").value="youremail";document.getElementById("pass").value="yourpassword";document.getElementById("loginbutton").click()'; | |
Runtime.evaluate({expression: js}).then(result => { | |
setTimeout(function () { | |
Runtime.evaluate({expression: "document.getElementsByClassName('_2s25')[0].href"}).then(result => { | |
Page.navigate({url: result.result.value}); | |
setTimeout(function () { | |
const js1 = 'document.getElementById("fb-timeline-cover-name").textContent'; | |
Runtime.evaluate({expression: js1}).then(result => { | |
console.log('Your Name :' + result.result.value); | |
}); | |
},2000) | |
}) | |
},5000) | |
}); | |
}); | |
}); | |
}).on('error', (err) => { | |
console.error(err); | |
}); | |
// execute file using nodejs | |
//node facebook_headless_login_using_google_chrome.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment