From c36bb2ca2a82338a822c6962f3373809b4bed814 Mon Sep 17 00:00:00 2001 From: Philipp Tanlak Date: Wed, 16 Aug 2023 19:58:10 +0200 Subject: add allowed domains feature --- js.go | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'js.go') diff --git a/js.go b/js.go index 526f27b..242f15f 100644 --- a/js.go +++ b/js.go @@ -58,18 +58,13 @@ func vm(src string) (ScrapeOptions, ScrapeFunc, error) { } var opts ScrapeOptions - - url, err := ctx.RunScript("options.url", "main.js") + optsJSON, err := ctx.RunScript("JSON.stringify(options)", "main.js") if err != nil { - return ScrapeOptions{}, nil, fmt.Errorf("reading options.url: %w", err) + return ScrapeOptions{}, nil, fmt.Errorf("reading options: %w", err) } - opts.URL = url.String() - - depth, err := ctx.RunScript("options.depth", "main.js") - if err != nil { - return ScrapeOptions{}, nil, fmt.Errorf("reading options.depth: %w", err) + if err := json.Unmarshal([]byte(optsJSON.String()), &opts); err != nil { + return ScrapeOptions{}, nil, fmt.Errorf("decoding options json: %w", err) } - opts.Depth = int(depth.Integer()) scrape := func(params ScrapeParams) (any, error) { suffix := randSeq(10) -- cgit v1.2.3