title: How to block css and image request in chromedp like puppeteer RequestInterception?
body: <p>I am trying to block CSS and images request in chromedp but I can't find proper details or code about that. if anyone know please msg me some reference code.</p>
  
  <p>in puppeteer, I am using below code to block image and CSS.</p>
  
  <pre><code>await page.on('request', (req) =&gt; {
    if (
      req.resourceType() == 'stylesheet' || 
      req.resourceType() == 'font'       || 
      req.resourceType() == 'image'      ||  
      req.resourceType() == 'media'
    ) {
      req.abort();
    } else {
      req.continue();
    }
  });
  </code></pre>
  
  <p>As per below github method, I tried but not work.
  <a href="https://github.com/chromedp/chromedp/issues/260" rel="nofollow noreferrer">https://github.com/chromedp/chromedp/issues/260</a></p>
  
  <pre><code>    package main
  
  import (
      "context"
      "io/ioutil"
      "os"
      "time"
  
      "github.com/chromedp/cdproto/cdp"
      "github.com/chromedp/cdproto/fetch"
      "github.com/chromedp/cdproto/network"
      "github.com/chromedp/chromedp"
  )
  
  func main() {
      dir, err := ioutil.TempDir("", "chromedp-example")
      if err != nil {
          panic(err)
      }
      defer os.RemoveAll(dir)
  
      opts := append(chromedp.DefaultExecAllocatorOptions[:],
          chromedp.DisableGPU,
          chromedp.NoDefaultBrowserCheck,
          chromedp.Flag("headless", false),
          chromedp.Flag("ignore-certificate-errors", true),
          chromedp.UserDataDir(dir),
      )
  
      allocCtx, cancel := chromedp.NewExecAllocator(context.Background(), opts...)
      defer cancel()
  
      // also set up a custom logger
      taskCtx, cancel := chromedp.NewContext(allocCtx)
      defer cancel()
  
      // create a timeout
      taskCtx, cancel = context.WithTimeout(taskCtx, 100*time.Second)
      defer cancel()
  
      // ensure that the browser process is started
      if err := chromedp.Run(taskCtx); err != nil {
          panic(err)
      }
  
      // listen network event
  
      chromedp.ListenTarget(taskCtx, DisableImageLoad(taskCtx))
  
      chromedp.Run(taskCtx,
          network.Enable(),
          fetch.Enable(),
          chromedp.Navigate(`http://www.yahoo.com`),
          chromedp.WaitVisible(`body`, chromedp.BySearch),
      )
  
  }
  
  func DisableImageLoad(ctx context.Context) func(event interface{}) {
      return func(event interface{}) {
          switch ev := event.(type) {
          case *fetch.EventRequestPaused:
              go func() {
                  c := chromedp.FromContext(ctx)
                  ctx := cdp.WithExecutor(ctx, c.Target)
  
                  if ev.ResourceType == network.ResourceTypeImage {
                      fetch.FailRequest(ev.RequestID, network.ErrorReasonConnectionAborted).Do(ctx)
                  } else {
                      fetch.ContinueRequest(ev.RequestID).Do(ctx)
                  }
              }()
          }
      }
  }
  </code></pre>