Skip to content
AnswerWell geo Documentation

Research · 5 min read · Answerwell

Public Suffix API, DNS Resolve, and Domain Encoding Options

How registrable-domain options, hostname DNS resolve, and Punycode encoding work in browser extensions and Workers.

This page summarises Chrome extension documentation on hostnames and registrable domains, together with a small related note from Cloudflare Workers Node.js url for Punycode conversion. Most everyday extension work that touches cookies, site boundaries, or security decisions needs a registrable domain (sometimes called eTLD+1), not a raw hostname string; the Public Suffix API and DNS API are the supported ways to obtain that in an extension, while DomainOptions controls edge cases and display encoding.

Public Suffix API: registrable domain from a hostname

Section titled “Public Suffix API: registrable domain from a hostname”

The Public Suffix API (browser.publicSuffix in Manifest V3, chrome.publicSuffix in Manifest V2) uses the Public Suffix List to separate a hostname’s registrable domain from its public suffix (for example co.uk). Your extension must declare the publicSuffix permission before calling these methods.

getDomain(): what is the registrable domain?

Section titled “getDomain(): what is the registrable domain?”

getDomain() returns the registrable domain for a hostname, if one exists:

Gets the registrable domain for hostname, if any.

— Chrome, browser.publicSuffix

Signature (MV3):

browser.publicSuffix.getDomain(hostname: string, options?: DomainOptions): string | undefined

The MV2 surface is the same pattern on chrome.publicSuffix (chrome.publicSuffix). Use this when you need one stable label for “which site” (permissions scoped by site, UI grouping, or comparing two URLs) instead of parsing strings yourself.

For suffix checks without computing the full registrable domain:

Gets the known public suffix for hostname, if any.

— Chrome, browser.publicSuffix

Determines whether hostname is itself a known public suffix.

— Chrome, browser.publicSuffix

getKnownSuffix(hostname) helps when you only need the list-known suffix (for example com or co.uk). isKnownSuffix(hostname) tells you whether the input is itself a known public suffix, which is useful when validating user-entered hostnames or normalising configuration.

DomainOptions: IP addresses, suffix rules, and encoding

Section titled “DomainOptions: IP addresses, suffix rules, and encoding”

Optional second argument options on getDomain() is a DomainOptions object. The same fields appear on the MV2 and MV3 reference pages.

Property Default Effect
allowIPAddress false When true, IP address literals may be returned as domains without Public Suffix List lookup.
allowPlainSuffix false When true, known public suffixes may be returned as domains.
allowUnknownSuffix false When true, unknown TLDs are treated as a public suffix (for example internal names like printer.internal-network).
encoding "punycode" Serialization of the returned domain; use "display" when showing the domain in UI.

Chrome documents the encoding choice as follows:

Defaults to “punycode”, but pass “display” if displaying the domain to the user. Generally, “display” will use Unicode, except in cases where that would be unsafe due to “Unicode confusables”.

— Chrome, browser.publicSuffix

For allowIPAddress:

Whether IP addresses may be returned as domains. Defaults to false. Note: When allowed, IP addresses are returned without being looked up in the Public Suffix List.

— Chrome, browser.publicSuffix

DNS API resolve(): hostname to resolved records

Section titled “DNS API resolve(): hostname to resolved records”

When you need resolver output rather than registrable-domain parsing, use the DNS API. In MV3:

Resolves the given hostname or IP address literal.

— Chrome, browser.dns

browser.dns.resolve(hostname: string): Promise<ResolveCallbackResolveInfo>

The hostname parameter is documented as “The hostname to resolve.” (browser.dns). MV2 exposes the same behaviour on chrome.dns.resolve, with an optional callback (chrome.dns).

Public Suffix vs DNS resolve: getDomain() answers “what site label should I use for policy/UI?” resolve() answers “what does the platform resolver return for this name?” They complement each other: resolve for connectivity or record inspection; public suffix for cookie/site identity rules.

Domain encoding: Punycode and Unicode outside the extension APIs

Section titled “Domain encoding: Punycode and Unicode outside the extension APIs”

DomainOptions.encoding controls how getDomain() returns a string. For normalising or converting domain labels in Cloudflare Workers (Node.js-compatible url module), use domainToASCII and domainToUnicode:

Returns the Punycode ASCII serialization of the domain. If domain is an invalid domain, the empty string is returned.

— Cloudflare, Node.js url in Workers

Returns the Unicode serialization of the domain. If domain is an invalid domain, the empty string is returned. It performs the inverse operation to domainToASCII().

— Cloudflare, Node.js url in Workers

Example from the same document:

import { domainToASCII, domainToUnicode } from "node:url";
console.log(domainToASCII("español.com")); // xn--espaol-zwa.com
console.log(domainToUnicode("xn--espaol-zwa.com")); // español.com

Invalid input yields an empty string for both functions (Node.js url in Workers). In an extension, prefer encoding: "display" on getDomain() when showing domains to users; in a Worker, prefer domainToUnicode / domainToASCII for stored or wire-format labels.

Manifest V2 chrome.* vs Manifest V3 browser.*

Section titled “Manifest V2 chrome.* vs Manifest V3 browser.*”
Concern MV3 MV2
Public suffix methods browser.publicSuffix chrome.publicSuffix
DNS resolve browser.dns chrome.dns
Permission publicSuffix publicSuffix

DomainOptions and method behaviour described on the MV3 page match the MV2 reference for the fragments in this cluster.

  • Calling getDomain() without the publicSuffix permission, or assuming it always returns a string (it may return undefined).
  • Using the registrable domain from default options for internal-only hostnames without setting allowUnknownSuffix when that behaviour is intended (browser.publicSuffix).
  • Showing punycode labels in UI while encoding stays at default "punycode" instead of "display".
  • Treating dns.resolve() results as equivalent to registrable-domain identity for cookies or storage partitioning.
  • Mixing MV2 chrome.* and MV3 browser.* namespaces in one codebase without a compatibility layer.
  1. In your extension manifest, confirm the publicSuffix permission is declared, then load the unpacked build that calls browser.publicSuffix or chrome.publicSuffix.

  2. In the extension’s service worker or background context, call getDomain() on test hostnames (a normal site, a multi-part public suffix, and an internal name) and record whether results match your policy for default DomainOptions.

  3. Repeat with encoding: "display" and compare UI strings to punycode defaults for an internationalised domain name.

  4. If you use resolution, call browser.dns.resolve or chrome.dns.resolve on the same hostnames and confirm you are not conflating DNS answers with registrable-domain output.

  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are questioning so it can be corrected.