summaryrefslogtreecommitdiff
path: root/js.go
diff options
context:
space:
mode:
authorPhilipp Tanlak <philipp.tanlak@gmail.com>2023-08-16 19:58:10 +0200
committerPhilipp Tanlak <philipp.tanlak@gmail.com>2023-08-16 19:58:10 +0200
commitc36bb2ca2a82338a822c6962f3373809b4bed814 (patch)
treed6cb54b7e9d7bf5742b06dedd6bf76eb09ea8385 /js.go
parentd82e66800478219dd924c6969bd91dbfe004fc9d (diff)
add allowed domains feature
Diffstat (limited to 'js.go')
-rw-r--r--js.go13
1 files changed, 4 insertions, 9 deletions
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)