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

Animated canvas is not rendered in the image #86

Open
oganm opened this issue Jul 8, 2019 · 4 comments
Open

Animated canvas is not rendered in the image #86

oganm opened this issue Jul 8, 2019 · 4 comments

Comments

@oganm
Copy link

oganm commented Jul 8, 2019

I have a small html file that creates a simple animation on canvas using a javascript library. However all I see with webshot is the empty canvas with the background color. I am unsure if webshot is supposed to capture animated frames but couldn't find a "known issues" section to see if this is within scope.

To replicate, download this file and do

webshot::webshot('hede.html')

After changing the file extension

Had to change the extension to paste the file to github. If you open it with a browser as an html file, you'll see the animation working

@oganm
Copy link
Author

oganm commented Jul 8, 2019

To make it simpler this file is an inanimate version, which also does not work.

@oganm
Copy link
Author

oganm commented Jul 10, 2019

The root of the issue seems to be phantomjs itself. Trying to see if any configuration of phantomjs can make this work

@wch
Copy link
Owner

wch commented Aug 7, 2019

This can be done with Chromote, using the screencastFrame command:

library(chromote)
b <- ChromoteSession$new(width = 240, height = 240)
frames <- list()
cancel_save_screencast_frames <- b$Page$screencastFrame(callback_ = function(value) {
  frames[[length(frames) + 1]] <<- value
  cat(".")
})

# You'll need to provide the correct file path
b$Page$navigate("file:///path/to/hede.html")

b$Page$startScreencast(format = "png", everyNthFrame = 1)

# Record for 5 seconds, then stop.
later(
  function() {
    b$Page$stopScreencast()
    cancel_save_screencast_frames()

    lapply(seq_along(frames), function(i) {
      writeBin(jsonlite::base64_dec(frames[[i]]$data), sprintf("frame%02d.png", i))  
    })
    b$close()
    message("done")
  },
  5
)

@oganm
Copy link
Author

oganm commented Aug 7, 2019

Oh this is the elsewhere you were talking about. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants