From a77e30e43fdca6caafe18c648d632496fd38eca0 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Wed, 11 Oct 2023 19:53:56 +0200 Subject: Fix jsonprint output in dev mode --- js.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'js.go') diff --git a/js.go b/js.go index 7e1f7c0..e972453 100644 --- a/js.go +++ b/js.go @@ -9,10 +9,12 @@ import ( "errors" "fmt" "math/rand" + "os" "strings" "github.com/evanw/esbuild/pkg/api" "github.com/philippta/flyscrape/js" + "go.kuoruan.net/v8go-polyfills/console" v8 "rogchap.com/v8go" ) @@ -67,6 +69,11 @@ func build(src string) (string, error) { func vm(src string) (Config, ScrapeFunc, error) { ctx := v8.NewContext() + + if err := console.InjectTo(ctx, console.WithOutput(os.Stderr)); err != nil { + return nil, nil, fmt.Errorf("injecting console: %w", err) + } + ctx.RunScript("var module = {}", "main.js") if _, err := ctx.RunScript(removeIIFE(js.Flyscrape), "main.js"); err != nil { -- cgit v1.2.3