question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URL constructor is missing 'base' option

See original GitHub issue

The URL constructor at https://github.com/capricorn86/happy-dom/blob/57a8d33d4b1ba3bdd4df0f7f8bc02e0d06bd8e9e/packages/happy-dom/src/location/URL.ts#L23 does not support the second form of the URL constructor which takes a base url:

new URL(url)
new URL(url, base)

Quick test:

# expected
> new URL('', 'https://example.com').pathname
'/'
# actual
> new URL('', 'https://example.com').pathname
''

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
hugo-dlbcommented, Oct 10, 2022

After a lot of debugging, I stumbled upon the same issue. In my case I was trying to replace jsdom by happydom for our tests but this is not possible because of this issue. MSW is relying on this constructor (and I’m sure many other libraries do): https://github.com/mswjs/interceptors/blob/main/src/utils/getUrlByRequestOptions.ts#L91

It would be awesome if happy-dom could add this. 😃

1reaction
capricorn86commented, Dec 7, 2022

We have now fixed this by using the native url module 🙂

You can read more about the release here: https://github.com/capricorn86/happy-dom/releases/tag/v7.8.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

URL() - Web APIs - MDN Web Docs - Mozilla
The URL() constructor returns a newly created URL object representing the URL defined by the parameters.
Read more >
URL parse vs constructor: path missing - Stack Overflow
So if anything the constructor seems to provide a better break down of the URL. I don't why, when I try to copy...
Read more >
URL (Java Platform SE 7 ) - Oracle Help Center
Creates a URL object from the String representation. This constructor is equivalent to a call to the two-argument constructor with a null first...
Read more >
URL | Node.js v19.3.0 Documentation
The URL constructor is accessible as a property on the global object. ... The url.format(URL[, options]) method allows for basic customization of the...
Read more >
MongoClient or how to connect in a new and better way
The main difference is that the constructor is missing the database name from Db. ... MongoClient supports the same options as the previous...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found