publicSuffix.getKnownSuffix()

Returns the known public suffix (eTLD) of the hostname according to the Public Suffix List, or null if the hostname has no known public suffix.

When a hostname has multiple possible public suffixes, the longest matching entry is returned.

Syntax

js
let suffix = browser.publicSuffix.getKnownSuffix(hostname)

Parameters

hostname

string. The hostname whose public suffix is to be returned.

Return value

A string containing the public suffix of hostname, or null if no known public suffix exists for hostname.

Throws an error if hostname is not a valid hostname.

Examples

Get the public suffix of a hostname:

js
console.log(browser.publicSuffix.getKnownSuffix("example.com")); // "com"
console.log(browser.publicSuffix.getKnownSuffix("example.co.uk")); // "co.uk"
console.log(browser.publicSuffix.getKnownSuffix("user.github.io")); // "github.io"
console.log(browser.publicSuffix.getKnownSuffix("com")); // "com"
console.log(browser.publicSuffix.getKnownSuffix("localhost")); // null

Browser compatibility