Welcome What's new in Chrome extensions API reference Samples
Welcome What's new in Chrome extensions API reference Samples

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"
],
...
}

This API is only available in Chrome Dev. There are no foreseeable plans to move this API from the dev channel into Chrome stable.

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();
Important

Do not include the scheme or trailing slash in the hostname. For example, https://example.com/ is invalid.

Summary

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

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

Resolves the given hostname or IP address literal.

Parameters

Returns

  • Promises are supported in Manifest V3 and later, but callbacks are provided for backward compatibility. You cannot use both on the same function call. The promise resolves with the same type that is passed to the callback.

This site uses cookies to deliver and enhance the quality of its services and to analyze traffic. If you agree, cookies are also used to serve advertising and to personalize the content and advertisements that you see. Learn more about our use of cookies.