Documentation / /
Web APIs

globalFetch API

experimental.globalFetch is an experimental API for making Ajax calls across origins.

This API is functionally identical to fetch() with the following caveats:

  • CORS is not applied, so the site can send a request to any service
  • A permission prompt is raised for each request to a new origin
  • Only HEAD and GET are supported
  • Cookies/credentials are never sent

For each new origin that the site contacts, a permission prompt will be presented to the user. This makes it possible for dat:// websites to make cross-origin requests, while the user still has an opportunity to block the requests.

To use this API, include the following in your dat.json manifest file:

{
  "experimental": {
    "apis": ["globalFetch"]
  }
}

Methods

experimental.globalFetch(input, init?)

This API is functionally similar to fetch() and accepts the same parameters. Refer to the fetch() documentation for more information

Example:

var res = await experimental.globalFetch('https://example.com')
var body = await res.text()