1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WebBrowser Javascript Errors C#

Discussion in 'C, C++, C#' started by bbrez1, Apr 9, 2010.

  1. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    I made a FB bot. It auto clicks on a certain button. Now I have a problem it works ok, but a lot of times it throws out a javascript error (IE doesn't do that) if I set ScriptErrorsSuppressed to true it doesn't show the error, but it does not work (does not submit).

    Any ideas? I know some of you had this problem before (lots of bots work this way)

    Thanks
     
  2. dietbird

    dietbird Junior Member

    Joined:
    Nov 3, 2009
    Messages:
    126
    Likes Received:
    64
    What is this bot written in? C Sharp?

    When you suppress the error it doesn't work because there's an error... duh.

    Just see what the error is and fix it. Or paste here and let someone fix it for you.
     
    • Thanks Thanks x 1
  3. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Hi,

    Thanks for your reply. Yes it's written in C# (I mentioned it in the title).

    I ran out of ideas, this is the error that I'm getting (pressing yes does not help):

    [​IMG]

    It's a bot that posts to walls (It throws out this error alot, from list about 20 pages it only posted to 3)

    Any kind of help is much appreciated
     
  4. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Any ideas anyone?

    thanks
     
  5. iPwnJ00

    iPwnJ00 Junior Member

    Joined:
    Mar 10, 2009
    Messages:
    132
    Likes Received:
    21
    Location:
    Melbourne, Australia
    Check if webbrowser state is 'complete' before executing the click?

    ie. the page has not been loaded yet.
     
  6. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Thanks for your post. I already did what you said (I call the function to post on Webbrowser_DocumentComplete)
     
  7. ShiftySituation

    ShiftySituation Power Member

    Joined:
    Apr 15, 2010
    Messages:
    621
    Likes Received:
    314
    Occupation:
    Having fun
    Location:
    Jacksonville, FL
    If there is an iFrame then WebBrowser_DocumentComplete will get called prematurely. There are other things that will cause it to call to but there are a few tricks you can do to insure that the page has loaded fully before the code in DocumentComplete will execute. One is a while loop but I'm not at my developer station or I would look at some of my old code and paste the loop check here... just google it.
     
  8. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Thanks will try this out :)
     
  9. smack

    smack Junior Member

    Joined:
    Feb 1, 2010
    Messages:
    182
    Likes Received:
    78
    Occupation:
    Software Engineer/Evil Genius
    Location:
    inside .NET
    please stop using the web browser control.

    every time you use a web browser control, god kills a kitten.

    take a look at HTTPWebRequest, it's not ideal but it is a far sight better than the web browser control. get yourself a packet logger like commview or httpanalyzer, and read up on HTTPWebRequest on MSDN.

    i'm hammered drunk in the atlanta airport, or else i would elaborate more. i have posted a good bit on the subject thought, so if you search, they will be there.

    cheers. i'm gonna go get more booze and wait for my flight. :)
     
    • Thanks Thanks x 2
  10. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Yep I've heard that a lot of times :D Well I worked with curl before in php so I think this won't be that hard :)
     
  11. mappum

    mappum Registered Member

    Joined:
    Aug 8, 2009
    Messages:
    84
    Likes Received:
    11
    Location:
    At my computer... how else would I be on a forum?

    I was going to say that. Well, most of that :p You have much better control by sending the data you want, not by trying to run everything through their scripts. It is a faster, easier, and more effective way to make bots. I use WireShark to analyze the HTTP requests being sent then I can figure out what I need to send.
     
    • Thanks Thanks x 1
  12. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Hey thanks for your info guys. I tried it and I have a problem. When I wan't to log into FB it says cookies aren't enabled. This is what I have till now:

    Code:
    string res = Post("https://login.facebook.com/login.php", "email=email&pass=pass&login=Login");
    Code:
            public string Post(string url, string data)
            {
                string strReturn = null;
    
                try
                {
                    CookieContainer cookieJar = new CookieContainer();
                    byte[] buffer = Encoding.ASCII.GetBytes(data);
                    HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(url);
    
                    WebReq.Method = "POST";
                    WebReq.ContentType = "application/x-www-form-urlencoded";
                    WebReq.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3";
                    WebReq.ContentLength = buffer.Length;
                    WebReq.CookieContainer = cookieJar;
                    Stream PostData = WebReq.GetRequestStream();
                    PostData.Write(buffer, 0, buffer.Length);
                    PostData.Close();
    
                    HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
                    HttpStatusCode status = WebResp.StatusCode;
                    string server = WebResp.Server;
    
                    Stream WebResponse = WebResp.GetResponseStream();
                    StreamReader _response = new StreamReader(WebResponse);
                    strReturn = _response.ReadToEnd();
                    MessageBox.Show(cookieJar.Count.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                return strReturn.Trim();
            }
    
    I haven't found anything helpful on google (I found a post on FB forum but they didn't want to help since this is against TOS)
     
  13. ShiftySituation

    ShiftySituation Power Member

    Joined:
    Apr 15, 2010
    Messages:
    621
    Likes Received:
    314
    Occupation:
    Having fun
    Location:
    Jacksonville, FL
    The response you get back is "Cookies not available"? If so, it is probably assigning cookies and then redirecting you, during the redirect you are losing cookies. Try adding:

    Code:
    //ADD THIS:
    WebReq.AllowAutoRedirect = false;   //try true, too if false doesn't work.
    //--------------------
    ...
    HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
    //ALSO ADD THIS:
    WebReq.CookieContainer.Add(WebResp.Cookies);
    //--------------------
    HttpStatusCode status = WebResp.StatusCode;
    
     
    • Thanks Thanks x 1
  14. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    Yes I get the Cookies must be enabled error. I tried what you said but it did not help.
     
  15. ShiftySituation

    ShiftySituation Power Member

    Joined:
    Apr 15, 2010
    Messages:
    621
    Likes Received:
    314
    Occupation:
    Having fun
    Location:
    Jacksonville, FL
    I used a bit of code a while back that I got from the net. What it did was control the redirects itself using WebRequest/Response in a loop. I don't know where I got it from and I doubt I still have it on my hard drive. It turned out that I was going around my elbow to get to my asshole and didn't need the code. It might work for you, it might not.
     
    • Thanks Thanks x 1
  16. w84it

    w84it Regular Member

    Joined:
    Jun 18, 2009
    Messages:
    442
    Likes Received:
    752
    There's initial cookies you have to get before processing the POST request.
    So first just do a normal webrequest with cookies to the login page and then do the POST request. :D
     
    • Thanks Thanks x 1
  17. ShiftySituation

    ShiftySituation Power Member

    Joined:
    Apr 15, 2010
    Messages:
    621
    Likes Received:
    314
    Occupation:
    Having fun
    Location:
    Jacksonville, FL
    w84it is right. You need to pass around your CookieContainer. You can use an "out CookieContainer" in your request methods so you can return your response string and pass back the CookieContainer to reuse again and again as it gets updated with new information.
     
    • Thanks Thanks x 1
  18. bbrez1

    bbrez1 Power Member

    Joined:
    Feb 21, 2009
    Messages:
    675
    Likes Received:
    2,360
    How come I didn't think of that before :D It works now, thanks
     
  19. Zone117x

    Zone117x Newbie

    Joined:
    Nov 4, 2009
    Messages:
    17
    Likes Received:
    2
    I love you :)