How to add an adblock plug-in to the WebBrowser control? - c#

I'm making a winform application containing a WebBrowser control. I'm trying to connect to a Web page that contains ads, but it's affecting the loading speed of the page. The adblock plugin for Chrome blocks ads. So is there any way to add that plugin or any other way to achieve the same result?

The adblock plugin is just some js script with some browsers specific metadata on top. You can check the source code here: https://adblockplus.org/source
You can probably sort something out with this (like run the plugin's code after page load)

Related

WebBrowser control - enter and keep offline mode

I would like to manually load HTML into a web browser control and make sure it does not create any internet traffic, so just show the content to the best of its abilities.
As specified in MSDN, WebBrowser.IsOffline is read-only.
Is there a way to set it (without using reflection hacks)?
Or do I have to resort to using a 3rd party control for this:
The most complete C# Webbrowser wrapper control
You can set WebBrowser.AllowNavigation to False.
Whether the control can navigate to another page after its initial page has been loaded.

Running Javascript Off a Webpage Through C#

I have a bunch of webpages where I need to grab some product information but the webpages are all written using javascript. So there will be something like
<a href="javascript:__getInfo('content_abc')">Product Name<a>
And once that's clicked all the page's content will change (but not the html address). How can I programmatically execute that script and get all the loaded content through a C# script?
While this is the wrong approach to your problem, there is a solution that might work.
By using automated testing tools, such as Selenium, it is possible to use the web driver interface to take control of a web browser and interact with elements on the screen, click buttons and check for results.

Windows Phone browser live html modification

I haven't looked into it very much but am struggling to find relevant information on the topic. I basically want to create a browser that applies a filter to a webpage by changing colors in a webpage. My guess is that I will have to change the html once loaded or something, would this work? Do I have other options?
PS. I don't just want to make every color darker, I would more like to invert the colors.
Edit:
If any you were wondering, I am talking about the XAML browser component that can be used in a Windows Phone application.
I think the simplest way to do that is to inject some Javascript into your page once it has loaded.
To do that, you need to set the IsScriptEnabled to true on your WebBrowser control and then subscribe to the Navigated event.
When that event occurs you can inject some JS codeby using the WebBrowser.InvokeScript method.
Here is an example of JS code that darken the page : JavaScript: Invert color on all elements of a page
If you are talking about in a PC internet browser, you can find an add-on to execute Javascript automatically, such as Greasemonkey for Firefox. If you are talking about Windows Phone's Internet Explorer, I don't really know what you could do there, as I don't think they allow add-ons.

c# asp.net use Windows Forms WebBrowser

I have a class of library code which uses a System.Windows.Forms.WebBrowser control to load a web page then extract information from the DOM tree, etc... I've found this to be the only reliable way to be able to parse information loaded onto a page with javascript, etc...
This worked fine when testing with console app, but when I call the same method from an asp.net page (ASP.NET MVC Controller) it crashes with a "ActiveX control '8856f961-340a-11d0-a96b-00c04fd705a2' cannot be instantiated because the current thread is not in a single-threaded apartment."... i've tried adding [STAThread] to my method but that doesn't seem to help!
Any ideas?
Thanks
Update:
I need to allow a page to complete load and execute all its javascript, then search it for text that matches a template I have already stored... Don't think HtmlAgilityPack will work? Does WatIn run the javascript?
Save yourself a lot of headache and use WatiN instead of a WebBrowser control.
See this question: Best method for Website Automation?
I believe it is impossible to get IIS to run in single thread apartment model (STA). Instead of using the WebBrowser control, you could take a look at the HTML Agility Pack. It will let your read in a web page and poke around the DOM. The WebBrowser control uses lots of computer resources that you won't have to worry about it make the switch.
Everything in the System.Windows is intended for desktop, not web stuff. I agree with Jake Pearson that you should use something else. But if you want you can try forcing the page into STA mode using this directive:
<%#Page AspCompat="true"%>
http://msdn.microsoft.com/en-us/library/zwk9h2kb.aspx

Drag and Drop to a hosted Browser control

I have a WinForms program written on .NET 2 which hosts a webbrowser control and renders asp.net pages from a known server.
I would like to be able to drag, say, a tree node from a treeview in my winforms app into a specific location in the hosted web page and have it trigger a javascript event there.
Currently, I can implement the IDocHostUIHandler interface and getting drag\drop events on the browser control, then call Navigate("javascript:fire_event(...)") on the control to execute a script on the page. However, I want this to work only when I drop data on a specific part of the page.
One solution, I suppose, would be to bite the bullet and write a custom browser plugin in the form of an activex control, embed that in the location I want to drop to and let that implement the needed drag\drop interfaces.
Would that work?
Is there a cleaner approach? Can I take advantage of the fact that the browser control is hosted in my app and provide some further level of interaction?
Take a look at the BrowserPlus project at Yahoo.
It looks like they have built a toolkit so that you don't have to do the gritty work of writing the browser plugin yourself.
If you can find out the on screen position of the part of the page you are interested in, you could compare this with the position of the mouse when you receive the drop event. I'm not sure how practical this is if you can get the info out of the DOM or whatnot.
As an alternative could you implement the mouse events on the bit of the page using javascript?

Categories

Resources