Browser fetch in a webview
Code using the webview’s standard fetch follows browser origin rules. CORSPROXY can supply CORS response headers when the permitted upstream response does not allow your origin. Test your app’s actual origin and supported request policy.
Native HTTP with Tauri’s plugin
For a native-only application, use Tauri’s HTTP plugin when you want the request handled by the native runtime. Install the plugin and configure its allowed URLs in your app’s capabilities. Browser CORS is not the access-control mechanism for that native request.
import { fetch as nativeFetch } from '@tauri-apps/plugin-http';
// Install the plugin and allow this URL in your Tauri capabilities first.
const response = await nativeFetch('https://api.example.com/public/data');
if (!response.ok) throw new Error('HTTP ' + response.status);
console.log(await response.json()); A shared desktop and browser build
A browser build cannot use the native plugin. If both builds use CORSPROXY, configure and test their actual request origins separately. Keep private provider credentials outside webview code, and use Production for server-side proxy calls.
