Skip to content

Commit

Permalink
remove response body code from Example_retrieveHTML
Browse files Browse the repository at this point in the history
We'll add a higher level API for this in #370. For now, just leave it
with OuterHTML.
  • Loading branch information
mvdan committed Jun 10, 2019
1 parent e657155 commit 5b47e1d
Showing 1 changed file with 0 additions and 34 deletions.
34 changes: 0 additions & 34 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"path/filepath"
"strings"

"github.com/chromedp/cdproto/network"
"github.com/chromedp/cdproto/page"
cdpruntime "github.com/chromedp/cdproto/runtime"
"github.com/chromedp/cdproto/target"
Expand Down Expand Up @@ -243,54 +242,21 @@ function changeText() {
`))
defer ts.Close()

respBody := make(chan string)
chromedp.ListenTarget(ctx, func(ev interface{}) {
ev2, ok := ev.(*network.EventResponseReceived)
if !ok {
return
}
go func() {
if err := chromedp.Run(ctx, chromedp.ActionFunc(func(ctx context.Context) error {
body, err := network.GetResponseBody(ev2.RequestID).Do(ctx)
respBody <- string(body)
return err
})); err != nil {
panic(err)
}
}()
})

var outerBefore, outerAfter string
if err := chromedp.Run(ctx,
network.Enable(),
chromedp.Navigate(ts.URL),
chromedp.OuterHTML("#content", &outerBefore),
chromedp.Click("#content", chromedp.ByID),
chromedp.OuterHTML("#content", &outerAfter),
); err != nil {
panic(err)
}
fmt.Println("Original response body:")
fmt.Println(<-respBody)
fmt.Println()
fmt.Println("OuterHTML before clicking:")
fmt.Println(outerBefore)
fmt.Println("OuterHTML after clicking:")
fmt.Println(outerAfter)

// TODO: reenable once we fix the race with EventResponseReceived. The
// code needs to wait for EventLoadingFinished.
// Output:
// Original response body:
// <body>
// <p id="content" onclick="changeText()">Original content.</p>
// <script>
// function changeText() {
// document.getElementById("content").textContent = "New content!"
// }
// </script>
// </body>
//
// OuterHTML before clicking:
// <p id="content" onclick="changeText()">Original content.</p>
// OuterHTML after clicking:
Expand Down

0 comments on commit 5b47e1d

Please sign in to comment.