Skip to content

Commit

Permalink
Add information about resizing window
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Nov 2, 2023
1 parent aef4d49 commit e21c70c
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,31 @@ b$screenshot("s3.png", selector = ".page", region = "margin", scale = 2)
If a vector is passed to `selector`, it will take a screenshot with a rectangle that encompasses all the DOM elements picked out by the selectors. Similarly, if a selector picks out multiple DOM elements, all of them will be in the screenshot region.


### Setting width and height of the viewport (window)

The default size of a `ChromoteSession` viewport is 992 by 1323 pixels. You can set the width and height when it is created:

```R
b <- ChromoteSession$new(width = 390, height = 844)

b$Page$navigate("https://www.r-project.org/")
b$screenshot("narrow.png")
```

With an existing `ChromoteSession`, you can set the size with `b$Emulation$setVisibleSize()`:

```R
b$Emulation$setVisibleSize(width=1600, height=900)
b$screenshot("wide.png")
```

You can take a "Retina" (double) resolution screenshot by using `b$screenshot(scale=2)`:

```R
b$screenshot("wide-2x.png", scale = 2)
```


### Taking a screenshot of a web page after interacting with it

Headless Chrome provides a remote debugging UI which you can use to interact with the web page. The ChromoteSession's `$view()` method opens a regular browser and navigates to the remote debugging UI.
Expand Down
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1227,6 +1227,33 @@ rectangle that encompasses all the DOM elements picked out by the
selectors. Similarly, if a selector picks out multiple DOM elements, all
of them will be in the screenshot region.

### Setting width and height of the viewport (window)

The default size of a `ChromoteSession` viewport is 992 by 1323 pixels.
You can set the width and height when it is created:

``` r
b <- ChromoteSession$new(width = 390, height = 844)

b$Page$navigate("https://www.r-project.org/")
b$screenshot("narrow.png")
```

With an existing `ChromoteSession`, you can set the size with
`b$Emulation$setVisibleSize()`:

``` r
b$Emulation$setVisibleSize(width=1600, height=900)
b$screenshot("wide.png")
```

You can take a “Retina” (double) resolution screenshot by using
`b$screenshot(scale=2)`:

``` r
b$screenshot("wide-2x.png", scale = 2)
```

### Taking a screenshot of a web page after interacting with it

Headless Chrome provides a remote debugging UI which you can use to
Expand Down

0 comments on commit e21c70c

Please sign in to comment.