How to save Viewer Pane as image through command line? : <p>Let's say I have the following HTML viewed in the Viewer Pane</p>

<pre><code>tempDir &lt;- tempfile()
dir.create(tempDir)
htmlFile &lt;- file.path(tempDir, "index.html")
write('&lt;h1&gt; Content&lt;/h1&gt;', htmlFile, append = TRUE)
write('&lt;h2&gt; Content&lt;/h2&gt;', htmlFile, append = TRUE)
write('lorem ipsum...', htmlFile, append = TRUE)
viewer &lt;- getOption("viewer")
viewer(htmlFile)
</code></pre>

<p>When I have this html in the Viewer Pane, I can click on the "Save as image" button:</p>

<p><a href="https://i.stack.imgur.com/ZzyKr.png" rel="noreferrer"><img src="https://i.stack.imgur.com/ZzyKr.png" alt="enter image description here"></a></p>

<p>And I have the html content as a png, for example : </p>

<p><a href="https://i.stack.imgur.com/SwyhO.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SwyhO.png" alt="enter image description here"></a></p>

<p>Is there a way to do this with the command line? I know about <code>rstudioapi::savePlotAsImage()</code>, so I'm looking for a kind of <code>saveViewerAsImage</code>. </p>

<p><strong>Edit</strong>: I know we can do this with the {webshot} package, but I'm looking for the RStudio function that does that. </p>
