From e4dc8bd6bc292865e5920a5a068518acdd5bf016 Mon Sep 17 00:00:00 2001 From: Andrei Date: Thu, 23 May 2024 17:41:44 +0200 Subject: [PATCH] updated: nodejs runtime detection --- dist/index.js | 8 ++++---- src/index.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/dist/index.js b/dist/index.js index 8343a03..49fc9df 100644 --- a/dist/index.js +++ b/dist/index.js @@ -24,12 +24,12 @@ const isDomain = (domain) => { }); }; function bestDnsResolverForThisRuntime() { - if (navigator?.userAgent === 'Cloudflare-Workers') { - return 'cloudflare-dns'; - } - else if (navigator?.userAgent.startsWith('Node.js/')) { + if (globalThis.process?.release?.name === 'node') { return 'node-dns'; } + else if (globalThis.navigator?.userAgent === 'Cloudflare-Workers') { + return 'cloudflare-dns'; + } else { return 'google-dns'; } diff --git a/src/index.ts b/src/index.ts index 3b93706..5779306 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,10 +42,10 @@ const isDomain = (domain: string): boolean => { } function bestDnsResolverForThisRuntime(): string { - if (navigator?.userAgent === 'Cloudflare-Workers') { - return 'cloudflare-dns' - } else if (navigator?.userAgent.startsWith('Node.js/')) { + if (globalThis.process?.release?.name === 'node') { return 'node-dns' + } else if (globalThis.navigator?.userAgent === 'Cloudflare-Workers') { + return 'cloudflare-dns' } else { return 'google-dns' }