I noticed that Microsoft Edge is capable of opening multiple windows, but i can not seem to find any example of this anywhere to open multiple windows.
I need to open multiple windows in my app for popups from my main windows WebView, i know this is possible but i dont know where to start nor is there anything on the internet
You can try following sample code
var currentAV = ApplicationView.GetForCurrentView();
var newAV = CoreApplication.CreateNewView();
await newAV.Dispatcher.RunAsync(
CoreDispatcherPriority.Normal,
async () =>
{
var newWindow = Window.Current;
var newAppView = ApplicationView.GetForCurrentView();
newAppView.Title = "New window";
var frame = new Frame();
frame.Navigate(typeof(MainPage), null);
newWindow.Content = frame;
newWindow.Activate();
await ApplicationViewSwitcher.TryShowAsStandaloneAsync(
newAppView.Id,
ViewSizePreference.UseMinimum,
currentAV.Id,
ViewSizePreference.UseMinimum);
});
Source: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/f1328991-b5e5-48e1-b4ff-536a0013ef9f/uwpis-it-possible-to-open-a-new-window-in-uwp-apps?forum=wpdevelop
Related
I'm having issues with Puppeteer, I am trying to type in a textbox that is in an IFrame.
I have created a simple repo with a code snippet, this one contains an IFrame with a tweet from Twitter.
await new BrowserFetcher().DownloadAsync(BrowserFetcher.DefaultChromiumRevision);
var launchOptions = new LaunchOptions
{
Headless = false,
DefaultViewport = null
};
launchOptions.Args = new[] { "--disable-web-security", "--disable-features=IsolateOrigins,site-per-process" };
ChromeDriver = await Puppeteer.LaunchAsync(launchOptions);
page = await ChromeDriver.NewPageAsync();
await page.GoToAsync(Url, new NavigationOptions { WaitUntil = new WaitUntilNavigation[] { WaitUntilNavigation.Networkidle0 } });
var selectorIFrame = "#twitter_iframe";
var frameElement1 = await page.WaitForSelectorAsync(selectorIFrame);
var frame1 = await frameElement1.ContentFrameAsync();
var frameContent1 = await frame1.GetContentAsync();
var frame1 = await frameElement1.ContentFrameAsync(); fails with Frame # not found, see image with error below.
Versions:
PuppeteerSharp 7.0
.Net Framework 6
Git example
Try to disable some of the security features that can be disabled when launching puppeteer.
Check in puppeteer chrome://flags/ in case there's something blocking iframe access, maybe is insecure content or maybe you have to be explicit about isolation trial.
My 2 cents on this, it should allow it to access it from non secure
Args = new[]
{
"--disable-web-security",
"--disable-features=IsolateOrigins,site-per-process,BlockInsecurePrivateNetworkRequests",
"--disable-site-isolation-trials"
}
I have two instances of the ChromiumWebBrowser in my WinForms project (Visual Studio 2012). My goal is to have the second browser instance "copy" the behavior of the user input in the first browser instance. I can successfully retrieve the input from the first browser, and I managed to hook up Selenium in the project as well.
However, I'm having one issue. Whenever Selenium sends its commands, the first browser is the one that responds to them. For the life of me, I can't seem to figure out how to make the second browser respond. Whenever I completely remove the first browser, the second one starts responding correctly, but adding the first browser again will make only have the first browser use the Selenium commands. I even tried to switch out the moments the browsers are added to the form, but to no avail: whenever there are two available, the wrong one is responsive.
Relevant code:
public BrowserManager(Controller controller, string startingUrl)
{
_controller = controller;
var settings = new CefSettings { RemoteDebuggingPort = 9515 };
Cef.Initialize(settings);
// Input browser
inputBrowser = new ChromiumWebBrowser(startingUrl);
var obj = new XPathHelper(this);
inputBrowser.RegisterJsObject("bound", obj); //Standard object registration
inputBrowser.FrameLoadEnd += obj.OnFrameLoadEnd;
// Output browser
var browserSettings = new BrowserSettings();
var requestContextSettings = new RequestContextSettings { CachePath = "" };
var requestContext = new RequestContext(requestContextSettings);
outputBrowser = new ChromiumWebBrowser(startingUrl);
outputBrowser.RequestContext = requestContext;
outputBrowser.AddressChanged += InitializeOutputBrowser;
outputBrowser.Enabled = false;
outputBrowser.Name = "outputBrowser";
}
The selenium part:
public class SeleniumHelper
{
public SeleniumHelper()
{
DoWorkAsync();
}
private Task DoWorkAsync()
{
Task.Run(() =>
{
string chromeDriverDir = #"ActionRecorder\bin\x64\Debug\Drivers";
var chromeDriverService = ChromeDriverService.CreateDefaultService(chromeDriverDir);
chromeDriverService.HideCommandPromptWindow = true;
ChromeOptions options = new ChromeOptions();
options.BinaryLocation = #"ActionRecorder\bin\x64\Debug\ActionRecorder.exe";
options.DebuggerAddress = "127.0.0.1:9515";
options.AddArguments("--enable-logging");
using (IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(chromeDriverService, options))
{
driver.Navigate().GoToUrl("http://www.google.com");
var query = driver.FindElement(By.Name("q"));
query.SendKeys("A google search test");
query.Submit();
}
});
return null;
}
}
And finally, a screenshot for some visualization:
Some help with the issue would be very much appreciated. If i missed some crucial info, feel free to ask for it. Thanks in advance!
Greetz,
Tybs
The behavior is correct. You have one debug address and you can only have one debug address for CEF. Which means when you use Selenium it is only seeing one browser.
By default Selenium will send an command to current active Tab or Window. Now in your case you have multiple Chrome view embedded, but they are technically Chrome Tab/Windows which you have placed on the same form.
So if you are in luck below code in should be able to move you to the Window you are interested in
driver.SwitchTo().Window(driver.WindowHandles.Last());
See if it works. If it doesn't then your only other workaround would be to change the order of Adding ChromiumWebBrowser and that should reverse the window it works on.
Below are some important threads that you should read from top to bottom. Very relevant to your issue/request
https://code.google.com/archive/p/chromiumembedded/issues/421
https://github.com/cefsharp/CefSharp/issues/1076
I'm trying to write an application that uses the Visual Studio Team Service (VSTS) API to display items from Visual Studio Online.
I have the following code that works perfectly in a Console application:
var connection = new VssConnection(new Uri(collectionUri), new VssClientCredentials());
using (var witClient = connection.GetClient<WorkItemTrackingHttpClient>())
{
var wiql = new Wiql {
Query = "SELECT [System.Id] FROM WorkItems WHERE State = 'New'"
};
var workItems = await witClient.QueryByWiqlAsync(wiql);
}
In a Console app, I receive a Visual Studio prompt to enter credentials, and everything works great. However, when I run the same code from WPF, I don't get the prompt, and the application just seems to hang.
I had this working in my WPF app for a brief moment after allowing it to run asynchronously from a button click event. Then I made some more changes, and--hours later--I just haven't been able to get it. I CTRL+Z'd my way back to the point where it was working and still--nothing. I suspect this has something to do with thread management, and I've tried everything I can think of with using Dispatcher.Invoke and running in Window_Loaded or hooking it up to a button.
I'm completely stumped.
I'm using the following NuGet package:
PM> Install-Package Microsoft.TeamFoundationServer.ExtendedClient
You need to start another thread to execute that (e.g. System.Threading.Tasks.Task.Run).
For example:
private void button_Click(object sender, RoutedEventArgs e)
{
var workitem = System.Threading.Tasks.Task.Run(() => GetItems(123)).Result;
}
public WorkItem GetItems(int itemId)
{
var myCredentials = new VssClientCredentials();
var vstsConnection = new VssConnection(new Uri(#"https://XXX.visualstudio.com/"), myCredentials);
var vstsClient = vstsConnection.GetClient<WorkItemTrackingHttpClient>();
var workItem = vstsClient.GetWorkItemAsync(itemId).Result;
return workItem;
}
On the other hand, you can specify account in your code directly (could be let user to provide account by using a custom login window).
var u = new Uri("XXX");
VssCredentials c = new VssCredentials(new Microsoft.VisualStudio.Services.Common.WindowsCredential(new NetworkCredential("[user name]", "[password]")));
var connection = new VssConnection(u, c);
Try with this:
TfsClientCredentials tcc = new TfsClientCredentials();
tcc.AllowInteractive = true;
TfsTeamProjectCollection ttpc = new TfsTeamProjectCollection(new Uri("https://xjsdal.visualstudio.com"), tcc);
using (var witClient = ttpc.GetClient<WorkItemTrackingHttpClient>())
{
var wiql = new Wiql
{
Query = "SELECT [System.Id] FROM WorkItems WHERE State = 'New'"
};
var workItems = await witClient.QueryByWiqlAsync(wiql);
}
I am having issues with Authentication in my Windows Phone 7 app using Facebook SDK .net
here is the authentication part
var facebookClient = new FacebookClient();
facebookClient.AppId = FacebookAppId;
facebookClient.AppSecret = FacebookSecret;
var authUrl = facebookClient.GetLoginUrl(new
{
client_id = FacebookAppId,
client_secret = FacebookSecret,
scope = "publish_stream",
response_type = "token",
display = "touch",
redirect_uri = "https://www.facebook.com/connect/login_success.html"
});
browser.Navigate(authUrl);
So the browser screens seem to work fine, login screen shows and then the permissions screens show. When I press OK on the last permission screen I just get a white screen. In fact I have been staring at this white screen for 10mins now.
Any ideas?
Here is the Browser.Navigated event handler. I have commented where I have put breakpoints
async void browser_Navigated(object sender, System.Windows.Navigation.NavigationEventArgs e)
{
FacebookOAuthResult result;
var facebookClient = new FacebookClient(); // Put break point here to make sure the event is handled
if(facebookClient.TryParseOAuthCallbackUrl(e.Uri, out result))
{
if (result.IsSuccess) // Put break point here to check result but its never reached
{
Logging.WriteLine("Authentication was a success!");
Classes.Facebook.Instance.AccessToken = result.AccessToken;
CreateFacebookPost();
}
else
{
MessageBox.Show(string.Format("Error: {0}\nReason:{1}", result.ErrorDescription, result.ErrorReason), "Authentication Error", MessageBoxButton.OK);
Logging.WriteLine("Authentication Failed");
Logging.WriteLine(string.Format("Error: {0}\nReason:{1}", result.ErrorDescription, result.ErrorReason));
}
browser.Visibility = System.Windows.Visibility.Collapsed;
browser.Navigated -= browser_Navigated;
}
}
EDIT 1:
Just some more info. I know the authentication (from Facebooks view) is a success as I can now see the app on my Facebook. Also, if I push back on the phone to go to previous screen of the app and then go back into the facebook section it shows everything is ok and I can make posts.
EDIT 2:
Using very similar code, this works fine in a Windows Phone 8 app. I have compared the 2 and can't seen any difference.
Looks like I have found the solution. You have to set IsScriptedEnabled=True on the WebBrowser control. By default it is false.
I am able to stream an rtsp on windows 7 64 bit machine through C# Winform application. This is the library i used - VLCDotNet and here is the code sample to play the RTSP stream:
LocationMedia media = new LocationMedia(#"rtsp://192.168.137.73:554/live.sdp");
vlcControl1.Media = media;
vlcControl1.Play();
I would like to store the streams to a file in my PC on a button click and stop the same with another button. How do i achieve this?
Here is the code:
Vlc.DotNet.Core.Medias.MediaBase media1
= new Vlc.DotNet.Core.Medias.PathMedia("rtsp://192.168.137.73:554/live.sdp");
media.AddOption(":sout=#transcode{vcodec=theo,vb=800,
scale=1,acodec=flac,ab=128,channels=2,samplerate=44100}:std{access=file,mux=ogg,
dst=D:\\123.mp4}");
VlcControl control = new VlcControl();
control.Media = media;
control.Play();
VlcContext.StartupOptions.IgnoreConfig = true;
VlcContext.StartupOptions.LogOptions.LogInFile = true;
VlcContext.StartupOptions.LogOptions.ShowLoggerConsole = true;
VlcContext.StartupOptions.LogOptions.Verbosity = VlcLogVerbosities.Debug;
// Disable showing the movie file name as an overlay
// VlcContext.StartupOptions.AddOption("--no-video-title-show");
// VlcContext.StartupOptions.AddOption("--no-audio");
VlcContext.StartupOptions.AddOption("--rtsp-tcp"); //this line was important to make this work
As of Vlc.DotNet.Core 2.1.62, The way to do this is use the extra opts param of the .Play on the vlc control.
var opts = new string[] { #":sout=file/ogg:C:\video.ogg" };
vlc.MediaPlayer.Play(new Uri(videoURI), opts);
`