Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
An unofficial Tauri plugin that enables seamless cross-origin resource sharing (CORS) for web fetch requests within Tauri applications.
Platform | Supported |
---|---|
Linux | ✓ |
Windows | ✓ |
macOS | ✓ |
Android | ✓ |
iOS | ✓ |
Overview
When building cross-platform desktop applications with Tauri, we often need to access services like OpenAI that are restricted by Cross-Origin Resource Sharing (CORS) policies in web environments.
However, on the desktop, we can bypass CORS and access these services directly. While the official tauri-plugin-http can bypass CORS, it requires modifying your network requests and might not be compatible with third-party dependencies that rely on the standard fetch
API.
How it Works
This plugin extends the official tauri-plugin-http by hooking into the browser's native fetch
method during webpage initialization. It transparently redirects requests to the tauri-plugin-http, allowing you to use the standard fetch
API without additional code changes or workarounds.
Installation
- Add the plugin to your Tauri project's dependencies:
# src-tauri
cargo add tauri-plugin-cors-fetch
- Initialize the plugin in your Tauri application setup:
// src-tauri/src/lib.rs
- Add permissions in your
capabilities
configuration:
// src-tauri/capabilities/default.json
- Enable
withGlobalTauri
in your Tauri configuration:
// src-tauri/tauri.conf.json
Usage
Once installed, the plugin automatically hooks into the browser's fetch
API. You can use fetch
normally without any code changes:
// Standard fetch - now works with CORS
.
.;
Configuration (Optional)
Configure which requests should bypass CORS:
window.;
Alternative Methods
// Direct CORS-enabled fetch
window.;
// Original native fetch (with CORS restrictions)
window.;
Limitations
- Streaming: Server-Sent Events (SSE) and streaming responses are not supported. See implementation details.
- XHR: Only supports the modern
fetch
API, notXMLHttpRequest
.
License
MIT License © 2024-PRESENT Del Wang