Question: I am having trouble finding a way to authenticate an user. 
When you start the Node JS Server manually this worked fine (and yeah its ugly code):

```
 if (data.URL.includes("https://share.url.com")) {
        await page.type('#userNameInput', 'user');
        await page.type('#passwordInput', 'pass');
        await page.click('#submitButton');

        await page.waitForNavigation({waitUntil: 'load'});
        await page.waitFor(6000);
    }

```

Sharepoint didnt know my user data so they navigated me to a login page where I could fill in the Login Information and then move to my requested site. But in the meantime there were 2 changed made: 1. This Login Page doesnt exist anymore, if the login information isnt found I just get linked to a page where it says "Sorry you don't have access to this page". The 2nd problem or change is that the node server is started by a service.

At the end I just need to somehow access the page and then take a screenshot of it. But the auth is making me trouble. I now need a workaround to this problem, but I cant think about other solutions.

**Puppeteer authenticate:** 

```
await page.authenticate({
    username: "user", 
    password: "pass"
});

```

This doesnt work or using this with an auth header doesnt work either.

**Saving user cred. in browser (chrom(ium)):**

I tried to save the user cred. for the page inside the browser, but this didnt have any affect.

**URL Auth:**

I tried to auth inside the URL like (<https://user:pass@share.url.com/bla/site.aspx>) but it doesnt work.

I am out of ideas how to approach this problem, have you got any suggestions how I could try this in an other way or did you see errors in my code or in my thoughts?

Thanks go to Bill Gates

Answer: 
About

> 
> Saving user cred. in browser (chrom(ium)):
> 
> 
> 

I had similar situation - I wanted to do screenshot from facebook when I'm logged in. To achieve it I did steps like:

1) Created temp user data dir

```
mkdir /tmp/puppeteer_test

```

2) Run Chrome with these arguments

```
/usr/bin/google-chrome --user-data-dir=/tmp/puppeteer_test --password-store=basic

```

3) Go to facebook.com, log into and then close the browser

4) Run puppeteer with appropriate arguments:

```
const browser = await puppeteer.launch({
  headless: false,
  executablePath: '/usr/bin/google-chrome',
  args: ['--user-data-dir=/tmp/puppeteer_test']
});
const page = await browser.newPage();
await page.goto('https://facebook.com', { waitUntil: 'networkidle2' });
await page.screenshot({path: 'facebook.png'});
await browser.close();

```
I am doing following for SharePoint

```
const browser = await puppeteer.launch();
const page = await browser.newPage();

await page.setViewport({width: 1920, height: 1080});

// Open SharePoint page
console.log("Opening page");
await page.goto('https://mytenant.sharepoint.com/sites/mysite');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Page opened");

// Input username
console.log("Inputting username");
await page.type('#i0116', 'user@mytenant.com');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Username input completed");

// Input password
console.log("Inputting password");
await page.type('#i0118', 'password123');
await page.click('#idSIButton9');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("Password input completed");

// Stay signed in
console.log("staying signed in");
await page.keyboard.press('Enter');
await page.waitForNavigation({ waitUntil: 'networkidle0' });
console.log("staying signed in completed");

// Wait, because rendering is picky
await page.waitFor(6000);

```