chrome.dns

說明

使用 chrome.dns API 進行 DNS 解析。

權限

dns

可用性

開發人員頻道

資訊清單

如要使用這項 API,您必須在資訊清單中宣告 "dns" 權限。

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

用量

下列程式碼會呼叫 resolve(),擷取 example.com 的 IP 位址。

service-worker.js:

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

resolveDNS();

類型

ResolveCallbackResolveInfo

屬性

  • 地址

    字串 選填

    代表 IP 位址常值的字串。只有在 resultCode 指出成功時才會提供。

  • resultCode

    數字

    結果代碼。零表示成功。

方法

resolve()

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

解析指定的主機名稱或 IP 位址常值。

參數

傳回