chrome.dns

Description

Use the chrome.dns API for dns resolution.

Permissions

dns

Availability

Dev channel

Manifest

To use this API, you must declare the "dns" permission in the manifest.

{
  "name": "My extension",
  ...
  "permissions": [
    "dns"
  ],
  ...
}

Usage

The following code calls resolve() to retrieve the IP address of example.com.

service-worker.js:

const resolveDNS = async () => {
    let record = await chrome.dns.resolve('example.com');
    console.log(record.address); // "192.0.2.172"
};

resolveDNS();

Types

ResolveCallbackResolveInfo

Properties

  • address

    string optional

    A string representing the IP address literal. Supplied only if resultCode indicates success.

  • resultCode

    number

    The result code. Zero indicates success.

Methods

resolve()

Promise
chrome.dns.resolve(
  hostname: string,
  callback?: function,
)

Resolves the given hostname or IP address literal.

Parameters

Returns

  • Promises are only supported for Manifest V3 and later, other platforms need to use callbacks.