Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Redirect stops before the final destination that has an error Name Not Resolved #12343

Closed
2 tasks
kazanemed opened this issue Apr 25, 2024 · 4 comments
Closed
2 tasks

Comments

@kazanemed
Copy link

kazanemed commented Apr 25, 2024

Minimal, reproducible example

await page.setRequestInterception(true);

            await page.on(PageEmittedEvents.Request, (req) => {
              if ([
                "script", "fetch",
                   "xhr",
              "stylesheet", "image", "font", "media", "texttrack", "eventsource",
              "websocket", "manifest", "other"
            ].includes(req.resourceType())) {
              return req.abort();
            }
            console.log(req.url())
            req.continue();
            });
            

            const response = await page?.goto("https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://tinyurl.com/mlkdaylunch&ved=2ahUKEwjAxbnrp9iFAxWA9gIHHSiSBMsQFnoECBQQAQ&usg=AOvVaw1zSAE11qJ2cPYgP22N71-M", { waitUntil: ['networkidle0'] })

Error string

net::ERR_NAME_NOT_RESOLVED

Bug behavior

  • Flaky
  • PDF

Background

It happens with this URL:

https://www.google.com/url?sa=t&source=web&rct=j&opi=89978449&url=https://tinyurl.com/mlkdaylunch&ved=2ahUKEwjAxbnrp9iFAxWA9gIHHSiSBMsQFnoECBQQAQ&usg=AOvVaw1zSAE11qJ2cPYgP22N71-M


When printing requests URL's, it does reach the final destination https://una.presence.io/form/mlk-day-lunch which is an invalid url that must show the error : net::ERR_NAME_NOT_RESOLVED . But the problem it's showing that the URL before it https://tinyurl.com/mlkdaylunch that has the error of : net::ERR_NAME_NOT_RESOLVED. Which results to not show the final url destination in response interceptor.

In fact, when you try to start page.goto from the before final url : https://tinyurl.com/mlkdaylunch, it will work fine and shows that the url that comes after it is not resolved ( which is correct )

Expectation

net::ERR_NAME_NOT_RESOLVED at https://una.presence.io/form/mlk-day-lunch

Reality

net::ERR_NAME_NOT_RESOLVED at https://tinyurl.com/mlkdaylunch

Puppeteer configuration file (if used)

const browser = await puppeteer.launch({
          headless: 'new',
          executablePath: await chromium.executablePath,
          args: [
            '--disable-gpu',
            '--disable-dev-shm-usage',
            '--disable-setuid-sandbox',
            '--no-first-run',
            '--no-sandbox',
            '--no-zygote',
            '--ignore-certificate-errors',
            '--ignore-certificate-errors-spki-list',
            '--enable-features=NetworkService',
            '--disable-features=HttpsUpgrades',
            '--disable-extensions',
            '--disable-default-apps',
            '--disable-background-networking',
            '--disable-infobars',
          ]
        },
        );

Puppeteer version

21.10.0

Node version

18.17.0

Package manager

npm

Package manager version

9.6.7

Operating system

macOS

Copy link

github-actions bot commented Apr 25, 2024

This issue has an outdated Puppeteer version: 21.10.0. Please verify your issue on the latest 22.7.1 version. Then update the form accordingly.


Analyzer run

@github-actions github-actions bot added invalid and removed invalid labels Apr 25, 2024
@Lightning00Blade
Copy link
Collaborator

There is no expectation from Puppeteer here to return the last response URL, we return the one the user tried to navigate to.
You could work around this by:

let lastNavigationRequest;
page.on('request', req =>{
    //...
    if (req.isNavigationRequest() && req.frame() === page.mainFrame()) {
      lastNavigationRequest = req;
    }
    // Prevent the error form throwing
    await page.goto(...).catch(() => {});
    console.log(lastNavigationRequest.url());
})

Currently Puppeteer does not provide a means to get the request from a failed navigation directly from the page.goto() command.

@kazanemed
Copy link
Author

@Lightning00Blade Thanks for your reply however I think there was a misunderstood about the nature of the bug i'm referring to.

For the error : Name Not Resolved , i don't want to get rid of it, in fact, i want to know where exactly in URL's chain it happened, which logically MUST be in the last url that appears. But when i catch the error while navigation, it shows that the error of Name Not Resolved has appeared in the url before final destination ( which is wrong )

@Lightning00Blade
Copy link
Collaborator

Lightning00Blade commented Apr 26, 2024

How puppeteer works is that is sends a command and it fails due to request being canceled,
in such cases we don't try to find the HTTP response associated with the error as we get it from the command.
There is a feature request to support getting the last response from the page #11555
But this is already achievable through page.on('request') with example above given.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants