如何在 firefox 中设置 browser.helperApps.neverAsk.saveToDisk 以避免在使用 Selenium 导出 Protonmail 电子邮件时出现下载弹出窗口

How to set browser.helperApps.neverAsk.saveToDisk in firefox to avoid download popup when exporting Protonmail emails using Selenium

我正在尝试在使用 Selenium C# 实现导出 protonmail 邮件时自动下载 eml 文件。根据 MimeMapping.GetMimeMapping,MIME 类型是 message/rfc822。然而,尽管设置了以下首选项,下载文件的弹出窗口仍然出现。 关于在这种特殊情况下如何避免弹出窗口的任何想法?

opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "message/rfc822");
FirefoxOptions opcion = new FirefoxOptions();
opcion.SetPreference("browser.download.folderList", 2);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.dir", ruta);
opcion.SetPreference("browser.download.useDownloadDir", true);
opcion.SetPreference("browser.download.viewableInternally.enabledTypes", "");
opcion.SetPreference("browser.helperApps.alwaysAsk.force", false);
opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "Unknown/Extension missing, text/javascript, application/x-javascript,application/javascript, multipart/x-gzip, application/x-gzip, application/x-gzip, text/css, text/plain, application/x-binary, message/partial, multipart/form-data, multipart/byteranges,RFC-822 data,text/plain,application/pdf,application/eml,gzip,application/javascript,gzip,image/gif,application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/Zip, application/x-Zip, application/x-Zip-compressed, application/download, application/octet-stream,application/protonmail.ch, application/protonmail.com,image/pjpeg,application/vnd.semf,application/vnd.semd,application/vnd.sema,message/rfc822,multipart/x-gzip,multipart/eml,application/x-gzip,application/octet-stream,Thunderbird Document,wget url\sample.eml,application/xml,text/plain,text/xml,image/jpeg,text/eml,test/sample/message.eml,application/blob,text/plain,multipart/mixed,application/pdf,text/plain,application/text,text/xml,application/xml,application/json,application/eml,blob://");

最后在这种情况下要走的路是设置

opcion.SetPreference("browser.download.improvements_to_download_panel", true);

最终代码为:

FirefoxOptions opcion = new FirefoxOptions();
opcion.SetPreference("browser.download.folderList", 2);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.dir", ruta);
opcion.SetPreference("browser.download.improvements_to_download_panel", true);
opcion.SetPreference("browser.download.manager.showWhenStarting", false);
opcion.SetPreference("browser.download.useDownloadDir", true);
opcion.SetPreference("browser.download.viewableInternally.enabledTypes", "");
opcion.SetPreference("browser.helperApps.alwaysAsk.force", false);
opcion.SetPreference("browser.helperApps.neverAsk.saveToDisk", "Thunderbird Document, blob: ,application/vnd.protonmail.v1+json, application/json, json, media-src,blob,message, message/rfc6532,message/partial, message/external-body, message/rfc822, application/octet-stream, text/plain, application/download, application/octet-stream, binary/octet-stream, application/binary, application/x-unknown, texto/html");
opcion.SetPreference("pdfjs.disabled", true);
return opcion;