如何在 Firefox 中设置 browser.helperApps.neverAsk.saveToDisk 以避免使用 Selenium 导出 Protonmail 电子邮件时弹出下载
Posted
技术标签:
【中文标题】如何在 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 【发布时间】:2022-01-14 18:01:45 【问题描述】:我正在尝试在使用 Selenium C# 实现导出质子邮件时自动下载 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://");
【问题讨论】:
【参考方案1】:最后在这种情况下要走的路是设置
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;
【讨论】:
以上是关于如何在 Firefox 中设置 browser.helperApps.neverAsk.saveToDisk 以避免使用 Selenium 导出 Protonmail 电子邮件时弹出下载的主要内容,如果未能解决你的问题,请参考以下文章
Python Selenium在ubuntu中设置firefox配置文件的路径