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.

[Feature]: Make page.goto work with URL objects

See original GitHub issue

Context:

  • GOOD Playwright Version: 0.10.0
  • BAD Playwright Version: 0.11.0
  • Operating System: Mac OS X 10.14.6
  • Extra: node@11.15.0 npm@6.7.0

Code Snippet

    const url = new URL(baseUrl)
    url.pathname =  "theusers/thepassword"
    url.searchParams.append("reset_thepassword_token", 1)

    // ERROR IN THIS PART
    const changePasswordPage = page.goto(url) // alternative: url.href
    // ERROR IN THIS PART

    await Promise.all([
      // ...etc,
      changePasswordPage
    ])

Describe the bug feature I have a piece of code where I construct a URL object and pass that to the page.goto function.

I just noticed that the url in page.goto is typehinted as string:

https://github.com/microsoft/playwright/blob/39c580a9b14d67f9e597029cb7564c7ece59a359/src/frames.ts#L325

After the helper function for localhost was added, the page.goto(URL) now throws an error: TypeError: urlString.startsWith is not a function

https://github.com/microsoft/playwright/blob/39c580a9b14d67f9e597029cb7564c7ece59a359/src/helper.ts#L216

I understand the alternative is to simply access the URL.href property, my question is:

  • Would it be a good idea to support passing a URL object instead of just a string?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
aslushnikovcommented, Mar 6, 2020

Would it be a good idea to support passing a URL object instead of just a string?

@aesyondu Nah, let’s keep it simple. Strings work good for us so far.

  1. What is the scope? I noticed that in many places, the API currently expects url: string. Is the issue specific for Page and Frames? This might have some impact of the versioning.

@ddayguerrero Hi! I closed your PR regarding this - sorry for confusion. In general, we don’t think this whole change worth the hassle - it doesn’t really bother that much our clients.

  1. Do we have more details on Playwright’s contribution guidelines?

This is a good one - filed https://github.com/microsoft/playwright/issues/1257 to address this.

0reactions
sadik13commented, Jun 28, 2021

HI, As per my requirement, I wanna access the below code instead of the full URL I wanna set the hostname into env variables outside of the tes.journey.js file and access it into my playwright code.

await page.goto(‘http://www.google.com’);

I need like this below way: const URL =“env path address of HOST”; await page.goto(url);

so, plz suggested ur ideas of code for this.

Thanks in advance!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use URL Objects (URL Interface) - JavaScript Tutorial
URL objects are especially useful when combining them with the Fetch API in order to make HTTP requests. Support me on Patreon: ...
Read more >
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 >
Creating a URL - The Java™ Tutorials
The easiest way to create a URL object is from a String that represents the human-readable form of the URL address. This is...
Read more >
JavaScript: Go to URL: A Complete Guide - Career Karma
To navigate to a new URL, use the location object from the Browser's History API. The session history lets you reassign the location...
Read more >
How to get the browser to navigate to URL in JavaScript
If you want to simulate clicking on a link, use location.href If you want to simulate an HTTP redirect, use location.replace Note that...
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