0

I have an application that updates GitHub usernames via API and an attribute that is only accessible via UI.

The flow of the application is as follows:

user submits form > write to sheet > trigger: filter sheet & POST to lambda > lambda event: update usernames and attribute > return update confirmation to sheet

When I run the application I get one of two errors

  1. INFO TimeoutError: Navigation timeout of 30000 ms exceeded
  2. Protocol error (Target.createTarget): Target closed

I've passed the following args to the browser from what I've seen in other discussions.

['--no-sandbox', '--use-gl=egl', '--single-process', '--headless']

Additionally, I had to set the browser context to incognito to get around authentication and redirects.

When I ran the application the first time, it successfully updated the username and the attribute for each user. When I rerun the application the usernames are change but receive either INFO TimeoutError: Navigation timeout of 30000 ms exceeded or Protocol error (Target.createTarget): Target closed for updating the attribute.

```
# Lambda logs success on first run
INFO    Promise { [ { status: 'fulfilled', value: [Object] } ] }

# Lambda errors
1. INFO TimeoutError: Navigation timeout of 30000 ms exceeded
2. Protocol error (Target.createTarget): Target closed

# Apps Script
Error   
Exception: Request failed for https://<url>.amazonaws.com returned code 503. 
Truncated server response: {"message":"Service Unavailable"} 
(use muteHttpExceptions option to examine full response)
```
async function updateAttr ({ username, password}, users, browser) {
    try {
        for (const {oldUsername, newUsername} of users) {
            let url = `https://<url>.github.com/stafftools/users/${oldUsername}/security`;
            let incognitoBrowser = await browser.createIncognitoBrowserContext();

            let page = await incognitoBrowser.newPage();
            await page.goto(url);
            
            const toggleUsernamePassword = '#js-pjax-container > div > div.auth-form-body.Details.js-details-container > button > span.Details-content--shown'
            await page.waitForSelector(toggleUsernamePassword);
            await page.click(toggleUsernamePassword);
            
            const usernameField = '#login_field';
            await page.click(usernameField);
            await page.keyboard.type(username);
            
            const passwordField = '#password';
            await page.click(passwordField);
            await page.keyboard.type(password);
            
            const signIn = '#js-pjax-container > div > div.auth-form-body.Details.js-details-container.open.Details--on > div > form > input.btn.btn-primary.btn-block'
            await page.waitForSelector(signIn);
            await page.click(signIn);
            
            await page.waitForNavigation();
            const editAttr = '#js-pjax-stafftools-container > div:nth-child(3) > div > details > summary';
            await page.waitForSelector(editAttr);
            await page.click(editAttr);
            
            const editNameID = await page.$('#name_id');
            await editNameID.click({ clickCount: 3 })
            await editNameID.type(newUsername);
            
            const submitNameId = '#js-pjax-stafftools-container > div:nth-child(3) > div > details > details-dialog > form > div.Box-footer > button';
            await page.click(submitNameId);
            await page.close();
        }
        return { puppeteer: {
                message: "attribute has been changed",
            }
        };
    } catch(error){
        if(error) console.log(error);
        return error;
    }
};
twesst
  • 11
  • 2
  • Your `waitForNavigation`/`click` looks like the [classic puppeteer gotcha race condition](https://github.com/puppeteer/puppeteer/issues/1412). Try removing `await page.waitForNavigation();`, or if that doesn't work, try `await Promise.all([page.waitForNavigation(), page.click(signIn)])`. BTW, you can [use the return value of `waitForSelector`](https://serpapi.com/blog/puppeteer-antipatterns/#not-using-the-return-value-of-waitforselector-and-waitforxpath). – ggorlen Mar 16 '23 at 23:20

0 Answers0