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

url.startsWith is not a function. #1664

Closed
Erwin-Goossen opened this issue Jan 6, 2025 · 1 comment · Fixed by #1672
Closed

url.startsWith is not a function. #1664

Erwin-Goossen opened this issue Jan 6, 2025 · 1 comment · Fixed by #1672
Assignees
Labels
bug Something isn't working

Comments

@Erwin-Goossen
Copy link

Describe the bug
Happy-dom throws the next error:
TypeError: url.startsWith is not a function. (In 'url.startsWith("about:")', 'url.startsWith' is undefined)

To Reproduce
Steps to reproduce the behavior:
Not sure tbh. But did some debugging and partly found the cause of this.

This is the part where it fails in BrowserFrameURL:

static getRelativeURL(frame, url) {
    url = (url instanceof URL ? url.toString() : url) || 'about:blank';
    if (url.startsWith('about:') || url.startsWith('javascript:')) {

The problem is that url is not an instance of URL, but still an object, alyhough the string value is about:blank. Because of not being an instance of URL, but still being an object the .startsWith fails.

replacing the url assignment with url = (url instanceof URL || typeof url === 'object' ? url.toString() : url) || 'about:blank'; fixes the error/issue

Expected behavior
Happy-dom not to throw an error on a 'wrong' url

Screenshots
If applicable, add screenshots to help explain your problem.

Device:

  • OS: macOS 14.6.1 (23G93)
  • Browser Bun vv1.1.42
  • Version 16.2.7

Additional context
Add any other context about the problem here.

TypeError: url.startsWith is not a function. (In 'url.startsWith("about:")', 'url.startsWith' is undefined)
      at getRelativeURL (<path-to-project></>/node_modules/happy-dom/lib/browser/utilities/BrowserFrameURL.js:16:17)
      at <path-to-project></>/node_modules/happy-dom/lib/browser/utilities/BrowserFrameNavigator.js:63:20
      at navigate (<path-to-project></>/node_modules/happy-dom/lib/browser/utilities/BrowserFrameNavigator.js:57:44)
      at href (<path-to-project></>/node_modules/happy-dom/lib/location/Location.js:210:13)
      at location (<path-to-project></>/node_modules/happy-dom/lib/window/BrowserWindow.js:904:31)
      at <path-to-project></>/src/components/Popup/Popup.spec.tsx:40:6```
@capricorn86
Copy link
Owner

Thank you for reporting @Erwin-Goossen! 🙂

Support for this should now be added in v16.4.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants