Welcome Guest Search | Active Topics | Sign In | Register

How to handle blob:http(s) Uri Options
Guido
Posted: Friday, June 6, 2025 8:43:07 AM
Rank: Newbie
Groups: Member

Joined: 4/2/2025
Posts: 4
Hi,

we have a web application that allows the user to download a .pdf file. By clicking on a button, it opens a new tab that points to a Uri like the following one:

blob:https://my.domain.com/e65d733f-de20-4867-b40d-f3ef5864b02f

The .pdf file is displayed in the new tab. This is how it works in Chrome.

In our Wpf application we cannot handle multiple tabs as we must use only one window. If we handle the NewWindow event and run Process.Start(e.TargetUrl), we receive a Windows message telling that there is no application that can open that link, and that's fine. So, if the e.TargetUrl starts with "blob:", we do nothing. What we expected at this point was that the download of the file started, firing events like BeforeDownload and DownloadCompleted, but nothing happens.

We have also tried in the NewWindow handler:
1. e.Accepted = true:
2. WebView.Download(e.TargetUrl);
3. WebView.Download(e.TargetUrl.Replace("blob:", ""));
4. Process.Start(e.TargetUrl.Replace("blob:", "")): this opens a Chrome session, but the recourse is protected so we receive a Not Found error.

Is there any way to handle "blob:" links to download a file?

Thank a lot in advance for your help.

Best regards,
Guido

eo_support
Posted: Friday, June 6, 2025 12:29:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,373
Hi,

Please use code like this in your NewWindow handler:

Code: C#
void WebView_NewWindow(object sender, NewWindowEventArgs e)
{
    webView.RunLater(() =>
    {
        webView.Download(e.TargetUrl, result_file);
    });
}


Here "webView" is the current WebView that triggers the NewWindow event. "result_file" is the full path where you want to save the file. The key points are:

1. You can NOT set e.Accepted to true. If you set e.Accepted to true, you must display e.WebView;
2. WebView.Download is the right method for this case. Internally WebView.Download creates a secondary WebView to perform the download and handles all download related events on that WebView. So you will not see any download related events in your code;
3. WebView.Download won't return until the download completes. This means you can NOT call it directly inside NewWindow event handler since that will block the browser engine from continuing onto other tasks (including the download task). As such you must use WebView.RunLater;

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!
Guido
Posted: Monday, June 9, 2025 5:34:09 AM
Rank: Newbie
Groups: Member

Joined: 4/2/2025
Posts: 4
Hi,

we have just tried following your suggestion and it works.

Thanks a lot!

Bests,
Guido
eo_support
Posted: Monday, June 9, 2025 11:55:57 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,373
Great. Thanks for confirming!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.