Skip to main content

An XMLHttpRequest (XHR) polyfill for Deno CLI and Deploy

Works with
This package works with Deno
JSR Score
2 months ago

Provides a polyfill for Deno CLI and Deploy for XMLHttpRequest (XHR).

When loaded, it will inject XMLHttpRequest into the global namespace along with a couple other key objects.

While the module exports XMLHttpRequest, most use cases it should just be imported before any other dependencies that require XHR to be present:

import "jsr:/@kitsonk/xhr";
import * as lib from "https://other/dependency/that/needs/xhr/lib.js";

This polyfill has several known/intentional limitations from a browser standard XMLHttpRequest:

  • It does not handle XML, though the name implies it, nor does it handle HTML being treated as a response type "document". This uses the browser's built in parser to parse the XML and HTML into a DOM object.
  • Sync is not supported (passing false to the async argument). Most browsers have deprecated it in the main thread. Since this polyfill works by calling Deno's fetch() it is nearly impossible to generate a sync version, plus it is a really bad idea to block a thread while waiting for a server response. Don't do it, don't use software that requires it.
Built and signed on
GitHub Actions
View transparency log

Add Package

deno add @kitsonk/xhr

Import symbol

import * as mod from "@kitsonk/xhr";