vmware-tanzu-labs / educates-training-platform

A platform for hosting interactive workshop environments in Kubernetes, or on top of a local container runtime.
https://docs.educates.dev
Apache License 2.0
72 stars 18 forks source link

Clicking on links in dashboard terminal always opens a blank page. #374

Closed GrahamDumpleton closed 4 months ago

GrahamDumpleton commented 4 months ago

Describe the bug

Once upon a time you could click on a URL link in the dashboard terminal and it would open a new browser window on that URL. This is no longer working and it always opens a blank page in the new browser page.

Additional information

No response

jorgemoralespou commented 4 months ago

We should try to see why this happens as it's annoying.

GrahamDumpleton commented 4 months ago

It cannot be fixed as is because xterm.js changed how they launched new browser windows and it now no longer works when embedded in an iframe as a result.

Options are:

GrahamDumpleton commented 4 months ago

Fix turns out to be quite simple. Provided have latest xterm.js can do:

        function handleLinkClick(event: MouseEvent, uri: string): void {
            window.open(uri, '_blank');
        }

        this.terminal.loadAddon(new WebLinksAddon(handleLinkClick))

This is how it did it a long time ago.

It was changed to:

function handleLink(event: MouseEvent, uri: string): void {
  const newWindow = window.open();
  if (newWindow) {
    try {
      newWindow.opener = null;
    } catch {
      // no-op, Electron can throw
    }
    newWindow.location.href = uri;
  } else {
    console.warn('Opening link blocked as opener could not be cleared');
  }
}

The problem is that newWindow.location.href = uri; is blocked when target updated after the fact.

When done as part of window open all is fine.