Skip to content

WebGL renderer doesn't work in a shadow dom #5338

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

Open
CGNonofr opened this issue May 13, 2025 · 10 comments · May be fixed by #5334
Open

WebGL renderer doesn't work in a shadow dom #5338

CGNonofr opened this issue May 13, 2025 · 10 comments · May be fixed by #5334

Comments

@CGNonofr
Copy link

Details

  • Browser and browser version: any
  • OS version: any
  • xterm.js version: @xterm/[email protected]

Steps to reproduce

  1. Create a terminal inside a shadow dom with the webgl addon
  2. The terminal is broken/empty
@CGNonofr CGNonofr linked a pull request May 13, 2025 that will close this issue
@theflyingape
Copy link
Contributor

theflyingape commented May 15, 2025

I don't claim to understand this fix and please excuse if this is an entirely separate issue (for me), but would this have any impact on external libs that allow for making an image off a DOM element, i.e., html-to-image? I ask because I don't understand why disabling WebGL allows for this lib to just work, while when WebGL renderer is enabled, it captures a black canvas.

A code snippet follows to help clarify:

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

... whereas the crtRef points to the <div ref="crt"> element encapsulating the XtermJs "terminal" container. And I've tried from the parent to each child element below with (essentially) the same results.

@jerch
Copy link
Member

jerch commented May 15, 2025

@CGNonofr Can you plz provide a minimal repro example? This way we have a common error ground, from where we can investigate.

@theflyingape No clue if it is related, but my first guess for your issue would be, that html-to-image does not correctly pull the webgl canvas content into its intermediate SVG.

@theflyingape
Copy link
Contributor

@jerch perhaps another addon to capure DOM or SVG is in order? 😉

@CGNonofr
Copy link
Author

I can probably a minimal repo exemple, but the suggested fix seems obvious enough to me to understand the issue that was already fixed somewhere else in the code in the past

I'll provide a repo when I'll be able to

@jerch
Copy link
Member

jerch commented May 18, 2025

@CGNonofr
Sorry, nothing of what you wrote makes any sense to me. Which suggested fix? When and where in which code?

Gonna close the issue, feel free to re-open, if something is left unanswered (preferably a discussion/question, unless it is clearly a bug of xterm.js).

@jerch jerch closed this as completed May 18, 2025
@CGNonofr
Copy link
Author

I've attached a PR to the issue, why are you closing it ??

@jerch
Copy link
Member

jerch commented May 19, 2025

Oh sorry, didnt see that until now. Reopened the issue.

@jerch jerch reopened this May 19, 2025
@CGNonofr
Copy link
Author

Is the reproduction repo still required? Is there anything I can do to help moving forward on this?

@jerch
Copy link
Member

jerch commented May 20, 2025

Yes a minimal repro would still be good, as we otherwise have no way to test it all.

In general we try to be test-driven to some degree, so ideally we have things tested automatically in CI. But this seems rather cumbersome for this case here, so a minimal repro for a manual test is good enough imho and would document at least one setup, that it is supposed to fix.

@CGNonofr
Copy link
Author

CGNonofr commented May 20, 2025

I was actually able to add a shadow dom test, see the attached PR

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

Successfully merging a pull request may close this issue.

3 participants