From 1ef21c6ed69994559b5383f40d3f3dc44f6e972d Mon Sep 17 00:00:00 2001 From: Julien Neuhart Date: Wed, 12 Dec 2018 12:20:07 +0100 Subject: [PATCH] RPC error (#23) --- .travis.yml | 6 ++++-- internal/pkg/pm2/chrome.go | 5 +++-- internal/pkg/printer/html.go | 7 ++++--- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 05db359c..f70e2bb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,13 +11,15 @@ env: - secure: CmLh169xwt3OC7l19lDUwdZYfw+l/+XXKjTGxnuJiXHa9hAH+nc4mEUSmqHMHwjquyYE6LnSVGZ94LH8sCaGed/TMm0Lj3DZtZ0VsjYu3sKsNrVJn5WdYEah+GvNJ8i8uzvHnGk1L2fAagLpXFUB2K9UraA1CFiHs1fF5Fua7Ra0mE7lMz0MFvyvzcmc9u8nMz71K2YVsXqn+I/rv8onJCTtc/Ds0hVrBXwG5Fh0T3xHqjOhME9ZI2hRHnnQVdBojSY3USifQ//qAKowfBVc0pebEtgFpyXx/I17A6xCm0KVtnA2tNqu1+XFkjWaBzryaLE9ujhJcTRC/YK0JUZ+QxfYbD5C7jVy9Jlx1lOEjJ42B/ImNxPP+9p3wi2MWNbcbZJPxIe635fnT17lI7CLK2Qg1xjfTQ4WTEKW5IhnYMiyfRKiripFh4PCkDm8cJlTbpntsX1n0uheydbsgf/11vS7o1WGhVQ8+Jelc4DvIbBHCqienQEOLJDBwm7FiK5JbwZJ6ZAGeDM/IhGU1h9PNjVbHUyJhUxYoPYUE9QsZFT7ENCrRQpq49KOzXBRfffyJNJRh+Ep9X5YoW0dUp0MNu5B7z2+6w9X9n/C+loa11xF42bFzniCvvbSOQ37J+EngDinVxJkNPeyivR4fye2ENhIAjAEjouTJLOSXL9nAOU= stages: - - lint + - tests - publish jobs: include: - - stage: lint + - stage: tests script: make lint + - stage: tests + script: make tests - stage: publish if: tag IS present script: ./scripts/publish.sh $TRAVIS_TAG $DOCKER_USER $DOCKER_PASS \ No newline at end of file diff --git a/internal/pkg/pm2/chrome.go b/internal/pkg/pm2/chrome.go index 42090f6c..12d11d1d 100644 --- a/internal/pkg/pm2/chrome.go +++ b/internal/pkg/pm2/chrome.go @@ -54,8 +54,9 @@ func (c *Chrome) getFullname() string { func (c *Chrome) isViable() bool { // check if Chrome is correctly running. - devt := devtool.New("http://127.0.0.1:9222") - _, err := devt.Create(context.TODO()) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + _, err := devtool.New("http://localhost:9222").Version(ctx) return err == nil } diff --git a/internal/pkg/printer/html.go b/internal/pkg/printer/html.go index 8cda9378..5d641888 100644 --- a/internal/pkg/printer/html.go +++ b/internal/pkg/printer/html.go @@ -36,14 +36,15 @@ const defaultHeaderFooterHTML string = "" // Print converts HTML to PDF. // Credits: https://medium.com/compass-true-north/go-service-to-convert-web-pages-to-pdf-using-headless-chrome-5fd9ffbae1af func (html *HTML) Print(destination string) error { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() // use the DevTools HTTP/JSON API to manage targets (e.g. pages, webworkers). - devt := devtool.New("http://127.0.0.1:9222") - pt, err := devt.Create(html.Context) + devt, err := devtool.New("http://localhost:9222").Version(ctx) if err != nil { return fmt.Errorf("creating DevTools target: %v", err) } // open a new RPC connection to the Chrome Debugging Protocol target. - conn, err := rpcc.DialContext(html.Context, pt.WebSocketDebuggerURL) + conn, err := rpcc.DialContext(html.Context, devt.WebSocketDebuggerURL) if err != nil { return fmt.Errorf("creating RPC connection: %v", err) }