EdgeWebDriver icon indicating copy to clipboard operation
EdgeWebDriver copied to clipboard

XML file downloads are blocked

Open RajeshPoola opened this issue 2 years ago • 2 comments

While using InPrivate mode, downloading XML files triggers a security pop-up showing the file download blocked message.

I used the following options but they didn't work. I didn't find any documentation regarding this.

var options = new EdgeOptions();
options.AddArgument("--safebrowsing-disable-download-protection");
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("savefile.default_directory", OutputFilePath);
![Screenshot 2024-01-05 110535](https://github.com/MicrosoftEdge/EdgeWebDriver/assets/82456213/e781eb22-fca9-47a7-a698-69afe8cfc033)

options.AddUserProfilePreference("savefile.prompt_for_download", false);

RajeshPoola avatar Jan 05 '24 16:01 RajeshPoola

Hi @RajeshPoola

I’m facing the exact same issue as you with XML files being blocked during download. I would love to know how you managed to solve this issue? Any tips or guidance would be greatly appreciated.

Thanks in advance for your response!

Ssloan18 avatar Jan 09 '25 16:01 Ssloan18

Hi @RajeshPoola

I’m facing the exact same issue as you with XML files being blocked during download. I would love to know how you managed to solve this issue? Any tips or guidance would be greatly appreciated.

Thanks in advance for your response!

@Ssloan18 If you have admin access on your machine you can try this. Call this method before setting up driver

private static void AllowEdgeToDownloadXmlFiles()
{
    // Define the registry path and value
    const string regPath = @"SOFTWARE\Policies\Microsoft\Edge";
    const string regName = "ExemptFileTypeDownloadWarnings";
    const string regValue = "[ { \"file_extension\": \"xml\", \"domains\": [\"azurefd.net\"] } ]";

    try
    {
        // Open or create the registry key
        using var key = Registry.LocalMachine.CreateSubKey(regPath);
        if (key != null)
        {
            // Set the registry value
            key.SetValue(regName, regValue, RegistryValueKind.String);
            Console.WriteLine("Registry key set successfully.");
        }
        else
        {
            throw new ApplicationException("Failed to create or open the registry key.");
        }
    }
    catch (UnauthorizedAccessException)
    {
        throw new ApplicationException(
            "Access to the registry key is denied. Please run the program as an administrator.");
    }
    catch (Exception ex)
    {
		throw new UnauthorizedAccessException("An error occurred: " + ex.Message);
    }
}

RajeshPoola avatar Jan 09 '25 16:01 RajeshPoola