puppeteer/docs/api/puppeteer.page.goto.md
Ophir Back e3d69ec554
feat(page): Adding support for referrerPolicy in page.goto (#9561)
Issue: #9394

**What kind of change does this PR introduce?**

Feature - Added support of the `referrerPolicy` parameter (from CDP's
`Page.navigate`) to Puppeteer's `page.goto`.

**Did you add tests for your changes?**

No, currently it has no meaning that isn't browser implementation based,
which might get broken in the future. If there are suggestions to tests,
please let me know so I'll add them.

**If relevant, did you update the documentation?**
Yes, the documentation of the `goto` method has been updated.

**Summary**
I wanted to contribute to this project, which I used for testing on our
environment and saw issue #9394, so I decided to resolve it :)

**Does this PR introduce a breaking change?**
No. I added the `referrerPolicy` as an optional parameter, which will
use the HTTP header `Referrer-Policy` if not provided (much like the
`referer` parameter) so it will not interfere.

Co-authored-by: Ophir Back <ophir.back@broadcom.com>
2023-01-23 11:11:20 +00:00

3.6 KiB

sidebar_label
Page.goto

Page.goto() method

Signature:

class Page {
  goto(
    url: string,
    options?: WaitForOptions & {
      referer?: string;
      referrerPolicy?: string;
    }
  ): Promise<HTTPResponse | null>;
}

Parameters

Parameter Type Description
url string URL to navigate page to. The URL should include scheme, e.g. https://
options WaitForOptions & { referer?: string; referrerPolicy?: string; } (Optional) Navigation Parameter

Returns:

Promise<HTTPResponse | null>

Promise which resolves to the main resource response. In case of multiple redirects, the navigation will resolve with the response of the last redirect.

Remarks

The argument options might have the following properties:

  • timeout : Maximum navigation time in milliseconds, defaults to 30 seconds, pass 0 to disable timeout. The default value can be changed by using the Page.setDefaultNavigationTimeout() or Page.setDefaultTimeout() methods.

  • waitUntil:When to consider navigation succeeded, defaults to load. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
    - load : consider navigation to be finished when the load event is fired.
    - domcontentloaded : consider navigation to be finished when the DOMContentLoaded event is fired.
    - networkidle0 : consider navigation to be finished when there are no more than 0 network connections for at least 500 ms.
    - networkidle2 : consider navigation to be finished when there are no more than 2 network connections for at least 500 ms.

  • referer : Referer header value. If provided it will take preference over the referer header value set by page.setExtraHTTPHeaders().
    - referrerPolicy : ReferrerPolicy. If provided it will take preference over the referer-policy header value set by page.setExtraHTTPHeaders().

page.goto will throw an error if:

  • there's an SSL error (e.g. in case of self-signed certificates). - target URL is invalid. - the timeout is exceeded during navigation. - the remote server does not respond or is unreachable. - the main resource failed to load.

page.goto will not throw an error when any valid HTTP status code is returned by the remote server, including 404 "Not Found" and 500 "Internal Server Error". The status code for such responses can be retrieved by calling response.status().

NOTE: page.goto either throws an error or returns a main resource response. The only exceptions are navigation to about:blank or navigation to the same URL with a different hash, which would succeed and return null.

NOTE: Headless mode doesn't support navigation to a PDF document. See the upstream issue.

Shortcut for page.mainFrame().goto(url, options).