Search code examples
c#geckogeckofx

Method to block image, flash, style when use gecko navigate?


I need to make a bot "get video link" from abc..
I use httpwebrequest and httprespone but I realize this website has ajax text and httpwebsite can't get it.
-> I decide to use geckowebrowser
Step by step
1. use geckowebrowser documentcomplete event and use navigate to website
2. use geckobutton to click and wait 5 seconds to get ajax text
-> It success but too slow, it delay to load style, image, flash, etc

so I try to search and I get this "DOMContentLoaded event fires when the DOM is loaded, but before all page assets are loaded (CSS, images, etc.)." ya, this is what i want, i don't want to load image, flash...
but when i use it, i get this code

    GeckoWebBrowser web2 = new GeckoWebBrowser();
    web2.DOMContentLoaded += Web2_DOMContentLoaded;
    private void Web2_DOMContentLoaded(object sender, DomEventArgs e)
    {
        ...
        //When domcontent loaded i need to get some element
        but i can't find any function can do that here
        i need to use document.getElementById or something like that :(

    }

How can I do that "without global variable" ? or any other "method to block image, css, flash" when use gecko navigate.... please help :(

Thanks for read my post !!


Solution

  • Make sure Property of your Gecko Web Browser UseHttpActivityObserver is True.

    Now you can handle whether you want to load different types of content or not. Example below is for .jpg. Sorry, it's in VB. To convert it, you can use http://converter.telerik.com/

    Private Sub Browser1_ObserveHttpModifyRequest(sender As Object, e As Gecko.GeckoObserveHttpModifyRequestEventArgs) Handles Browser1.ObserveHttpModifyRequest
    Dim str = e.Uri.ToString
         If str.Substring(str.Length - 4) = ".jpg" Then
              e.Cancel = True
         End If
    End Sub