Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add screenshot for take screenshot of page. #267

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ RUN make build
FROM debian:bullseye-slim

RUN apt-get update \
&& apt-get install -y fonts-noto-cjk \
&& apt-get install -y chromium \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,16 @@ actions:
- outerHTML: 'h1'
```

**`screenshot`** (aliases: `getScreenshot`)

Take a full screenshot of the entire browser viewport.

```yaml
actions:
- screenshot:
# record to current.png:
```

**`sendKeys`**

Send keys (`value`) to the first element node matching the selector (`sel`).
Expand Down
8 changes: 8 additions & 0 deletions cdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (rnr *cdpRunner) Run(_ context.Context, cas CDPActions) error {
res[arg.Key] = *vv
case *map[string]string:
res[arg.Key] = *vv
case *[]byte:
res[arg.Key] = *vv
default:
res[arg.Key] = vv
}
Expand All @@ -117,6 +119,8 @@ func (rnr *cdpRunner) Run(_ context.Context, cas CDPActions) error {
r[k] = *vv
case *map[string]string:
r[k] = *vv
case *[]byte:
r[k] = *vv
default:
r[k] = vv
}
Expand Down Expand Up @@ -155,6 +159,10 @@ func (rnr *cdpRunner) evalAction(ca CDPAction) (chromedp.Action, error) {
v := map[string]string{}
rnr.store[k] = &v
vs = append(vs, reflect.ValueOf(&v))
case reflect.Slice:
var v []byte
rnr.store[k] = &v
vs = append(vs, reflect.ValueOf(&v))
default:
return nil, fmt.Errorf("invalid action: %v", ca)
}
Expand Down
10 changes: 10 additions & 0 deletions cdpfn.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,16 @@ var CDPFnMap = map[string]CDPFn{
},
Aliases: []string{"getAttributes", "attrs", "getAttrs"},
},
"screenshot": {
Desc: "Take a full screenshot of the entire browser viewport.",
Fn: func(b *[]byte) chromedp.Action {
return chromedp.FullScreenshot(b, 100)
},
Args: CDPFnArgs{
{CDPArgTypeRes, "png", "[]byte"},
},
Aliases: []string{"getScreenshot"},
},
"evaluate": {
Desc: "Evaluate the Javascript expression (`expr`).",
Fn: func(expr string) chromedp.Action {
Expand Down