Skip to content

Commit

Permalink
Add chromedp.NoModifyURL compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
waybackarchiver committed Mar 18, 2023
1 parent 97c9e29 commit 0f0e551
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ require (
github.com/wabarc/rivet v0.1.4-0.20221226142645-ebc8a29d914f
github.com/wabarc/screenshot v1.6.1-0.20230315004517-7587f8bc14e0
github.com/wabarc/telegra.ph v0.0.0-20230318134541-a0922e1ace3a
github.com/wabarc/warcraft v0.3.1-0.20230308001245-81029e9c1365
github.com/wabarc/warcraft v0.3.1-0.20230308125707-3daa5592ba52
go.etcd.io/bbolt v1.3.6
golang.org/x/net v0.8.0
golang.org/x/sync v0.1.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -618,8 +618,8 @@ github.com/wabarc/screenshot v1.6.1-0.20230315004517-7587f8bc14e0 h1:H7Ufx43fg3k
github.com/wabarc/screenshot v1.6.1-0.20230315004517-7587f8bc14e0/go.mod h1:iQ6N8Myjc1XCR7Vh/1ihsWGZQY/vXAMneHwUmKRitxE=
github.com/wabarc/telegra.ph v0.0.0-20230318134541-a0922e1ace3a h1:W1gb0ww1oIARudOfXEMoXkZU1gqk0JERkIvVEgtuzq4=
github.com/wabarc/telegra.ph v0.0.0-20230318134541-a0922e1ace3a/go.mod h1:n+wNWjpzSvzIw8l5JbpeRzJqkOnSsXSgmI45635MUC4=
github.com/wabarc/warcraft v0.3.1-0.20230308001245-81029e9c1365 h1:iEmU6uKU/b0Y3Ow9hfpvHr1p4qRttFziw7tEZLr3ELc=
github.com/wabarc/warcraft v0.3.1-0.20230308001245-81029e9c1365/go.mod h1:/BbCwReBjlqHRaw8Yh+7sfAicOesiMYNhiFpuL1x8Rc=
github.com/wabarc/warcraft v0.3.1-0.20230308125707-3daa5592ba52 h1:ys1ltR7cKqATsLeqXBCp7kPCItIDxwyOjAFj0btH0wQ=
github.com/wabarc/warcraft v0.3.1-0.20230308125707-3daa5592ba52/go.mod h1:/BbCwReBjlqHRaw8Yh+7sfAicOesiMYNhiFpuL1x8Rc=
github.com/whyrusleeping/tar-utils v0.0.0-20180509141711-8c6c8ba81d5c/go.mod h1:xxcJeBb7SIUl/Wzkz1eVKJE/CB34YNrqX2TQI6jY9zs=
github.com/whyrusleeping/tar-utils v0.0.0-20201201191210-20a61371de5b h1:wA3QeTsaAXybLL2kb2cKhCAQTHgYTMwuI8lBlJSv5V8=
github.com/whyrusleeping/tar-utils v0.0.0-20201201191210-20a61371de5b/go.mod h1:xT1Y5p2JR2PfSZihE0s4mjdJaRGp1waCTf5JzhQLBck=
Expand Down
50 changes: 23 additions & 27 deletions reduxer/reduxer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"context"
"fmt"
"io"
"net"
"net/http"
"net/url"
"os"
Expand Down Expand Up @@ -251,39 +250,36 @@ func capture(ctx context.Context, cfg *config.Options, uri *url.URL, dir string)
screenshot.Quality(100), // image quality
}

if remote := remoteHeadless(cfg.ChromeRemoteAddr()); remote != nil {
logger.Debug("reduxer using remote browser")
addr := remote.(*net.TCPAddr)
browser, er := screenshot.NewChromeRemoteScreenshoter[screenshot.Path](addr.String())
if er != nil {
return shot, errors.Wrap(er, "dial screenshoter failed")
}
shot, err = browser.Screenshot(ctx, uri, opts...)
} else {
fallback := func() (*screenshot.Screenshots[screenshot.Path], error) {
logger.Debug("reduxer using local browser")
shot, err = screenshot.Screenshot[screenshot.Path](ctx, uri, opts...)
}
if err != nil {
if err == context.DeadlineExceeded {
return shot, errors.Wrap(err, "screenshot deadline")
if err != nil {
if err == context.DeadlineExceeded {
return shot, errors.Wrap(err, "screenshot deadline")
}
return shot, errors.Wrap(err, "screenshot error")
}
return shot, errors.Wrap(err, "screenshot error")
return shot, err
}

return shot, err
}

func remoteHeadless(addr string) net.Addr {
conn, err := net.DialTimeout("tcp", addr, time.Second)
if err != nil {
return nil
// Try to take a screenshot with a remote headless browser
// Fallback to local browser if remote is unavailable
if remote := cfg.ChromeRemoteAddr(); remote != "" {
logger.Debug("reduxer using remote browser")
browser, er := screenshot.NewChromeRemoteScreenshoter[screenshot.Path](remote)
if er != nil {
logger.Error("screenshot dial failed: %v", er)
return fallback()
}
shot, err = browser.Screenshot(ctx, uri, opts...)
if err != nil {
logger.Error("screenshot failed: %v", err)
return fallback()
}
return shot, nil
}

if conn != nil {
conn.Close()
return conn.RemoteAddr()
}
return nil
return fallback()
}

func createDir(baseDir string) (dir string, err error) {
Expand Down
1 change: 0 additions & 1 deletion service/slack/slack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"time"

"github.com/gorilla/websocket"
// "github.com/gorilla/websocket"
// "github.com/slack-go/slack/slackevents"
"github.com/slack-go/slack"
"github.com/slack-go/slack/slacktest"
Expand Down

0 comments on commit 0f0e551

Please sign in to comment.