Skip to content

Urls

Namespace: E2E.Internal

public static class Urls

URL normalization and origin policy helpers.

Inheritance: object

View source

public static string BaseUrlOf(string href)

The base URL as a test reads it (upstream’s baseUrlOf): <code class=“paramref”>href</code> without its trailing slash, so $"{BaseUrl}/path" joins with one slash.

Parameters

Name Type Description
href string

Returns: string

public static bool IsImplicitTestHost(string hostname)

True when environment may default to test (loopback, .localhost, and .test hosts).

Parameters

Name Type Description
hostname string

Returns: bool

public static bool IsLoopbackHost(string hostname)

True for loopback hosts where plain HTTP is allowed.

Parameters

Name Type Description
hostname string

Returns: bool

public static bool IsRefusedLinkScheme(string protocol)

Whether a link’s scheme (with its colon, as Uri.Scheme + ":") is one no app link may take, in any case. A device link is any app’s custom scheme, so links are checked against this list rather than the http(s) rule navigation follows. Upstream’s isRefusedLinkScheme.

Parameters

Name Type Description
protocol string

Returns: bool

public static string PrintableUrl(string url)

<code class=“paramref”>url</code> without userinfo, query, or fragment, any of which may carry a credential: safe to print (upstream’s printableUrl).

Parameters

Name Type Description
url string

Returns: string

public static bool SameSite(string url, string site)

True when a URL’s host is on <code class=“paramref”>site</code> as SiteOf(string) reads it (upstream’s sameSite): the rule for which child frames an observation reads. An unparseable URL is off every site.

Parameters

Name Type Description
url string
site string

Returns: bool

public static string SiteOf(string hostname)

The registrable-domain approximation (upstream’s siteOf): the last two labels of a host, or the last three when the last is a two-letter country code and the one before it a short second-level label (example.co.uk, shop.com.au). An IP literal or a single-label host such as localhost is a site of its own. Where the approximation errs it errs narrow, except on shared hosting suffixes such as vercel.app, which it reads as one site.

Parameters

Name Type Description
hostname string

Returns: string

public static bool UrlMatches(string current, string expected, string baseHref, bool? ignoreCase = null)

True when <code class=“paramref”>current</code> matches <code class=“paramref”>expected</code> (upstream’s urlMatches): a string resolves against <code class=“paramref”>baseHref</code> and compares exactly after serialization, folding case when <code class=“paramref”>ignoreCase</code> is true.

Parameters

Name Type Description
current string
expected string
baseHref string
ignoreCase bool?

Returns: bool

public static bool UrlMatches(string current, Regex expected, bool? ignoreCase = null)

True when <code class=“paramref”>current</code> matches <code class=“paramref”>expected</code>: a regular expression tests the whole serialized URL, with <code class=“paramref”>ignoreCase</code> as Playwright’s (true adds the i flag, false removes it).

Parameters

Name Type Description
current string
expected Regex
ignoreCase bool?

Returns: bool