C# autodetect popup and click yes - c#

I am creating a C# application where I am loading some websites into an webbrowser element. The website is loaded with: myWebbrowser.Navigate(URL) or by clicking a link on a webpage.
My problem is that occasionally my application stops running and it uses huge amounts of memory. After a while I get the following message:
Stop Running this script?
A script on this page is causing you web browser to run slowly.
If it continues to run, your computer might become
unresponsive.
Yes No
I want the application to "detect" this popup-box and click yes to it, but I have no idea how to do this. Any help would be appreciated. thanks

In VB6 you could use on the SHDocVw.InternetExplorer object the method silent.
I use
webbrowsercontrol.Silent = True
To block script errors.

Related

How to wait for the end of the loading of a webpage before resuming execution using cefshrap (C#)

I'm currently working with CefSharp on a web application. I would like to be able to pause the execution of the program while the webpage is loading and then, once all the elements have been loaded, resume the execution (for example click on a button or enter a given field).
I'm a former java developper and have used Selenium on a few projects. I know that what I'm looking for is a CefSharp equivalent to the "driver.manage().timeouts().implicitlyWait(...);" method of Selenium. I've been looking for a solution for a while and have found a few threads speaking of this problem however none of the solutions seems to work.

Webbrowser control in C# weird behavior

I'm finishing (QA testing) a web parser built in C# that is parsing specific data from a
web site that is being load to a webbrowser control in a WFA (Windows Form Application) program.
The weird behavior is when I'm killing the internet connection... Actually the program is designed to navigate recursively in the site and each step its waiting for a WebBrowserDocumentCompletedEventHandler to be triggered. Beside that there is a Form timer set,
and if the handler is not triggered in a specific interval then its reloading the entire procedure.
Everything is working good even if I manually avoid the handler from triggering - As I said the timer kicks in and restart the operation successfully and retrying another value successfully.
When shutting the internet connection manually while the procedure is running, I can see the page is getting the internet explorer message: "This page can't be displayed"
(For some reason the DocumentComplete... is not triggered).
Then immediately reconnecting the internet and waiting for the timer to kick in - As expected it fires the reload function but this time everything is going wild!! the functions are being fired not in the correct order and it seems like there is 100 threads that are running at the same time - a total chaos.
I know that its not easy to answer this question without experiencing that and seeing the code
But if I copy the entire code it will be just too long using 5 different classes and I really can't see where is the problem...
I'll try to simplify the question:
why when connection lost the documentcomplete handler don't fires?
Does anyone has experienced an application going wild only after webbrowser control losses connection?
Thanks

How to run headless YUI tests and log success/failure in a log file?

I have some YUI tests which I need them to run headless. Currently, these tests are run by launching their corresponding TestFileName.html. Upon launching, the browser shows passed or failed tests on the screen with green and red icons and their corresponding messages. During this process, the machine is unusable because the browser's UI keeps popping up and down.
I am trying to make the test run headless. For that I created a WebBrowser (from .NET) control in memory and launched the page in it. But, this way I can not see the UI and determine if the tests passed of failed. I need to log the success/failure and corresponding messages in a log file in file system.
I am not sure how to do so. Can someone please tell me what can I do to achieve headless execution of YUI and creating the logs?
Thanks
You might want to look at Phantom.js. It's a head-less version of WebKit (ie. Safari and Chrome), and people use it all the time for running head-less JS tests, so you can probably find a lot more information out there for it than for that .NET thing you mentioned.
YUI provides a Node.js command line tool named "grover" that does exactly this: https://github.com/yui/grover
Use npm to install grover and then run 'grover paths/to/test/files.html ...' You can also use grover to generate code coverage reports.

Alert issue on Google chrome and firefox using javascript

When an application or a small program is written and opened in chrome/firefox it is showing "Prevent this page from creating additional dialogs".
How might I stop this error through a C# program and not through modifying about:config, chromejs, or userchrome.css. I need this to work for each and every user using the application..
Is this possible?
This is Browser Behaviour, I don't think you can change it.
Or create your own dialog box.

C#, WebBrowser, how to inject and execute JavaScript before any other script on the page?

I know how to inject my own scripts into web pages on load event, but it doesn't always work as expected. Sometimes the page succeeds to run its own scripts before mine and it makes my whole app fail. I try do disable the possibility the page spawns another browser window. I have an app running on my server, when it starts Internet Explorer instances randomly - it soon crashes the whole machine which is a disaster.
I made a script which changes window.open method and it does the trick perfectly - except the case when the page pops up another window BEFORE my code is executed. Is there a way to freeze JS before I finish injecting my script? Maybe is there a way to inject my script in an earlier point, before DocumentCompleted event? But how?
This doesn't directly answer your question about how to do it in the browser - but I'm aware of a similar thing that is done by Avast internet security and it does it using an HTTP proxy.
The idea is to intercept HTML pages as they are received over the wire, and inject your script into the HTML itself; thus there's no way that any other script can execute before it.
Whilst that might sound scary - you can do it using the technology underpinning the very excellent Fiddler HTTP debugger - the FiddlerCore API

Categories

Resources