-
Notifications
You must be signed in to change notification settings - Fork 616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs]How the project supports CORS #26
Comments
In electron it looks like this:
|
We're about to push a few updates to master and cut a new release. As soon as that lands, I will update the wiki to go into gory details about the config. To answer your question in the meantime, we apply a CSP - but haven't added CORS for the mode that uses a server. We are using |
As discussed internally, it's planned to add the following items to the docs:
|
Hello! Thanks for the great project. I believe I have the same question as the original poster. In particular, is it possible to de-activate CORS checks in Tauri? |
Wow, this is an old issue. Anyway, to turn off the CSP in the webview, do this:
However, this really only limits what the webview can do. If you want to sidestep CORS restrictions, then you need to perform your request outside of the browser context. This article is a great read: https://blog.container-solutions.com/a-guide-to-solving-those-mystifying-cors-issues
So, if you wanted to sidestep CORS limitations placed on the browser, what you could try is to craft a request using our HTTP API and have the Rust side make the request, returning the results (after potentially filtering them???) to the webview. Please see: |
Hey why this thread is closed i think this is not completely resolved My node js backend server asked for origin to resolve cors I have added few of my development and production origin to pass cors and its working When its comes to tauri, tauri sends request to my nginx load balancer and origin logs like In windows origin is tauri://localhost When i allow the origin in my backend tauri://localhost Windows application is working fine But mac and linux is still not working |
This comment was marked as spam.
This comment was marked as spam.
@Laegel any support or answer or trick to bypass this issue |
Will there be a config option for this? or flag:
or config:
|
how to make origin request from electron like this so i can only allow request cors for this url to secure my servers access not everyone will be able to access |
No ( = highly unlikely)
Using the webview's native http functions it's realistically only possible on Windows: tauri-apps/tauri#4912. In Rust it should be easy tho. |
+1 As it stands, even a basic app which could be neatly encapsulated in one secure process, instead requires splitting into side carts and more moving parts. etc. Why not enable running whole JS app neatly encapsulated inside browser process, with access to APIs/CORS etc? |
+1 |
Is anyone able to provide an actual example that show-cases what exact problems you're facing? Preferably issues that can not be fixed with tauri's own http module (https://tauri.app/v1/api/js/http). Thank you. |
play video, i use hls.js there will be cross-domain problems. because I want to play videos from other sites the following start project command
|
@robothot I'm trying to do the exact same thing. I ended up implementing a custom loader for https://gist.github.com/nathanbabcock/59c0298bed74ac48f7f209e30cf53b00 |
I created a library called |
@ComfyFluffy what is the difference with @tauri-api/api/http |
@yenche123 The main thing it does is to override the default XHR implementatiion which is implemented by the webview with a custom XHR that uses @tauri-api/api/http to fetch the data. Actually I'm using an SDK which uses XHR internally. With this I do not need to make changes to the SDK and just make it work. |
@FabianLars here is a scenario where this is a big letdown. Download files to HTML:
This will be blocked by protocol mismatch: I cannot just use I thought of adding a symlink as mentioned on discord - eg |
A solid case for me: I'm running most of my responses from a custom protocol, e.g. I'm hitting CORS issues there because I can't instruct |
I have tried to get around this by switching to the |
Ok, I worked around it by making these asset/resource requests go through my custom protocol, but wiring it up to take a different path when the URI matches a certain pattern that I can control: if req.uri().starts_with("myproto://localhost/_assets") {
let path = req.uri().split_once("myproto://localhost/_assets")
.map_or("", |(_, after)| after);
let resource_path = app.path_resolver()
.resolve_resource(format!("{}{}", "../src/public", path))
.expect("failed to resolve resource");
let mime_type = mime_guess::from_path(&resource_path)
.first_or_octet_stream();
let body = fs::read_to_string(resource_path)
.map_err(|e| e.to_string())
.unwrap()
.as_bytes()
.to_vec();
return ResponseBuilder::new()
.mimetype(mime_type.essence_str())
.body(body);
} The problem with this approach is the fact that I now have to maintain that code... it would be much nicer if this was handled internally to Tauri and return the appropriate HTTP response for the requested resource. But that implies some ability to control the CORS headers 🤷🏻♂️ |
If you don't care about safety. You can set the webview2 startup parameter --disable-web-security
Reference: https://tauri.app/v1/api/config#windowconfig.additionalbrowserargs |
@RSDoty I don't seem to be able to use your plan.
|
If anyone is facing CORS issues related to media playback, i.e HLS, DASH with DRM support etc. You can use shaka-player with this custom network plugin: https://gist.github.com/MirazMac/52ee5da091c274d82286b26a094000e5 I used dynamic import to import I modified it based on the original fetch plugin that shaka-player uses. Using this is very simple. import shaka from "shaka-player";
import { TauriFetchLoader } from "./TauriFetchLoader.js";
// Register the custom fetch plugin with Shaka
shaka.net.NetworkingEngine.registerScheme(
"http",
TauriFetchLoader.parse,
shaka.net.NetworkingEngine.PluginPriority.PREFERRED,
true,
);
shaka.net.NetworkingEngine.registerScheme(
"https",
TauriFetchLoader.parse,
shaka.net.NetworkingEngine.PluginPriority.PREFERRED,
true,
);
shaka.net.NetworkingEngine.registerScheme(
"blob",
TauriFetchLoader.parse,
shaka.net.NetworkingEngine.PluginPriority.PREFERRED,
true,
); Then you can use shaka-player normally. This will bypass CORS and also allow you to use forbidden headers. Example: const player = new shaka.Player(document.getElementById('video'));
const networkingEngine = player.getNetworkingEngine();
networkingEngine.registerRequestFilter((type, request) => {
request.headers["Cookie"] = "Value";
}); Sorry about hijacking the thread but this has bothered me for so long and I hope this helps someone in the future. |
As the title
And https://github.com/tauri-apps/tauri/blob/7e2854007a/cli/tauri.js/src/template/defaultConfig.ts whether his config description can be added to Wiki
The text was updated successfully, but these errors were encountered: