-
Notifications
You must be signed in to change notification settings - Fork 55
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
Need API for downloading a file #302
Comments
@studylamp thanks for opening the issue. When you say access the browser cookies, do you mean webview app access the browser (Edge) cookies, or just access webview cookies? The reason I'm asking is we made a conscious decision to separate browser and webview data for obvious security reason of not letting apps steal user data/credentials they entered in the browser. If we are talking about this in the context of webview, we can consider a http request API from webview, but I also want to discuss a couple alternatives and see whether they works for you.
Btw, how are you detecting non-viewable content? Do you as the developer also own the web content, or you're detecting things through webResourceRequested? |
I mean the WebView2 control's cookies from the current session as it exists inside of my application. Same issue as #4 .
This would be very very helpful.
Well, sometimes we need this for even viewable content (example: download a plain text file to be processed in our application, not shown in the web view), but if the mime type is "attachment" I want to be able to control the download process rather than shove the bits into the user's downloads folder. We know the URL before-hand and just want to be able to grab it through http using the cookies/etc after the user has already logged in. A simple API for http request allowing me to direct the content to a memory stream or file of my choice would be a good solution. In this particular case, a handler for begin/end download would even be enough. My current workaround is to just use a web resource filter and keep track of the current cookies being sent in the requests, and then form a simple http request using them, but outside of the webview. |
Thanks for the details. Sounds like you're on a working but painful workaround. We will track this as a feature request on our backlog. |
You can use XMLHTTPRequest for this e.g:
|
A good suggestion and it is fine for one of our use cases. However, we also need to be able to download very large video files after a purchase in the web view. Managing that in javascript and hoping it is not interrupted by new navigation in the web view is not ideal. An async http get API would be a robust solution and is supported by other browser controls I have worked with, so hopefully this feature request will be implemented. |
Ah yes, I see. If MS don't implement anything, I will be adding it to this control: https://github.com/ukandrewc/Webview2.Winforms.DOM |
Updated the control to get cookies and translate them into .Net CookieCollection
|
After some internal consideration, we are not planning on working on an http request method in the near future. HTTP requests are generally not considered in scope for WebView. Developer can either use XHR or native HTTP method + use cookies from webview to authenticate the native http libraries. We can still discuss this with additional input. Feel free to add comment or ask for re-opening in the future. |
I am here as I missed this feature while looking at WebView2. I have used CEFSharp and a .NET HTTPClient to download files. I am not an expert but it took me a while to work out the Headers needed especially cookies needed. I got it working eventually. Then the website I was targeting changed cookies and headers. The HTTPClient now does not work. CefSharp exposes which means CEF exposes a download feature which uses the credentials of the current user logged in. Chrome/Edge Extensions also expose the ability to download something as well. Objectively you could say that a number of different developers think it is a good feature. All of the above would also have the ability to use XHR and native HTTP (extensions could send the cookies to a native host which could then use HTTP). Correct me if I am wrong but you are using CEF so the feature is there to be used, they thought it important enough to expose it, you simply choose not to hook it up? |
As far as I can tell, there is no way to download the contents of a URL to a file or memory stream using the browser's current session/cookies/etc.
Especially since we current cannot access the browser's cookies #4 , we need to be able to download non-viewable content or attachments into our own temporary file location and provide a viewer outside of the browser. When the content is behind cookies or other authorization, we have no way to do this through the standard Windows http apis.
Ideally, we would have an API for requesting the contents of a URL, which the browser would handle by responding with cookies, handling authorization, and redirects -- with a callback for the data as it is received, or at least something notifying when the download is complete.
AB#28992572
The text was updated successfully, but these errors were encountered: