VS 2019 - CefSharp - Screen sharing options not showing up - c#

We are creating a desktop application with embedded browser that can connect to conferences at https://meet.jit.si/ We used CefSharp (v 79.1.360) that works fine with audio and camera, except that it does not open "Screen sharing" options. When that web conference is used from a regular Chrome or Firefox, a new popup is displayed with options to share entire desktop or a specific program. Please let me know if that is a settings issue in CefSharp or a limitation of all embedded browsers that they cannot provide screen sharing. Appreciate your help very much in either making this work in CefSharp or in suggesting another Browser control that works.
Settings
CefSettings settings = new CefSettings();
// Add the --enable-media-stream flag
settings.CefCommandLineArgs.Add("enable-media-stream", "1");
settings.CefCommandLineArgs.Add("enable-usermedia-screen-capturing", "1");
Cef.Initialize(settings);
browser = new ChromiumWebBrowser("https://meet.jit.si/");
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);
// Allow the use of local resources in the browser
BrowserSettings browserSettings = new BrowserSettings();
browserSettings.FileAccessFromFileUrls = CefState.Enabled;
browserSettings.UniversalAccessFromFileUrls = CefState.Enabled;
browser.BrowserSettings = browserSettings;

Related

Which firefox web driver preference is to allow screen sharing?

I am using Selenium Firefox Options Preferences to avoid pop ups for permissions such as microphone, video. But I want to avoid the pop up for screen sharing too. This is the code where i am setting the Firefox Options:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.SetPreference("permissions.default.microphone", 1);
firefoxOptions.SetPreference("permissions.default.camera", 1);
So, as i mentioned before, the question is, what would be the preference to allow screen sharing of entire screen in Firefox Web Driver?
i think you need this:
firefoxOptions.SetPreference("media.navigator.permission.disabled", true);

WPF CefSharp: Session restoring does not work

I have a question.
I develop a WPF application using CefSharp v75.1.141 from NuGet.
The application contains several instances of ChromiumWebBrowser with separate containers cookie cache, etc. where each instance is authorized on the site https://web.whatsapp.com/ under different account. On other sites, session are saved and restored successfully, but not at WhatsApp.
WhatsApp, as I understand it, uses cookies, local storage and file system for authorization.
All this seems to be saved on disk, but authorization is always required after a restart.
I tried many configuration options for Cef, but nothing worked.
But if you use Cef in normal mode (without separate storage), everything works fine.
Browser Initialization Code on app startup:
var settings = new CefSettings();
settings.RootCachePath = "Cache";
// For FHD+
Cef.EnableHighDPISupport();
// Initialize cef with the provided settings
Cef.Initialize(settings);
Browser instance setup:
if (UID == null)
UID = Guid.NewGuid().ToString();
var requestContextSettings = new RequestContextSettings
{
CachePath = Path.Combine("Cache", UID),
PersistSessionCookies = true,
PersistUserPreferences = true
};
Browser = new ChromiumWebBrowser("https://web.whatsapp.com/);
Browser.RequestContext = new RequestContext(requestContextSettings);
I really need your help. Ty.
WhatsApp is really.. kinda special. But there's a solution for your problem.
What you need to do is to give WhatsApp Web App little bit more time to process its stuff. Don't close your app too early (give it about 20-40 seconds to let it finish saving data).

Geckodriver 0.16.0 start firefox with flashplayer

Since geckodriver v0.16.0 flashplayer is disabled by default.
Is there any possibility to start firefox with enabled flashplayer?
I'm using C#. My code right now:
var profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("selenium"); //created firefox user named selenium
profile.SetPreference("plugin.state.flash", 1);
Code bellow doesn't work for me:
profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", true);
When I use this one:
profile.SetPreference("plugin.state.flash", 1);
firefox is asking if I want to enable flashplayer, and than refreshes page (with all inputs filled previously - so i got empty fields).
If I select "allow and remember", next time I start this code nothig is saved. I'm getting the same situation.
I found solution there:
How to enable Adobe Flash in FireFox Selenium webdriver with FirefoxProfile
If I replaced profile.setPreference("plugin.state.flash", 1); to profile.setPreference("plugin.state.flash", 2); it stopped to asking me if I want to enable flash player.
Here is the solution for you:
With Selenium 4.3.0, gecko driver v0.16.0 & Mozilla Firefox 53.0 this code works well with myfreecams.com.
It is worth mentioning that the default Firefox profile is not very automation friendly. When you want to run automation reliably on a Firefox browser it is advisable to make a separate profile. Automation profile should be light to load and have special proxy and other settings to run good test. You should be consistent with the profile you use on all development and test execution machines. If you used different profiles everywhere, the SSL certificates you accepted or the plug-ins you installed would be different and that would make the tests behave differently on the machines.
So, Create a New Firefox profile and use the same in the Test script involves three steps process. First you need to Start the Profile Manager, second is to Create a New Profile and third is to use the same profile in Test scripts. Let's assume we created a new FirefoxProfile by the name "debanjan".
Use the following code to open http://www.myfreecams.com/ with your new FirefoxProfile "debanjan":
String driverPath = "C:\\Utility\\BrowserDrivers\\";
//Mozila Firefox
System.setProperty("webdriver.gecko.driver", driverPath+"geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
FirefoxDriver driver = new FirefoxDriver(dc);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS);
driver.navigate().to("http://www.myfreecams.com/");
PS: This code is in Java so you may have to convert it into C# format.
Let me know, if this helps you.

All open Chrome windows using Selenium Chrome driver

How do I identify an existing open Chrome Window with a specific url in its address bar, and open a new tab in that window using Selenium web driver in C#? All examples I see shows how to open new tabs in a window that is opened within Selenium ChromeDriver.
IWebDriver driver = null;
var chromeDriverService = ChromeDriverService.CreateDefaultService();
chromeDriverService.HideCommandPromptWindow = true;
driver = new ChromeDriver(chromeDriverService);
List<string> tabs = new List<string>(driver.WindowHandles);
driver.WindowHandles always return the windows opened by the ChromeDriver. But, I am looking for all windows. As soon as the line that instantiates ChromeDriver is executed, a new window opens up. But, I need a new URL to be opened in a new tab in an existing window.
WebDriver can't control browser windows that it didn't open. This is in part a security measure to prevent WebDriver-based malware. Additionally, to communicate with a browser instance, the browser must be listening on a port for incoming driver commands. Unless WebDriver started the browser, the browser has no way to know to listen on that port.

Through windows service open browser to render and screenshot webgl page in selenium .Net

I have made an application in which i have used selenium in .Net. In the code, What i did was, using chrome driver, i opened up a url in chrome, where the page contains webgl and took a snapshot of the page. This works fine, when i run the code in visual studio, the chrome browser opens the webpage and renders the webgl page perfectly and takes a screenshot and saves to disk.
However, when i wrap this code in a windows service and invoke the service from other application , the browser window does not seem to open and even the snapshot taken says "Webgl not supported" (i have added code to show this message if webgl is not supported by the browser).
I am really confused , as the code works fine when running from visual studio, the webgl page renders ok, and when invoked from windows service say's webgl not supported.
I tried running the windows service with administrator rights as well as Local System, with interact with desktop option enabled, but didnt help.
Has anyone any idea, as what might be happening?
Here is the Code
Logger.Log("Step 001");
DesiredCapabilities capabilities = new DesiredCapabilities();
Logger.Log("Step 002");
capabilities = DesiredCapabilities.HtmlUnitWithJavaScript();
Logger.Log("Step 003");
ChromeOptions options = new ChromeOptions();
Logger.Log("Step 004");
options.AddArguments("start-maximized", "no-default-browser-check", "--ignore-certificate-errors","--enable-webgl-image-chromium", "--ignore-gpu-blacklist", "--use-gl", "--no-sandbox", "--disable-web-security");
Logger.Log("Step 005");
capabilities.SetCapability(ChromeOptions.Capability, options);
Logger.Log("Step 006");
capabilities.SetCapability(CapabilityType.IsJavaScriptEnabled, true);
Logger.Log("Step 007");
capabilities.SetCapability(CapabilityType.AcceptSslCertificates, true);
Logger.Log("Step 008");
IWebDriver WebDriver = new ChromeDriver(options);
Logger.Log("Step 009");
WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
Logger.Log("Step 010");
Logger.Log("Navigating to Url");
Logger.Log("Step 011");
WebDriver.Navigate().GoToUrl("http://localhost:8088/index.html");
Logger.Log("Step 012");
Logger.Log("Navigating to Url Complete");
Logger.Log("Sleeping for 10 sec.");
System.Threading.Thread.Sleep(10000);
Logger.Log("Sleep complete");
Logger.Log("Taking screenshot");
Screenshot screenshot = ((ITakesScreenshot)WebDriver).GetScreenshot();
Logger.Log("Step 013");
screenshot.SaveAsFile("c:\\temp\\acd.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
Logger.Log("Step 014");
Logger.Log("Snapshot Complete");
Logger.Log("Webdriver quit");
WebDriver.Quit();
You can try using PhantomJS. It will provide you with a headless browser for Chrome.

Categories

Resources