Skip to content

XtermJs can use WebGL: SVG canvas capture returns blank #531

@theflyingape

Description

@theflyingape

This works using XtermJs (the terminal emulation library also used in VS Code) DOM renderer for compatibility; but their WebGL renderer is much more performant on today's hardware and browsers.

I left a note on this issue with their developers hoping for a clue or breakthrough:
xtermjs/xterm.js#5338 (comment)

Is there something special required to capture their WebGL canvas?

  <div class="bg-zinc-200 min-h-dvh h-dvh min-w-full w-full">
    <div class="flex flex-nowrap h-full w-full justify-center pt-2">
      <!-- monitor with a thin bezel -->
      <div ref="crt" class="bg-zinc-800 p-3 pb-8 rounded-md min-w-5/12 w-5/6 max-w-11/12 min-h-1/2 h-11/12 max-h-11/12 overflow-hidden resize resizer">
        <DevOnly><XtermJs v-show="value == 'localhost'" @vue:mounted="console.log('mounted!')" session="localhost" theme="White" :wsUrl="`${wsUrl}`" :fontSize=save.fontSize /></DevOnly>
        <XtermJs v-show="value == 'Dev'" @vue:mounted="" session="Dev" theme="White" :wsUrl="`${wsUrl}`" :fontSize=save.fontSize />
        <XtermJs v-show="value == 'Test'" @vue:mounted="" session="Test" theme="Green" :wsUrl="`${wsUrl}`" :fontSize=save.fontSize />
        <XtermJs v-show="value == 'Live'" @vue:mounted="" session="Live" theme="Amber" :wsUrl="`${wsUrl}`" :fontSize=save.fontSize />
...

function snap() {
// html2canvas(<HTMLDivElement>document.getElementById('monitor')).then((canvas) => {
  htmlToImage.toJpeg(<HTMLDivElement>get(crtRef)!.getElementsByClassName('xterm-screen')[0], { quality: 0.9 }).then((dataUrl:string) => {
    const link = document.createElement('a')
    link.download = `${get(value)}-crt-snap.jpg`
    link.href = dataUrl
    link.click()
  })  
}

I've tried every parent-child DIV off the element inspector, but had to settle for the DOM renderer.

  • html-to-image: latest 1.11.13
  • OS: latest Fedora 42, Windows 11, and ChromeOS
  • Browser: latest Chrome
  • latest Nuxt 3.17.3, UI Pro 3.1.2 with TailWind CSS 4.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions