msokk / electron-render-service

Microservice for rendering PDF/PNG/JPEG from HTML with Electron
MIT License
102 stars 28 forks source link

PNG / JPG capture glitches: timing issue? #25

Closed gwicke closed 7 years ago

gwicke commented 7 years ago

PNG and JPG renders often seem to be taken too early, before electron has finished rendering.

Examples, produced by repeating this request with different browserHeight / browserWidth values:

image

Some also only show a transparent background & a scrollbar: image

I experimented with triggering the call to capturePage in a ready-to-show event handler, or adding a static delay before this call. Neither eliminated the issue.

msokk commented 7 years ago

Hmm, I wonder if this has anything to do with the target file being rendered is SVG. Also I haven't tested directly rendering image files. Wrapping it in some HTML could help?

gwicke commented 7 years ago

Wrapping the image in HTML does indeed avoid the issue: https://pdf-electron.wmflabs.org/png?accessKey=secret&url=https://people.wikimedia.org/~gwicke/svg.html&browserHeight=102&browserWidth=102

This work-around should be good enough for our application.

msokk commented 7 years ago

Great, rendering is called when did-finish-load event triggers. I actually didn't notice the ready-to-show event in Electron docs, but looks like it is not much better than current event:

This is event is usually emitted after the did-finish-load event, but for pages with many remote resources, it may be emitted before the did-finish-load event.