| Crates.io | tauri-plugin-cors-fetch |
| lib.rs | tauri-plugin-cors-fetch |
| version | 4.1.0 |
| created_at | 2024-03-23 16:31:06.822451+00 |
| updated_at | 2025-06-28 12:43:52.601574+00 |
| description | Enabling Cross-Origin Resource Sharing (CORS) for Fetch Requests within Tauri applications. |
| homepage | |
| repository | https://github.com/idootop/tauri-plugin-cors-fetch |
| max_upload_size | |
| id | 1183647 |
| size | 188,059 |

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 | ✓ |
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.
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.
# src-tauri
cargo add tauri-plugin-cors-fetch
// src-tauri/src/lib.rs
pub fn run() {
tauri::Builder::default()
.plugin(tauri_plugin_cors_fetch::init())
.run(tauri::generate_context!())
.expect("failed to run app");
}
capabilities configuration:// src-tauri/capabilities/default.json
{
"permissions": ["cors-fetch:default"]
}
withGlobalTauri in your Tauri configuration:// src-tauri/tauri.conf.json
{
"app": {
"withGlobalTauri": true
}
}
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
fetch("https://api.example.com/data")
.then((response) => response.json())
.then((data) => console.log(data));
Configure which requests should bypass CORS and set default request parameters:
window.CORSFetch.config({
include: [/^https?:\/\//i], // Process all HTTP requests (default)
exclude: ["https://api.openai.com/v1/chat/completions"], // Skip CORS bypass
// Default request parameters (applied to all CORS requests)
// see https://v2.tauri.app/reference/javascript/http/#clientoptions
request: {
maxRedirections: 5, // Default maximum redirections
connectTimeout: 30 * 1000, // Default connection timeout (ms)
proxy: {
all: "http://127.0.0.1:7890", // Default proxy for all requests
},
},
});
Configuration Options:
include: Array of URL patterns (strings or RegExp) that should use CORS bypass
exclude: Array of URL patterns that should NOT use CORS bypass
request: Default request parameters (applied to all CORS requests) object containing:
connectTimeout: Default connection timeout (ms)maxRedirections: Default maximum redirections to followproxy: Default proxy configuration for all requests (see Tauri HTTP proxy docs)These default request parameters will be used for all CORS requests unless overridden in individual fetch calls.
// Direct CORS-enabled fetch
window.fetchCORS("https://api.example.com/data");
// Original native fetch (with CORS restrictions)
window.fetchNative("https://api.example.com/data");
fetch API, not XMLHttpRequest.MIT License © 2024-PRESENT Del Wang