I am using skybound.geckofx .net wrapper to show stored web content in my winforms app. Some of this pages has links and js refers to online content. Is any simple way to disable downloading online content in geckofx wrapper ?
browser.Navigating += (sender, args) => { if (IsLinkOnLine(sender.Uri)) args.Cancel = true; };
Where IsLinkOnLine is a function that returns true if Uri referees to 'online content'.
browser is a GeckoWebBrowser instance.
I would also recommend using a newer version of geckofx https://bitbucket.org/geckofx/ if you've not already.
Related
I have a WPF application which uses CEF to display web content. My question is, is there a way to debug the Javascript/Web parts inside a WPF application?
You may also use ShowDevTools() extension method (source)
ChromiumWebBrowser browser = new ChromiumWebBrowser();
browser.ShowDevTools(); // Opens Chrome Developer tools window
Enable remote debugging in your application:
C# (CefSharp)
CefSettings.RemoteDebuggingPort = 8088;
C++
CefSettings settings;
settings.remote_debugging_port = 8088;
then run your app and point your browser to http://localhost:8088/ to access the Chromium developer console (the same you have in Chrome with Ctrl+Shift+j)
While the accepted answer is correct, it doesn't really have enough detail.
I got this working in CefSharp using the WinForms control in a WPF application. (the WinForms control seems to have better performance). The code for remote debugging will probably be very similar for the WPF control though.
var settings = new CefSettings { RemoteDebuggingPort = 8088 };
Cef.Initialize(settings);
WindowsFormsHost.Child = new ChromiumWebBrowser(url);
Then go to http://localhost:8088/ in your browser.
To use 'ShowDevTools()' you will need first verify if the browser is initialized.
An example solution:
//Add an event to check
ChromeBrowser.IsBrowserInitializedChanged += ChromeBrowser_IsBrowserInitializedChanged;
//Declare the event method to be called
private void ChromeBrowser_IsBrowserInitializedChanged(object sender, IsBrowserInitializedChangedEventArgs e)
{
if (e.IsBrowserInitialized)
{
ChromeBrowser.ShowDevTools();
}
}
To open the Chromium Dev-Tools window you can do the following:
CefBrowser.GetBrowser().GetHost().ShowDevTools();
This is similar to Eido95's answer, but it doesn't require the extension methods, which essentially just wrap these method calls.
NOTE: The control needs to be initialized before calling this method can be called. If you're wiring-up and F12-like functionality this shouldn't be a problem. If you're trying to do this when the app is starting you will need to listen for the ChromiumWebBrowser.IsBrowserInitializedChanged event
An alternative can be to launch cef with --enable-chrome-runtime.
You'll have the fully featured debugger (link files on disk and edit them from the debugger)
I'm new with Silverlight and Selenium. I searched to automate my Silverlight application with Selenium webdriver but I didn't find any useful source. Can someone guide me?
Cheers,
It's possible to declare methods and attributes as [Scriptable] or a whole class as [ScriptableType]. This way you can invoke/access them via JavaScript, which can be done via WebDriver's executeScript and executeAsyncScript methods. In the class constructor, you can make the instance visible in the DOM by calling:
HtmlPage.RegisterScriptableObject("AnyNameYouWant", this);
Note that no default WebDriver interaction (click, typeKeys) will work within your Silverlight object, so a click on a button, for instance, will have to be done programmatically like:
var peer = new ButtonAutomationPeer(button);
var ip = (IInvokeProvider)peer;
ip.Invoke();
The silverlight-selenium project (https://code.google.com/p/silverlight-selenium/) provides some fixtures for common UI components, relying solely on this JavaScript to Silverlight bridge. Unfortunately, this project is not currently active, but the examples should give you some insights.
I am developing Windows 8 WPF desktop app. I need to preview webcam into my app. I come to know that MediaCapture class allows this (http://msdn.microsoft.com/en-US/library/windows/desktop/windows.media.capture.mediacapture) but I am not able to use MediaCapture classs into WPF app any idea, any help how to do this ? Thanks.
Update: I am using following code and it crashes:
async private void StartWebCamPrev()
{
Windows.Media.Capture.MediaCapture mediaCapture = new Windows.Media.Capture.MediaCapture();
await mediaCapture.InitializeAsync();
await mediaCapture.StartPreviewAsync();
}
The Windows.* namespaces belong to Windows Runtime (WinRT). Most of WinRT UI APIs are not available for desktop/WPF/.NET applications, so your approach won't work. You can use almost any other technique to display webcam preview, since WPF apps can integrate with a lot of other technologies - DirectShow being most notable. I would start with WPF MediaKit.
I added a Silverlight application to my ASP.NET website. Visual Studio made a new silverlight project and added its xap to the ClientBin folder under the project of my website. So both the projects are under one solution.
My Silverlight app is supposed to read an xml file and I was unable to make it access the file from the client bin folder under the website project. Adding a reference to that project does not work since it says only references to other silverlight applications can be added. Right now its working when the file is under the silverlight project but not when it is under the website project.
how can I make it read the file from website project?
The project structure is
WEBSITE1 (solution)
-WEBSITE1 (project)
-ClientBin
-file0.xml
-silverlightchart.xap
-SilverlightChart
-file1.xml
I can access file1.xml using
XDocument document = XDocument.Load("file1.xml");
I want to access file0.xml but no path works for me, for e.g,
XDocument document = XDocument.Load("~/ClientBin/file0.xml");
and WEBSITE1 is the startup project
You should be able to read a file from the ClientBin folder simply enough without needing to do anything special. At a guess I would say the you have accidentally set the Silverlight application as the startup project. In this scenario you want the website to be the startup project then either have the Silverlight apps test page marked as the start page or to navigate to the silverlight page once the browser has started.
Edit
The problem you have is that the Load method is synchronous but Silverlight does not support synchronous access to web resources. Hence passing a Uri to the Load method will only work if the that Uri can be fulfilled by content in the Xap. Thats why an Xml file in the silverlight project works because it ends up in the Xap.
To fetch Xml from the site you need to do this:-
WebClient client = new WebClient();
client.DownloadStringCompleted += (s, args) =>
{
XDocument document = XDocument.Load(args.result);
SomeFunctionToContinueWithDocumentProcess(document);
}
client.DownloadStringAsync(new Uri("file0.xml", UriKind.Relative);
// code exits here but _document won't be loaded yet
In my silverlight I have the need to modify PDF files. I usually use Itext libraries for this kind of thing but I am seeing that I cannot reference .NET libraries in Silverlight. Is there any workaround to get the iText functions I need in Silverlight?
Your question is a duplicate of this one, how can I use non-silverlight assemblies in silverlight.
As a work around I would suggest the following for using your itext library. Create a service to do your PDF file modification and then use it via WCF. First upload the PDF file to the server from the Silverlight application. Then call a method on the service using the uploaded path.
public void EditPdf(string pdfLocation)
{
var document = new Document();
PdfWriter.GetInstance(document, new FileStream(pdfLocation,FileMode.CreateNew));
document.Open();
document.Add(new Paragraph("Hello World"));
document.Close();
}
Then retrieve the PDF for the user via the Silverlight client.