I have a problem with blocking iframes in the webbrowser control. Currently I am using this code:
foreach (HtmlElement x in ((WebBrowser)sender).Document.GetElementsByTagName("iframe"))
{
MessageBox.Show("iframe!"); //DEBUG
x.OuterHtml = #"<iframe src=""about:blank"" frameborder=""0"" style=""display:none;""></iframe>";
// x.OuterHtml = String.Empty; //gives the same result
}
It works but when navigating to www.popuptest.com , the application just freezes completely because of this code. It shows 2 "iframe!" message boxes and freezes after closing the second one.
I have found the 2 iframes in the source code of webpage (in the advertisements shown on that website). This is the code that is causing it to freeze:
(a=document.createElement("IFRAME"),a.frameBorder=0,a.style.height=0,a.style.width=0,a.style.position="absolute",t=a,document.body&&(document.body.appendChild(a),a=t))&&(a=a.contentWindow)&&(r="1",a.document.open(),a.document.write("<!doctype html><html><head></head><body></body></html>"),a.document.close(),k(a.document))
I guess it is because of the frame being created in a different way? I have tested it both on win7/IE10 and winXP/IE6 and the result is the same. On winXP, however, it crashes and opens the debugger instead of freezing and that is how I got the faulty code.
Is there a better/safer method of removing the content of iframes?
I would try disabling frames using Download Control (DLCTL_NO_FRAMEDOWNLOAD). Here's how it can possibly be done, although I haven't tried that myself. Let us know if that works for blocking frames or not.
Related
Summary
I have a Xamarin application which creates a GoogleApiClient and calls EnableAutoManage. When my app runs, I am asked which user account to use, and then the app hangs on a blank popup page with a Google-themed spinner. Why is this happening?
Details
I have been following this video which shows how to set up an application's to read Google Fit data. Notice the timestamp - this is where the code is presented.
https://youtu.be/j_zsNxMI6jI?t=2172
I have followed the examples here, and have narrowed the problem to this piece of code:
// In my MainActivity's OnCreate:
try
{
int defaultClientId = 0;
googleApiClient = new GoogleApiClient.Builder(this)
.AddApi(FitnessClass.HISTORY_API)
.AddApi(FitnessClass.RECORDING_API)
.AddScope(FitnessClass.ScopeActivityRead)
.EnableAutoManage(this, defaultClientId,
result =>
{
int m = 3; // Breakpoint here is never hit
})
.Build();
}
catch (Exception e)
{
int m = 3; // Breakpoint here is never hit either
}
If I run my app (tried on both emulator and physical hardware), I am first asked which account to use.
After selecting the account, another popup appears with a Google-themed (changing between red, yellow, green, and blue) spinner at the top. The popup stays on screen and the spinner animates indefinitely.
As noted in the code above, no exceptions are raised, and no result is returned in the EnableAutoManage delegate. Why is this happening?
Update 1
If I remove the following line, the app no longer shows a spinner indefinitely:
.AddScope(FitnessClass.ScopeActivityRead)
The addition of this line of code seems to be the cause of the popup with the spinner.
Update 2
I thought I'd try the "new" approach of using GoogleApi rather than GoogleApiClient as explained here:
https://android-developers.googleblog.com/2017/11/moving-past-googleapiclient_21.html
Unfortunately, there seem to be no Xamarin bindings for this yet:
Xamarin Android: Cannot resolve GoogleSignIn and GoogleSignInClient
The reason this happened is because my google account hadn't yet been added as a test user. One might expect that Google would provide some kind of useful feedback through a popup, but instead it provided an empty page.
To solve this problem:
Go to https://console.cloud.google.com/apis/dashboard
Click on OAuth consent screen
Scroll down to the Test Users section
Enter the email addresses of the test users you would like to use testing your app (such as your own personal gmail)
Now the app should properly display a confirmation page.
I'm struggling with the browser control in my WEC7 application. I'm trying to display a local file in the webBrowser control, and everything appears to be working except that the page does not show up in the control on my form. All I see is a white rectangle where the webBrowser control is.
I made a stand-alone test app which does nothing but load a local file into the webBrowser control. I found code elsewhere on stackoverflow which seemed pretty clear. This is the code that loads the page:
private void LoadPageBtn_Click(object sender, EventArgs e)
{
try
{
string applicationDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetNam‌e().CodeBase);
string myFile = Path.Combine(applicationDirectory, #"HTMLPage1.htm");
Uri uri = new Uri(myFile);
webBrowser1.Navigate(uri);
}
catch (Exception ex)
{
Debug.WriteLine("ERROR: " + ex.Message);
}
}
The file HTMLPage1.htm is really basic and shows up fine in any desktop browser. If I provide a bogus file name in the code then I get a file not found exception, so I'm pretty sure the file is being deployed correctly on the target (set to "always copy" in the file properties).
I catch the Navigating, Navigated, and Complete events from the webBrowser control and output some debug stuff, including the URL from the WebBrowserNavigatingEventArgs. When the code runs I get the following debug output:
Navigating: file:///Program Files/webtest/HTMLPage1.htm
Complete:
I never see the Navigated event but I'm not sure that's a problem.
And the darn webBrowser control continued to show a white rectangle. Can anyone suggest what I may be missing?
I have posted the code here in case anyone would be kind enough to try it out themselves:
https://drive.google.com/file/d/0B75fBmfP8FI4YmpvYXFXcGN1Qzg/view?usp=sharing
OK, I found out what's going on. The answer was actually found on the Toradex support forum. The WebBrowser control is just a wrapper around IE and therefore IE needs to be included in the OS before you can use the WebBrowser in your application.
My OS build does not include the web browser components, so I'm in the process of rebuilding the OS and including all the IE7 stuff.
I have this browsercontroller and wonder how can I scroll down to the bottom of the page? I don't know the right command for this one
Here is my part of my code
Browser browserController = new Browser(); //call browser controlle
Searcher searchKey = new Searcher();
browserController.browserCloser("iexplore"); //close all recent open IE to avoid issues
using (IE browser = new IE(browserController.URLData())) //original code but with time out exception
{
browser.AutoClose = false;
browser.WaitForComplete(40);
Thread.Sleep(20000);
}
I need to scroll down to the IE and wait for the item to load
this is the website I'm checking https://hpe.wd5.myworkdayjobs.com/Jobsathpe/
I need to load all the results in the page
Do not use Thread.Sleep() in UI thread. It usualy blocks any UI actions even these which was invoked just before this call. Use Timer instead.
Codebehind:
scrollTo method
create a control at the bottom of the page... and Focus
Client side:
scrollTo, scrollBy
I'm working with a winform TabControl showing WebBrowsercontrols to display youtube videos.
However with two videos or more it becomes really annoying as all videos start directly.
I basically need to find out if there is a JS function, html code or a simple WebBrowser property to change, so videos are paused.
It might come in handy to find something like that for video quality too.
Has anybody ever heard of/seen where this option is stored? Or maybe the Js function itself being invoked when manually setting the quality?
EDIT:
b.DocumentCompleted += delegate { b.DocumentText=b.DocumentText.Insert(b.DocumentText.IndexOf("class=\"video-stream html5-main-video\""), "autoplay=false ");};
b.Url = new System.Uri(inp[s], System.UriKind.Absolute);
Basically this should add a new Event handler on each webbrowser form that modifies the DocumentText when the Uri that is called during creation has loaded.
Even though the browser debugger shows
<video tabindex="-1" class="video-stream html5-main-video" controlslist="nodownload" style=... src=...></video>
this isn't in the actual source code.
However I found
$oa=function(a){g.S(a.o,"video-stream");g.S(a.o,"html5-main-video");var b=a.app.g;b.zc&&a.o.setAttribute("data-no-fullscreen",!0);b.Oh&&(a.o.setAttribute("webkit-playsinline",""),a.o.setAttribute("playsinline",""));b.Nr&&a.o&&a.P(a.o,"click",a.o.play,a.o)};
in the base.js. Is it possible that youtube generates the html from the js?
How can I modify the video-tag attributes then?
I tried to modify when the event handler manipulates the video tag, since there may be DocumentCompleted events thrown from scripts or anything.
delegate (object sender, System.Windows.Forms.WebBrowserDocumentCompletedEventArgs e){
if (e.Url.AbsolutePath != ((System.Windows.Forms.WebBrowser)sender).Url.AbsolutePath){
//...
However it still fails as there is no occurance of the specific class that on the video tag.
I now dodged this by loading the Url only when the browser tab is selected, if someone finds a real solution, feel free to share
I have a form with a browser control. (this control uses IE9 because I set values on registry editor)
This web browser navigates to a specific URL and fills all fields on HTML page and submit them, then result page is displayed.
My problem is that i just want to know when this reslut page is fully loaded or completed so that i can fetch some information.
I use WebBroswer_DocumentCompleted event which works fine for the first page but not for the result page as it triggers before result
page is loaded.
I tried other solution which is to check the div tag inside the result page (this tag only appears when result page is loaded completely) and it works but not always.
My code:
private void WebBroswer_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlElementCollection elc3 = this.BotBrowser.Document.GetElementsByTagName("div");
foreach (HtmlElement el in elc3)
{
if (el.GetAttribute("id").Equals("Summary_Views")) //this determine i am at the result page
{
// fetch the result
}
}}
That div id is "Summary_Views".
I can provide you the link of that website on demand which is just for BLAST tools and database website for research purpose.
Frames and IFrames will cause this event to fire multiple times. Check out this answer:
HTML - How do I know when all frames are loaded?
Or this answer:
How to use WebBrowser control DocumentCompleted event in C#?
Or ms's kb article:
http://support.microsoft.com/kb/180366
Do you know if there are frames? If so then please say so, so people can help with that. If not then say so, so people can offer alternatives.
My guess is that the content is being generated by JavaScript. If it is then the document is complete before the JavaScript executes and you need to somehow wait until the JavaScript is done. The solution depends upon the web page. So you might need to process multiple document completes for diagnostic purposes and attempt to determine if there is a way to know which one you need.
At last i have solved my problem. I put a timer control from toolbox and set its time interval to 200ms and its Autoreset property to false. I set a tick event which has a code to check every 200ms whether this Div has been loaded or not, after that, Autoreset property is set to true.This solution is working perfectly :)