cefsharp - "Links that open a specific application" seem to be not working - cefsharp

I just begin with Cefsharp on C#.
Everything works fine except Cefsharp can not execute some special links that open/run a specific application on the computer.
The link still works on other Chromium official browsers (Google Chrome), I clicked the link and it launches the application. Cefshap is not, it does nothing when I clicked the link.
The link looks something like this: "runapp://api.abcxyz/..."
How can I make it work on Cefsharp?
image show that the link works on other chromium browsers

Firstly for security reasons loading of external protocols is disabled by default. Historically you would have implemented OnProtocolExecution.
There is currently an upstream bug in OnProtocolExecution see https://bitbucket.org/chromiumembedded/cef/issues/2715/onprotocolexecution-page-goes-blank-after
You can implement a workaround using RequestHandler.OnBeforeBrowser and calling Process.Start
It would look roughly something like the following (Written in Notepad++ very quickly, there maybe minor mistakes that you'd have to correct).
public class ExampleRequestHandler : RequestHandler
{
protected override bool OnBeforeBrowse(IWebBrowser chromiumWebBrowser, IBrowser browser, IFrame frame, IRequest request, bool userGesture, bool isRedirect)
{
if(request.Url.StartsWith("mailto:"))
{
System.Diagnostics.Process.Start(request.Url);
//Cancel navigation
return true;
}
return false;
}
}
browser.RequestHandler = new ExampleRequestHandler();

Related

Using WebBrowser in ASP.Net Web Application

I am trying to use a WebBrowser in a .cs class in a Web Application - NOT A WINDOWS FORM app using (VS 2019).
I know it's a Windows Form app control, but it seems like I should be able to use it in a Web App.
Using WebBrowser in Web App does not have the .Url property, so I just use the .Navigate directly - this is where the code breaks.
I have tried many suggestions on the Net, but nothing seems to work - it looks like most of the examples uses a Web Page - I want to use the WebBrowser directly in code (.cs class).
private static void LoginViaUserAgentFlow()
{
Thread thread = new Thread(delegate ()
{
StringBuilder sb = new StringBuilder(String.Format("{0}/services/oauth2/authorize",
RHOutlook.chosenInstance.sfdcURL));
sb.Append("?response_type=token");
sb.Append(String.Format("&client_id={0}", RHOutlook.chosenInstance.clientId));
sb.Append(String.Format("&redirect_uri={0}", System.Web.HttpUtility.UrlEncode(RHOutlook.chosenInstance.redirectUri)));
WebBrowser webBrowserSFDCLogin = new WebBrowser();
//Here I can't use the .Url becaue it is not available - so I just use
//Navigate to get to the site
webBrowserSFDCLogin.Url = new Uri(sb.ToString());
//This is were it breaks, comes back with error when I navigate to the site.
webBrowserSFDCLogin.Navigate(sb.ToString());
//This code is never reached - failed at above code.
if (webBrowserSFDCLogin.LocationURL != null && webBrowserSFDCLogin.LocationURL.StartsWith(RHOutlook.chosenInstance.redirectUri))
{
//webBrowserSFDCLogin.ScriptErrorsSuppressed = true;
webBrowserSFDCLogin.Stop();
}
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
thread.Join();
}
I expect to be able to navigate to the external website. If I can navigate to the site if I copy the url directly in a browser (say Chrome).
I tried using ; this gives me the Url property, but still get the error.
You really should stick to suggestions and examples.
What you are trying to do is to use class that is designed for Windows Application inside a Web Application.
Those two frameworks are similar like Earth and Mars. I am afraid you are not going to be able to grow a tree on Mars.

JXBrowser control over dialog website not responding

Hey im having issues with a website in the jxbrowser. it seems like it is running into a timeout or whatever and then in the jxbrowser there is a dialog showing up "website not responding" and i can click on "reload" or "leave".
Can I in any way access this dialog and overwrite it? For instance everytime i would get this dont ask but go to the homepage instead?
I'm having trouble finding this if it is even possible.
I found a solution. JXBrowser has a RenderAdapter where a function exists onRenderUnresponsive wich can be overridden. Look at this: https://jxbrowser.support.teamdev.com/support/solutions/articles/9000091687-detecting-unresponsive-web-page
In my case I simply want to reload the website:
Browser browser = new Browser();
browser.addRenderListener(new RenderAdapter() {
#Override
public void onRenderUnresponsive(RenderEvent event) {
browser.reloadIgnoringCache(false);
}
});

Vaadin: How to react to a tray notification click?

I'm using Tray Notifications to let the user know about some pending actions. It works fine but would love to be able to click on it and do what I need it to do like showing the correct screen, etc. Sadly I'm unable to find some click listener like other components.
Am I'm missing something?
As far as I know that's not possible with the default notification in either Vaadin 7 or 8.
If you're using Vaadin 7, you can either fake it using a non-modal window (or something similar), or use the fancy-layouts add-on (also compatible with 8) that offers a FancyNotifications component (online demo and source). It's not exactly the same thing but it may provide what you need. Also be careful to select the v7 version and to add the suggested maven repo.
Basic usage:
public class MyUi extends UI {
#Override
protected void init(VaadinRequest request) {
FancyNotifications fancyNotifications = new FancyNotifications();
fancyNotifications.setPosition(FancyNotificationsState.Position.BOTTOM_RIGHT);
Button button = new Button("Show notification", buttonClickEvent -> {
FancyNotification fancyNotification = new FancyNotification(null, "Meh", "Click me to navigate to GITHUB");
fancyNotification.getTitleLabel().setContentMode(ContentMode.HTML);
fancyNotification.getDescriptionLabel().setContentMode(ContentMode.HTML);
fancyNotification.addLayoutClickListener(notificationClickEvent -> Page.getCurrent().setLocation("https://github.com/alump/FancyLayouts"));
fancyNotifications.showNotification(fancyNotification);
});
VerticalLayout content = new VerticalLayout();
content.setSizeFull();
setContent(content);
content.addComponents(button, fancyNotifications);
content.setComponentAlignment(button, Alignment.MIDDLE_CENTER);
}
}
Result:
If you're using 8, there's the notify add-on (online demo and github page) which supports click-listeners. Please be aware that this add-on currently supports Vaadin 8 and works with browsers that support the Notification API:
Development is mainly done on Chrome. Also Firefox is tested and mainly works as planned. Other browsers are still not tested. IE11 and Edge does not support Notification API as far as I know. Anyway add-on can use used only to show notifications on browsers that do support Notification APIs.
From the github demo:
private void showWithClickHandling() {
Notify.show(new NotifyItem()
.setTitle("Notification can be also clicked")
.setBody("Click here to navigate to project's GitHub page")
.setIcon(new ThemeResource("images/github.png"))
.setClickListener(e -> {
Page.getCurrent().setLocation(GITHUB_URL);
}));
}
... which will look like:

How to avoid the display of multiple alert windows in Flex

I have a timer in my application. For every 30 min, it will hit the web services and fetch the data and updates the UI. The application was working fine till yesterday. Suddenly, because of some issue, the web services were not available for some time. During that period, Application displayed the RPC Error multiple times(More than 100 alert boxes) in alert window. Because of this alert boxes, my application was hanged and i was not able to do anything.
I have tried several approaches, but nothing worked.Finally, I have tried to use a flag. In all the approaches, this looked promising. so i have implemented it.Basically, in this approach whenever we open an alert we will set a flag.While opening and closing alert we will reset this flag. But it didn't work as expected. Is there any approach, which can help us in avoiding multiple alert windows.
Please help me, to fix this issue.
I would write wrapper for opening alerts, and use only this wrapper, not Alert.show in the code:
public class AlertWrapper {
private static var lastAlert:Alert;
public static function showAlert(text:String, title:String):void {
if (lastAlert) {
PopUpManager.removePopUp(lastAlert);
//or
//return; //ignore last alert
}
lastAlert = Alert.show(text, title, null, 4, onAlertClose);
}
private static function onAlertClose(event:CloseEvent):void {
lastAlert = null;
}
}
Imports are missing, but I hope the idea is clear.

how to show special page for IE6 users requesting them to upgrade in ASP.NET MVC

Just like the every other web developer, I'm frustrated to hack my site code to work with IE 6. So decided to give up support for IE 6 and ask them politely to upgrade to IE 7+ or Firefox.
Can you suggest me how to detect IE6 users and display a special page showing the upgrade details in ASP.NET MVC?
Is handling this at server side scripting a good idea? or do you recommend to use any client side script like jQuery to handle this?
Easiest thing IMO is to create an action filter attribute. Then you can just tag your controllers with it (or add to global filters in MVC3).
Here's the attribute:
/// <summary>
/// If the user has IE6, this will present them with a page that tells them they have a crappy old browser. It gives them options to upgrade but they can also
/// choose to proceed anyway. This check is done only when they first visit the site. A cookie also prevents unnecessary future checks, so this won't slow the app down.
/// </summary>
public class WarnAboutIE6Attribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
//this will be true when it's their first visit to the site (will happen again if they clear cookies)
if (request.UrlReferrer == null && request.Cookies["browserChecked"] == null)
{
//give old IE users a warning the first time
if (request.Browser.Browser.Trim().ToUpperInvariant().EqualsExact("IE") && request.Browser.MajorVersion <= 6)
{
filterContext.Controller.ViewData["RequestedUrl"] = request.Url.ToString();
filterContext.Result = new ViewResult { ViewName = "InternetExplorerOldWarning" };
}
filterContext.HttpContext.Response.AppendCookie(new HttpCookie("browserChecked", "true"));
}
}
}
This attribute checks for IE6, and if it's present, it renders the "InternetExplorerOldWarning" view, which you have to create. It only presents this warning once by using a cookie. You could of course tweak that however you want. In my view, I gave them links to update or download other browsers. I also gave them the opportunity to continue with IE6. Check it out:
<h3>
Your Internet Explorer is Outdated</h3>
<div class="warning">Your version of Internet Explorer is a bit too old and unfortunately won't work well with this site.</div>
<p>Have no fear. You have options and in just a few minutes you can be rocking out in our app:</p>
<ul>
<li>If you have FireFox, Safari, or Google Chrome already on your computer use one of them for Takeoff instead.</li>
<li>Upgrade to the latest Internet Explorer. You can download and install right away. Even Microsoft recommends you do this.</li>
<li>Download an Internet Explorer alternative. We recommend FireFox, Safari, or Google Chrome. Choose one or all because each is great!</li>
</ul>
<p>This warning page will only show once. If you really want to use Takeoff with your current Internet Explorer, we won't stop you. But beware, it will probably look like garbage!</p>
<p>Whatever dude, I want to my old, insecure, scary, dangerous version of Internet Explorer.</p>
</div>
You may do the detection from the coding:
// ASP.net MVC C# example
if (Request.Browser.Browser == "IE" && Request.Browser.Version.ConvertTo<float>() < 7.0)
{
// output message to urge user to upgrade to latest IE browser
}
It would be terrible practise to specifically serve a different non-functional page to IE6. For starters, if you're in the UK you're likely to run afoul of the DDA, for seconds (depending on your situation of course) you really don't want to just stop 20-25% of your users using your site.
A lot of people are forced into using IE6 at work. Pissing them off unneccesarily doesn't make good business sense.
That said, there's no reason to make your site look pixel-perfect. You can detect that they're using IE6 server-side with Request.UserAgent and display an unobtrusive message at the top of your home page (or at the top of every page) letting users know that their browser is very old and you don't support it anymore. Then you can either serve a specific IE6 stylesheet (very cut-down), or if IE6's rendering issues aren't so severe as to make your site unusable, you can just not bother about them.
When I'm doing internet-work these days I charge extra to support IE6.
Showing a totally different page for IE 6 is a bit harsh IMHO, unless you want to block/redirect there is no need to validate this on the server-side.
“Politely” would mean that you validate the browser on the client side and show an alert/remind message to upgrade. The folks at stoplivinginthepast.com have build a standard logic to do this based on conditional comments (they suggest you show a message on the top of your landing page).
http://www.stoplivinginthepast.com/get-the-code/ http://www.stoplivinginthepast.com/wp-content/uploads/2009/02/warninggrab.jpg
Image courtesy: http://www.stoplivinginthepast.com/
I came across this answer in having troubles with IE8 and less. I wanted users to user IE9 or later but with compatibility mode on IE9 showing up as IE7.
So adding on to Steve Potters answer and inspired by the following link - http://social.msdn.microsoft.com/Forums/vstudio/en-US/ae715fd2-1ddd-46f7-8c26-9aed6b2103f1/how-to-detect-compatibility-mode-in-ie-any-version?forum=netfxjscript .
I changed my code to
public class WarnAboutIeAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
var isIe9Compatible = false;
if (request.UrlReferrer == null)
{
if (request.Browser.Browser.Trim().ToUpperInvariant().Equals("IE") && request.Browser.MajorVersion <= 8)
{
var useragent = request.Headers.GetValues("User-Agent");
if (useragent != null) isIe9Compatible = useragent[0].Contains("Trident/5.0");
if (!isIe9Compatible) filterContext.Result = new ViewResult {ViewName = "_InternetExplorerOldWarning"};
}
}
}
}
Adding in hope it helps someone.

Resources