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

Bad error when using anchor hash in URL #213

Closed
peterbe opened this issue May 29, 2018 · 4 comments
Closed

Bad error when using anchor hash in URL #213

peterbe opened this issue May 29, 2018 · 4 comments

Comments

@peterbe
Copy link
Owner

peterbe commented May 29, 2018

E.g.

const minimalcss = require('./index')
minimalcss.minimize({
  urls: ['https://www.peterbe.com#other-important-security-considerations']
  // urls: ['https://www.peterbe.com']
}).then(result => {
  console.log('OUTPUT', result.finalCss.length, result.finalCss)
}).catch(error => {
  console.error(`Failed the minimize CSS: ${error}`)
})

When I run it:

▶ time node --trace-warnings hack.js
Failed the minimize CSS: Error: Navigation Timeout Exceeded: 30000ms exceeded
node --trace-warnings hack.js  1.23s user 0.25s system 4% cpu 31.588 total
@peterbe
Copy link
Owner Author

peterbe commented May 29, 2018

Note in the sample code above, if I switch to use urls: ['https://www.peterbe.com'] instead, it works.

@peterbe
Copy link
Owner Author

peterbe commented May 29, 2018

So according to the documentation the call to page.goto can throw errors if, amongst other things, "target URL is invalid" but we aren't prepared for any errors thrown on that line:

response = await page.goto(pageUrl, { waitUntil: 'networkidle0' });
or
response = await page.goto(pageUrl);

@peterbe
Copy link
Owner Author

peterbe commented May 29, 2018

This code:

const puppeteer = require('puppeteer');

const Url = "https://www.peterbe.com#other-important-security-considerations";
// const Url="https://www.peterbe.com";

(async () => {
  const browser = await puppeteer.launch();
  console.log('Browser version', await browser.version());

  const page = await browser.newPage();
  await page.setRequestInterception(true);
  await page.setDefaultNavigationTimeout(5 * 1000);
  page.on('request', request => {
    const requestUrl = request.url();
    console.log(requestUrl);
    request.continue();
  });
  page.on('response', response => {
    console.log(response.status(), response.url());
  });
  await page.setJavaScriptEnabled(false);
  await page.goto(Url);
  const htmlVanilla = await page.content();
  await page.setJavaScriptEnabled(true);
  const response = await page.goto(Url, {
    waitUntil: 'networkidle0'
  });
  const htmlJS = await page.content();
  await browser.close();
})();

When you run that it will crash and fail with Error: Navigation Timeout Exceeded: 5000ms exceeded.
But when I upgraded to puppeteer 1.4.0 that code above works.

@peterbe
Copy link
Owner Author

peterbe commented May 29, 2018

Ignore this comment above about not catching errors around await page.goto(...). Those lines of code are actually already in a try{...} catch(e) {return safeReject(e)}.

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

No branches or pull requests

1 participant