-
Notifications
You must be signed in to change notification settings - Fork 7
RequestContext.SetPreference
Mohammed Osama Mohamed Sayed Ahmed edited this page May 21, 2019
·
2 revisions
string error;
string errorMessage;
string errorNew;
Cef.UIThreadTaskFactory.StartNew(delegate
{
ChromiumWebBrowser.RequestContext.SetPreference("spellcheck.dictionaries", new
List<object> { "en-US", "ru", "ar", "zh-CN", "ja" }, out error);
ChromiumWebBrowser.RequestContext.SetPreference("spellcheck.dictionary", "en-US", out error);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.plugins_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("spellcheck.use_spelling_service", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.enable_spellchecking", true, out errorMessage);
/// pref_names.cc
///
///
///
///
/// pref_names.cc
/// https://github.com/adobe/chromium/blob/master/chrome/common/pref_names.cc
ChromiumWebBrowser.RequestContext.SetPreference("translate.enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.password_manager_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.password_manager_allow_show_passwords", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("profile.notifications_default_content_setting", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.desktop_notification_position", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.default_content_settings", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.content_settings.plugin_whitelist", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.content_settings.whitelist_version", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.shortcut_created", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("geolocation.default_content_setting", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("geolocation.content_settings", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("import_bookmarks", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("webstore.enterprise_store_url", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("webstore.enterprise_store_name", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("profile.local_profile_id", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("profile.last_active_profiles", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("content_settings_window.last_tab_index", true, out errorExtension);
ChromiumWebBrowser.RequestContext.SetPreference("task_manager.window_placement", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("preferences.window_placement", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("download.extensions_to_open", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.window_placement", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.browseractions.container.width", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.install.allowlist", true, out errorMessage);
// Time of the last, and next scheduled, extensions auto-update checks.
ChromiumWebBrowser.RequestContext.SetPreference("extensions.autoupdate.last_check", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.autoupdate.next_check", true, out error);
//
ChromiumWebBrowser.RequestContext.SetPreference("browser.web_app.create_on_desktop", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.web_app.create_in_apps_menu", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.web_app.create_in_quick_launch_bar", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("geolocation.access_token", true, out errorMessage);
// Preferences that are exclusively used to store managed values for default
// content settings.
ChromiumWebBrowser.RequestContext.SetPreference("profile.managed_default_content_settings.geolocation", true, out errorMessage);
// Dictionary of schemes used by the external protocol handler.
// List of protocol handlers.
ChromiumWebBrowser.RequestContext.SetPreference("custom_handlers.registered_protocol_handlers", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("custom_handlers.enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("custom_handlers.ignored_protocol_handlers", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("protocol_handler.excluded_schemes", true, out errorMessage);
//
ChromiumWebBrowser.RequestContext.SetPreference("default_apps_installed", true, out errorNew);
ChromiumWebBrowser.RequestContext.SetPreference("default_apps", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("apps_promo_counter", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("intl.app_locale", true, out errorNew);
ChromiumWebBrowser.RequestContext.SetPreference("component_updater.state", true, out errorMessage);
// The metrics client GUID and session ID.
ChromiumWebBrowser.RequestContext.SetPreference("user_experience_metrics.client_id", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("user_experience_metrics.session_id", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.media_stream_camera_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.notifications_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.geolocation_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("profile.important_site_info_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("search.suggest_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("default_search_provider.enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("bookmark_bar.show_on_all_tabs", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("safebrowsing.enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("policy.url_whitelist", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("default_apps_install_state", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.touchpad.enable_tap_to_click", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.language.pinyin_correct_pinyin", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.accessibility", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.labs.advanced_filesystem", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.labs.mediaplayer", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.internet.show_plan_notifications", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.theme.use_system", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.theme.pack", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.theme.id", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.ui.developer_mode", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("extensions.toolbarsize", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("plugins.last_internal_directory", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("plugins.plugins_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("plugins.plugins_list", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("plugins.enabled_nacl", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("plugins.show_details", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.default_browser_setting_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("browser.custom_chrome_frame", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("settings.internet.show_plan_notifications", true, out errorMessage);
//
ChromiumWebBrowser.RequestContext.SetPreference("extensions.enabled_extensions", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("settings.enabled_settings", true, out error);
ChromiumWebBrowser.RequestContext.SetPreference("content_settings_window.geolocation_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("content_settings_window.media_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.global.javascript_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.global.plugins_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.media_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.java_enabled", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("allow_running_insecure_content", true, out errorMessage);
ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.allow_running_insecure_content", true, out errorMessage);
// ChromiumWebBrowser.RequestContext.SetPreference("profile.content_settings_window", new List<object> { "notifications", "geolocation", "important_site_info", "media_stream_camera", "site_engagement" }, out error);
// ChromiumWebBrowser.RequestContext.SetPreference("content_settings_window.exceptions", new List<object> { "notifications", "geolocation", "important_site_info", "media_stream_camera", "site_engagement" }, out error);
// ChromiumWebBrowser.RequestContext.SetPreference("profile.exceptions", new List<object> { "notifications", "geolocation", "important_site_info", "media_stream_camera", "site_engagement" }, out error);
// ChromiumWebBrowser.RequestContext.SetPreference("webkit.webprefs.allow_running_insecure_content", true, out errorMessage);
// ChromiumWebBrowser.RequestContext.SetPreference("webkit.webrtc.multiple_routes_enabled", true); // false
// ChromiumWebBrowser.RequestContext.SetPreference("webkit.webrtc.nonproxied_udp_enabled", true); // false
///
});
public CefReturnValue OnBeforeResourceLoad(IWebBrowser browserControl, IBrowser browser, IFrame frame, IRequest request, IRequestCallback callback)
{
var headers = request.Headers;
headers["Custom-Header"] = "My Custom Header";
request.Headers = headers;
return CefReturnValue.Continue;
}
Anyone got an answer for my question above re loading a page into the control when the WPF TabItem it is on it doesn't have focus?
@nzmike99 The default WPF TabControl
isn't really suitable for hosting a browser, see
When I add the ChromiumWebBrowserWithScreenshotSupport.cs file to the CefSharp.Wpf.Example project it needs the "using GalaSoft.MvvmLight.Command; " dependency which destroys the project with errors
@jeremiahjordani_twitter You could use any Delegate/RelayCommand implementation you like. Pretty common for WPF apps to have one.
If you don't have one then just change the access modifier for the paramaterless TakeScreenshot so it's usable in your instance. The command is entirely optional.
private void /*Btn*/Sceenshot_Click(object sender, RoutedEventArgs e)
{
/*
//CefSharp - Quick and Dirty Screenshot with no class dependency
MessageBox.Show("Take screenshot");
double dWidth = (webCefSharpChromiumWebBrowser.ActualWidth);
double dHeight = (webCefSharpChromiumWebBrowser.ActualHeight);
int actualWidth = 0;
int actualHeight = 0;
actualWidth = Convert.ToInt32(dWidth);
actualHeight = Convert.ToInt32(dHeight);
RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(actualWidth, actualHeight, 90, 90, PixelFormats.Pbgra32);
renderTargetBitmap.Render(webCefSharpChromiumWebBrowser);
PngBitmapEncoder pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create(renderTargetBitmap));
using (Stream fileStream = File.Create(@"C:\SaveFolderName\apollo.png")) //uses System.IO for fileStream
{
pngImage.Save(fileStream);
}
*/
}
[C#
] TakeScreenshot [WPF
]
/*Here is an example that reuses the image that's already rendered to the screen.*/
var template = Browser.Template;
var image = (System.Windows.Controls.Image)template.FindName("PART_image", Browser);
var pngImage = new PngBitmapEncoder();
pngImage.Frames.Add(BitmapFrame.Create((System.Windows.Media.Imaging.BitmapSource)image.Source));
var screenshotPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "CefSharp screenshot" + DateTime.Now.Ticks + ".png");
using (var fileStream = File.Create(screenshotPath))
{
pngImage.Save(fileStream);
}