×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 24

Hybrid View

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Issues working with web browser control

    Hi All,

    I am working on this new Lumia app where I have to get the html loaded document in my web browser control, filter html elements tags based on some criteria and validate user input.
    Parse html document include search for some tags, autofill text boxes values or validate user input values, automatically call submit button etc.

    here Html File will be dynamically loaded on my web browser control and I have no information about it.

    We can do this very easily with old control -
    Example is -

    webBrowser.Document.GetElementsByTagName(“div”);
    or
    webBrowser.Document.GetElementById(attribName).GetAttribute(“Value”);


    If we have to do same in windows phone what are alternatives -

    We can do something like this -
    String title = (string)browserCntrl.InvokeScript("eval", "document.title.toString()");

    It will give us title of document but how can be achieve the above in example with new web browser control.

    Is eval is the only approach to work with html document on new browser control?

    I am seeking for ideas and work around here.

    Thanks to all
    Last edited by sunder.tinwar; 2013-03-22 at 07:01.

  2. #2
    Nokia Developer Champion
    Join Date
    Sep 2012
    Location
    Morocco
    Posts
    291

    Re: Issues working with web browser control

    Hello,

    Just do a simple request using WebClient or HttpWebRequest using the "DownloadStringAsync("http://yoururl")" method, you will get a the html document as a string.

    then after you'll have to parse it, I use "htmlagility" api which allows you to parse your html very easily (you can download it from nuget).

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Thanks for reply, please check my updated question.

    I have to use web browser control only, as I have to work with user input, validate etc. So download string or http web request stuff will now work as per requirement.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Issues working with web browser control

    Is that working for you?

    You're running outside the browser and the web page and web site. The party that should be worried about injection is the site developers/owners.

    I think you will have an harder time parsing yourself the HTML than using that approach.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Yes all the examples provided here are working.

    We can parse a html document easily as shown in example. But I have to do same with new web browser control in windows phone sdk.

  6. #6
    Nokia Developer Champion
    Join Date
    Jul 2012
    Posts
    88

    Re: Issues working with web browser control

    Hello,
    If I understand well what you're asking, you want to get and parse the current HTML content of your webbrowser control ?
    Did you try using the WebBrowser.SaveToString Method?
    As for Parsing, you can use HTMLAgility, it is very powerful and easy to use.

    Hope this helps,
    Charaf

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Thanks for reply.

    We can save html page using WebBrowser.SaveToString Method. But then we have to parse it step by step.

    We will not be filter like this -
    webBrowser.Document.GetElementsByTagName(“div”);
    or
    webBrowser.Document.GetElementById(attribName).GetAttribute(“Value”);

    I have to use web browser control, as what user input I need to validate that and perform some action accordingly.

    I will dig into HTMLAgility today.

  8. #8
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    HTMLAgility is supported till windows phone 7 and 7.5. Their library yet not support WP8. But I must say its very powerful tool for parsing html. Thanks for introducing this to me. I will keep looking into the issue and find a solution.

  9. #9
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Hey guys I hit another issue with same, couple of website are blocking, injected javascript code.

    Now blocking code in the sense, blocking accessing to this keyword etc. Still your javascript code will be injected and work.

    I need find solution for this as well.

  10. #10
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Issues working with web browser control

    Can you give more details about what you are trying to do and what is failing?

  11. #11
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Quote Originally Posted by paulo.morgado View Post
    Can you give more details about what you are trying to do and what is failing?
    So I found the root cause which is very interesting to know, actually site were not blocking my javascript but whats happening was -

    When we browse a website on web browser control, browser control will download its external CSS and JavaScript automatically.

    Now if we try to save html document using webBrowserCntrl.SaveToString(); it will save only html part of it as a string and miss external CSS and JavaScript files.

    Now we can inject our JavaScript and try to navigate html using webBrowserCntrl.NavigateToString(html); but it will load only html part without external CSS and JavaScript files.

    My solution will work perfectly if sites have javascript and css in html file only.

    A Note about HtmlAgilityPack : The issue appears to be that the NuGet package references the incorrect assembly for WP8.

    By default it seems that it references the binary in sl4-windowsphone71, manually removing the reference to the HtmlAgilityPack DLL and referencing the binary in the sl3-wp folder removes the dependency problem.

    That is how I have resolved it anyway.

    So I guess with new control we can't do much. Developers are helpless now.

  12. #12
    Registered User
    Join Date
    Jan 2013
    Posts
    34

    Re: Issues working with web browser control

    Try adding a BASE element to the HTML with the base address of the page.

    But why don't you use the eval function to do whatever you want in the page instead?

  13. #13
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    Guys have anyone found any solution to this issue?

  14. #14
    Nokia Developer Champion
    Join Date
    Feb 2013
    Location
    Dublin, Ireland
    Posts
    475

    Re: Issues working with web browser control

    Quote Originally Posted by sunder.tinwar View Post
    Guys have anyone found any solution to this issue?
    webBrowser.InvokeScript( ... ) is the only way to interact with the HTML document. It's not as convenient webBrowser.Document.GetElementsByTagName(“div”) but it's all we have - and this applies to both Windows Phone 7 and Windows Phone 8.

  15. #15
    Registered User
    Join Date
    Mar 2013
    Posts
    36

    Re: Issues working with web browser control

    So is there a way we can achieve this webBrowser.Document.GetElementsByTagName(“div”) using webBrowser.InvokeScript( ... ). InovkeScript mostly useful in condition we know some js function already exits and we can just invoke it.

Page 1 of 2 12 LastLast

Similar Threads

  1. Browser control issues, 100% CPU on processing
    By digitalsol in forum Symbian C++
    Replies: 5
    Last Post: 2010-11-02, 13:40
  2. Replies: 5
    Last Post: 2010-08-17, 10:34
  3. Browser Control LoadUrlL not working
    By saha_forumnokia in forum Symbian C++
    Replies: 3
    Last Post: 2007-12-26, 18:18
  4. S60 Browser Control/Plugin APIs issues
    By moranski in forum Symbian C++
    Replies: 5
    Last Post: 2007-10-17, 06:49
  5. S60 Browser Control/Plugin APIs issues
    By moranski in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2006-04-23, 09:25

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •