go-rod / rod

A Chrome DevTools Protocol driver for web automation and scraping.
https://go-rod.github.io
MIT License
5.25k stars 345 forks source link

Unexpected error on browser hijacking - chrome:// and chrome-extension:// #837

Open xavier268 opened 1 year ago

xavier268 commented 1 year ago

Rod Version: v0.112.6

The code to demonstrate your question

     func main() {

    // Open browser, ensure login on a private https site ...
c := sdk.LoadConfig()
defer c.CloseBrowser()
c.Login()

    // hijack everything and trace ...
router := c.Browser().HijackRequests()
router.MustAdd("", trace)
go router.Run()
defer router.Stop()

    // sleep, to let me manually trigger a download, and trace what happens.
time.Sleep(10 * time.Minute)
   }

    // a basic trace function
    func trace(ctx *rod.Hijack) {
fmt.Printf(">>>\tRequest  : %s\n", ctx.Request.URL().String())
err := ctx.LoadResponse(http.DefaultClient, true)
if err != nil {
    fmt.Printf("******\tERROR : %v\n", err)
    fmt.Printf("%#v\n", *ctx.Response)
}

hh := ctx.Response.Headers()
for _, h := range hh {
    fmt.Printf("\t\tResponse : %v\n", h)
}
  }

What you got

When I navigate the site, I "trace" the requests and response as expected, and evything is fine.

Then, when I manually trigger the download button in the browser, i get the follwing unexpected error :

 >>>     Request  : chrome://resources/css/text_defaults_md.css
 >>>     Request  : chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.css
 ******  ERROR : Get "chrome://resources/css/text_defaults_md.css": unsupported protocol scheme "chrome"
 ******  ERROR : Get "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/index.css": unsupported protocol scheme "chrome-     extension"
 >>>     Request  : chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js
 ******  ERROR : Get "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/main.js": unsupported protocol scheme "chrome-extension"
 rod.HijackResponse{payload:(*proto.FetchFulfillRequest)(0xc00036aa10), fail:(*proto.FetchFailRequest)(0xc000302ae0)}
 >>>     Request  : chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer_wrapper.js
 rod.HijackResponse{payload:(*proto.FetchFulfillRequest)(0xc000129880), fail:(*proto.FetchFailRequest)(0xc00012b340)}
 rod.HijackResponse{payload:(*proto.FetchFulfillRequest)(0xc00036a9a0), fail:(*proto.FetchFailRequest)(0xc000302a60)}
 ******  ERROR : Get "chrome-extension://mhjfbmdgcfjbbpaeojofohoefgiehjai/pdf_viewer_wrapper.js": unsupported protocol scheme "chrome-extension"
rod.HijackResponse{payload:(*proto.FetchFulfillRequest)(0xc0002f6070), fail:(*proto.FetchFailRequest)(0xc0002b2320)}

In addition, when the router is hijacking, the download is not happeniing any more, whereas when no hijacking is installed, the manual downlod works perfectly on the rod chromium browser.

Obviously, the download seems to trigger a "pdf-viewer" extension, which in turn, does the actual download.

What you expected to see

I would expect :

What have you tried to solve the question

I tried :

Any hint on how I could capture, intercept and record what's happening, getting rid of that error ? Unfortunately, I cannot share the actual site which is private and requires my personnal login.

ysmood commented 1 year ago

395