Handle error in AngularJs if iFrame page post throws exception - angularjs

I have a web application that needs to display dynamically created MS Word files and it has following constituents:
A web service that returns the Word file Stream
An intermediate server page that calls the web service and writes the stream to Response
A web page (built in AngularJs) that collects user inputs and posts data to the intermediate page. Input also contains a file that user uploads from his computer.
From the AngularJs page, I post data to the intermediate page using a hidden iFrame. Entire setup works well and when the user clicks Submit and the browser duly shows Open/Save/Cancel dialog.
How do I display a message if web service throws exception? I am not able to catch it from AngularJs code.
PS: I can use the intermediate page to display the message in iFrame but then I need to clear it out when user takes another action on the form. How can I do that from AngularJs?

Related

Scraping from an existing chrome window with Selenium

I am trying to find a way to scrape a webpage - actually a Tradingview chart - from a window that has already been opened and logged into manually.
I have a python script that opens a chart, logs in, and scrapes elements using find_element(By.XPATH,'')
The problem with this is that every time it runs, it logs in like a brand new user on a brand new installation of chrome; no cookies or previous user data.
I previously had a chrome app that was able to scrape a chrome page that I had already opened and logged into manually. It would not have to fetch the data and initiate the page. The page was already open. And it just scraped the open page (actually a Tradingview chart) whenever it wanted the data.
It would be akin to scraping a page that was open in a browser but not connected to the internet.
It just scrapes whatever's there and skips the whole download, cookie verification part of the process...because I've already done that manually..
Is there a way to do this with selenium?

Best options to display a popup for angularjs app based on conditions

I have an angularjs app with ASP.NET WebAPI2 REST APIs. There is a scenario where I have a display a popup for initiating a survey for end users (both authenticated and anonymous types). On clicking the popup options, the user will be redirected to another applicaiton which captures all the responses provided by the user.
There is no relation between the angularjs app and the survey application.
Now next time if the user revisits the application then in that case based on the previous action taken to fill the survey , I have to take a decision to display or hide the popup for the user.
I thought of cookies and localStorage as the options but I think are not ideal choices for this scenario.
Can anyone help me to know are there any other possible options to handle this scenario?
You can solve this using the redirection link.
For example if he finished correctly the Survey you will redirect him to:
www.myapp.com/survey/success
Than in the App you can do something like: get the URL parameters, if the parameters is success store it on localStorage so next time he revisits the web-page the Popup wont show.
Otherwise direct him to:
www.myapp.com/survey/
I think the best option here is to save this information in the database using your ASP.NET WebAPI2 REST APIs. In the moment that the end user clicks the survey you can also make an Api call which will save in the database info about user's action(this will probably be sth you can do for authenticated users). For not authenticated users you can just save that information in localStorage in the moment they are clicking the survey.

Working around AntiForgeryToken to post form data

I am currently writing a website that will eventually be used as a stand-along application. As a result, I created an MVC application and handle the login through a form. It then redirects to another page which is essentially all the user will see for a while. Until the rest of the application is completed, this entire website will be viewed by the users within a WPF application's WebBrowser control as part of that application.
Since the user must log in to the WPF application, I would like to keep them from having to log in twice. So, my WPF application has code to navigate to the login url and post the data as follows:
Uri linkUri = new Uri("https://www.myURL.com/Account/Login");
ASCIIEncoding encode = new ASCIIEncoding();
byte[] postData = encode.GetBytes("grant_type=password&username=" + _user.UserName + "&password=" + _user.Password);
string postHeaders = "Content-Type: application/x-www-form-urlencoded";
this.myWebBrowser.Navigate(linkUri, null, postData, postHeaders);
Based on Fiddler, I think I am sending the data correctly. However, when the WebBrowser displays, it shows the error page with
The required anti-forgery cookie
"__RequestVerificationToken_L1NjaGVkdWxlci5XZWI1" is not present.
Since I never load the initial page with the AntiForgeryToken, this is expected. However, I was wondering if there were a way around this issue. For example, is there a way to silently load the form and post it without the user seeing it? Or, am I stuck just removing the AntiForgeryToken for now until the site is no longer used within WPF?
Thanks in advance!
Use OAuth to authenticate users from the third party site.

How can I refresh browser in silverlight 4 application?

I have an Silverlight 4 application, in log-in process I have some validations and data preparation, for any reason in each step if I get an exception, I want to stop my application and refresh the browser but I want save my exception message from my last session and then update my error text block in log-in screen and inform my user about exception message.how can I save my variable in session and then refresh browser?
On silverlight side you may use HtmlPage namespace ,
Beside this refreshing a page in silverlight is not a good practice,and shows your app. as if broken.Siverlight is a RIA. using benefits of this Rich platform is better I think.
HtmlPage.Window.Navigate(HtmlPage.Document.DocumentUri, "_self");
/* You may also add Query String to your URL as Bryant said,
Uri myUri=new Uri(HtmlPage.Document.DocumentUri.toString()+ "?Exception=True", UriKind.RelativeOrAbsolute);
HtmlPage.Window.Navigate(myUri, "_self");
*/
Hope helps!
Just take the current url and append your error message to the query string and then use javascript to open the current page to that url. You can then get the query string from silverlight to get the error message.

Populating data in Silverlight App before its sent to he browser

I have a Silverlight App which gets its data from a database. My Silverlight app (running in the browser) retrieves the data through a web service. Pretty standard setup.
But there is some data which has to be there all the time or the App is in an invalid state - think data to fill drop downs etc. So I need this data to be "pre-loaded" into the App before it's sent down to the client so that it's never in an invalid state. Today I load this data via a web service call when my first page is initialized which can some times take a few seconds - during that time my App is in an invalid state.
Is there a way to populate data (from a backend database) in my Silverlight App before it's sent to the browser?
It is valid for an app to start and not be ready to use for a while, so long as the user cannot interact with it (or see the broken bits:))
Better to ensure your app has a splash screen/login page etc that displays until such time as the required resources are loaded. Once loaded you can set an app state to then show the main screen.
I had the same problem with a website that loaded the menu items via a service (as the text was data driven). Wound up running a progress spinner over the top (with a full-screen background).
I don't think you can. The application runtime occurs on the client's machine. I would suggest putting up a loading dialog while you bring those items down from the database.
What HiTech Magic said. Best practice for this is to use a splash screen or login page. You can also have your buttons (and interaction) disabled by default, and after the data is loaded, enable the UI. I would go with the spash screen though..

Resources