diff --git a/wrp.go b/wrp.go index 956762a..196b3cb 100644 --- a/wrp.go +++ b/wrp.go @@ -21,6 +21,7 @@ import ( "net/url" "os" "strconv" + "strings" "time" "github.com/chromedp/cdproto/emulation" @@ -56,7 +57,7 @@ func pageServer(out http.ResponseWriter, r *http.Request) { log.Printf("%s Page Reqest for url=\"%s\" [%s]\n", r.RemoteAddr, u, r.URL.Path) out.Header().Set("Content-Type", "text/html") fmt.Fprintf(out, "\n
") if len(u) > 4 { - capture(u, w, h, s, y, out) + if strings.HasPrefix(u, "http") { + capture(u, w, h, s, y, out) + } else { + capture(fmt.Sprintf("http://www.google.com/search?q=%s", url.QueryEscape(u)), w, h, s, y, out) + } } else { - fmt.Fprintf(out, "No URL specified") + fmt.Fprintf(out, "No URL or search query specified") } fmt.Fprintf(out, "\n\n") } @@ -101,11 +106,10 @@ func capture(gourl string, w int64, h int64, s float64, y int64, out http.Respon log.Printf("Processing Caputure Request for %s\n", gourl) // Run ChromeDP Magic - scrl := fmt.Sprintf("window.scrollTo(0, %d);", y) chromedp.Run(ctx, emulation.SetDeviceMetricsOverride(w, h, s, false), chromedp.Navigate(gourl), - chromedp.Evaluate(scrl, &res), + chromedp.Evaluate(fmt.Sprintf("window.scrollTo(0, %d);", y), &res), chromedp.Sleep(time.Second*1), chromedp.CaptureScreenshot(&pngbuf), chromedp.Location(&loc),