Skip to content

Instantly share code, notes, and snippets.

@k0d3d
Created February 25, 2019 10:46
Show Gist options
  • Save k0d3d/503462b77ed9d13f3abf54826df397a0 to your computer and use it in GitHub Desktop.
Save k0d3d/503462b77ed9d13f3abf54826df397a0 to your computer and use it in GitHub Desktop.
First browserless script
const puppeteer = require("puppeteer");
module.exports = async function(context, req) {
context.log("Started working function");
const browser = await puppeteer.connect({
browserWSEndpoint: "ws://d.ixit.com.ng"
});
const page = await browser.newPage();
await page.goto("https://www.instagram.com/accounts/login");
await page.setViewport({ width: 1237, height: 670 });
await page.waitForSelector("[name=username]");
await page.type("[name=username]", "moonshootersng");
await page.type("[name=password]", "xxxxxx");
await page.click("[type=submit]");
try {
await page.waitForNavigation({ timeout: 2000 });
await page.goto("https://www.instagram.com/accounts/activity/");
const isLoggedIn = await page.$("h1");
if (isLoggedIn) {
context.res = {
body: 'Session Saved',
headers: {
"Content-Type": "text/html"
}
};
} else {
context.res = {
body: await page.content(),
headers: {
"Content-Type": "text/html"
}
};
}
} catch (e) {
await page.waitForSelector("[role=alert]");
const alertElement = await page.$eval(
"[role=alert]",
node => node.innerHTML
);
context.res = {
status: 401,
body: alertElement
};
}
await browser.close();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment