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] Malformed URL leads to UnhandledPromiseRejection #5065

Closed
roikoren755 opened this issue Jan 20, 2021 · 0 comments · Fixed by #5090
Closed

[BUG] Malformed URL leads to UnhandledPromiseRejection #5065

roikoren755 opened this issue Jan 20, 2021 · 0 comments · Fixed by #5090

Comments

@roikoren755
Copy link

roikoren755 commented Jan 20, 2021

Context:

  • Playwright Version: 1.7.1
  • Operating System: both on Mac running locally, and when ran via a Google CloudFunction on a linux based docker
  • Node.js version: 13.14.0 locally, 12.20.0 on Google CloudFunction
  • Browser: chromium
  • Extra: We couldn't get the CloudFunction to run with just Playwright, but installing Chromium via Puppeteer and using that executable worked 😆 . Locally I am using just Playwright.

Code Snippet

Help us help you! Put down a short code snippet that illustrates your bug and
that we can run and debug locally. For example:

const {chromium, webkit, firefox} = require('playwright');

(async () => {
  const browser = await chromium.launch();
  const page = await browser.newPage({ ignoreHTTPSErrors: true });
  await page.goto('https://www.youtube Panel Title.com/'); // Notice the spaces in the URL
})();

Describe the bug
When passing a malformed URL to the page.goto method, an UnhandledPromiseRejection is thrown, even if I wrap my code in a try-catch block. I got around this issue by trying to create a URL object from the string I get before trying to open it:

try {
  new URL(url);
} catch (e) {
  console.warn('Malformed URL', url);
  return;
}

The same error occurs occasionally, when the page I load has a well formed URL, but one of the assets it tries to load doesn't. This crashes the running function, even though all of my code is wrapped in a try-catch block, or uses await-to-js to catch rejected promises.

Add any other details about the problem here.

This is the error log I get when trying to open a malformed URL.

(node:23419) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_URL]: Invalid URL: https://www.youtube%20panel%20title.com/
    at onParseError (internal/url.js:257:9)
    at new URL (internal/url.js:333:5)
    at stripFragmentFromUrl (/services/browser/node_modules/playwright-chromium/lib/server/network.js:63:20)
    at new Request (/services/browser/node_modules/playwright-chromium/lib/server/network.js:83:21)
    at new InterceptableRequest (/services/browser/node_modules/playwright-chromium/lib/server/chromium/crNetworkManager.js:364:24)
    at CRNetworkManager._onRequest (/services/browser/node_modules/playwright-chromium/lib/server/chromium/crNetworkManager.js:235:25)
    at CRNetworkManager._onRequestWillBeSent (/services/browser/node_modules/playwright-chromium/lib/server/chromium/crNetworkManager.js:114:18)
    at CRSession.emit (events.js:315:20)
    at CRSession.EventEmitter.emit (domain.js:485:12)
    at /services/browser/node_modules/playwright-chromium/lib/server/chromium/crConnection.js:155:22
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

Successfully merging a pull request may close this issue.

1 participant