I am using wpf webview2 to build an app , the webview2 will navigate to my website which has one button to connect to audio , but i want to make it connect to audio automatically , so i tried use code like
document.getElementById("audioBtn").click(); to try to connect to audio.
But seems this doesn't work, i still have to manually click the button rather than trigger the click by script. (maybe due to some browser security policy ?)
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
So how can i automatically connect to audio ? Both the WPF application and the web application is mine.. so there is no security risk..
thank you so much...
I also tried to auto allow the permission in webview2
private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) { e.State = CoreWebView2PermissionState.Allow; }
You might be trying that click before the content is properly loaded, in which case there will be no document there or element in it.
Assuming this is the problem then you can handle the navigation completed event.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.web.webview2.core.corewebview2.navigationcompleted?view=webview2-dotnet-1.0.1245.22
Something like:
wv2.CoreWebView2.NavigationCompleted += (s, at) =>
{
wv2.ExecuteScriptAsync("document.getElementById('audioBtn').click();");
};
Before you navigate
Related
I am using the ReportViewer in my WPF application and I am trying to get a custom protocol to work with the application. So I get the ability to open sub-programs inside my application when a url is clicked inside the ReportViewer.
When I click on the custom-protocol-url (inside the ReportViewer) nothing happens.
When I open the same report via the Web-Browser, my URL works flawlessly.
It seems like the ReportViewer doesn't allow custom protocols? Has anyone experienced that aswell? Is there any documentation on that?
http, https and mailto are working in the ReportViewer.
I am just adding an Action in the Report pointing to my url
customurl://123
Url definition:
[HKEY_CLASSES_ROOT\customurl]
#="URL: customurl Protocol"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\customurl\shell]
[HKEY_CLASSES_ROOT\customurl\shell\open]
[HKEY_CLASSES_ROOT\customurl\shell\open\command]
#="\"C:\\Extra Programme\\TestAlert.exe\" \"%1\""
Testalert (just the test-program by microsoft):
static string ProcessInput(string s)
{
// TODO Verify and validate the input
// string as appropriate for your application.
return s;
}
static void Main(string[] args)
{
Console.WriteLine("Alert.exe invoked with the following parameters.\r\n");
Console.WriteLine("Raw command-line: \n\t" + Environment.CommandLine);
Console.WriteLine("\n\nArguments:\n");
foreach (string s in args)
{
Console.WriteLine("\t" + ProcessInput(s));
}
Console.WriteLine("\nPress any key to continue...");
Console.ReadKey();
}
I have looked into the code of ReportViewer and found an if statement, that checks if the url starts with either http:// or https:// or mailto:.
It gets this information with Uri.UriSchemeHttp, Uri.UriSchemeHttps and Uri.UriSchemeMailto
So you could overwrite eg. Uri.UriSchemeHttp with "customurl" (if your url is customurl://123) before rendering the report.
var field = typeof(Uri).GetField("UriSchemeHttp");
field.SetValue(null, "customurl");
The more elegant solution would be, to use a webbrowser control and just show the SSRS Web-Page
i create silverlight windows phone 8.1 project and i need to choose all kind of file from windows phone
i used FileOpenPicker for choose the file it redirect correctly and i can choose the file this is my code
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.List;
openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
openPicker.FileTypeFilter.Add("*");
openPicker.PickMultipleFilesAndContinue();
And i follow this msdn for receiving select
In my case
if i selecting file and come back to the app its every thing working
if i without select any file and come back using mobile hardware back button my app come to home screen. but it need to stay file picker page
my first page
when i press mobile hardware back button in above screen the page redirect to my first page it need to stay in my second page
thanks
Finally i got the answer and avoid redirection
bool reset;
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e)
{
if(reset && e.uri.tostring().Equals("MainPage.xaml"))
{
e.Cancel = true;
reset = false
}
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
reset = e.NavigationMode == NavigationMode.Reset;
}
I need to ebed a web browser in a Wpf app, I tried with the one from the toolbox but get some issues and went to CefSharp.
public MainWindow()
{
InitializeComponent();
BrowserSettings settings = new BrowserSettings();
Cef.Initialize(new CefSettings());
CefSharp.Wpf.ChromiumWebBrowser webBrowser = new CefSharp.Wpf.ChromiumWebBrowser();
licence_grid.Children.Add(webBrowser);
webBrowser.Address = "http://myurlToLoad the page";
}
The problem is when I used a normal url the page load.
But when I used the url I intend to use and whith which the user enter his user and password in a browser pop up (I mean not a pop up from the website) . I get an error with this page take yoo much time to load and nothing else.
Can someone give me some tracks to follow...
Thanks
It sounds like the popup you are referring to is in fact the site prompting for basic authentication.
In that case you need to provide an IRequestHandler.GetAuthCredentials handler.
As the question & answer is very old and i would like to give the latest update on this solution, there is slight change as per original solution suggested.
anybody consuming cefsharp need to implement the authentication dialog. and changes in method is
bool IRequestHandler.GetAuthCredentials(IWebBrowser browserControl, IBrowser browser, IFrame frame, bool isProxy,
string host, int port, string realm, string scheme, IAuthCallback callback)
{
//NOTE: If you do not wish to implement this method returning false is the default behaviour
// We also suggest you explicitly Dispose of the callback as it wraps an unmanaged resource.
// shyam - original implemenation.
//callback.Dispose();
//return false;
bool handled = false;
// Instantiate the dialog box
AuthDialog dlg = new AuthDialog(host); // create new dialog with username and password field.
// Open the dialog box modally
dlg.ShowDialog();
if (dlg.DialogResult == System.Windows.Forms.DialogResult.OK)
{
// The user did not cancel out of the dialog. Retrieve the username and password.
callback.Continue(dlg.UserName,dlg.Password);
handled = true;
}
return handled;
}
I have an app that uses a web browser control to navigate a website. When the user clicks on a hyperlink that will take them out of the site I want to be able to stop the navigation. I tried.
void wgBrowser_Navigating(object sender, NavigatingEventArgs e)
{
if (!e.Uri.AbsoluteUri.Contains(BASEURL))
{
e.cancel = true;
return;
}
progressPB.Visibility = Visibility.Visible;
}
This does in fact stop the navigation, but it kills the page causing a navigation error message to appear in the webbrowser.
I have tried a few things including a wgBrowser.Goback() after navigation, but that is not a real "back", and causes the page to reload complete losing data the user previously entered.
Any help will be greatly appreciated.
Thanks you.
Are u tried IsolatedStorageSettings? Because using IsolatedStorageSettings store the data will be better when the page is navigate.
Example:
private void tbUserName_SelectionChanged(object sender, RoutedEventArgs e)
{
if (appSetting2.Contains("MainPage2"))
{
appSetting2["MainPage2"] = this.tbUserName.Text;
}
else
{
appSetting2.Add("MainPage2", this.tbUserName.Text);
}
}
Use can use the InvokeScreipt method over WebBrowser control to stop page navigation.
yourWebBrowser.InvokeScript("eval", "document.execCommand('Stop');");
I'm wondering how to setup my Silverlight project to enable automatic updates for out-of-browser application.
I added some code in app.xaml.cs (see below), rebuild app, installed as out-of-browser, changed versionionfo in asseblyinfo.cs, rebuilded, run again but unfortunatelly no update happened. Am I still missing something?
public App()
{
this.Startup += this.Application_Startup;
this.Exit += this.Application_Exit;
this.UnhandledException += this.Application_UnhandledException;
InitializeComponent();
if (Application.Current.IsRunningOutOfBrowser)
{
App.Current.CheckAndDownloadUpdateCompleted +=
new CheckAndDownloadUpdateCompletedEventHandler(App_CheckAndDownloadUpdateCompleted);
App.Current.CheckAndDownloadUpdateAsync();
}
}
void App_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.Error == null && e.UpdateAvailable)
{
MessageBox.Show("Application updated, please restart to apply changes.");
}
}
EDIT
Bonus question:
How App detect that there is an update? From assemblyinfo.cs? Somewhere in manifests?
EDIT
Can anybody explain me WHY IsRunningOutOfBrowser returns always FALSE even if App is run from desktop's shortcut?
Thanks to Silvelright forum, there is a solution.
IsOutOfBrowser property cannot be used in constructor. The time where it starts working is Application started event.
Make sure the web server was running so the client can connect to the server and check for updates. You might also want to check the Error property to see if there where any exceptions.