From a695a33c239e282c77ba69729947c26308364493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Tue, 23 Sep 2025 18:31:41 +0200 Subject: [PATCH 1/2] fix: fix computed style computation on firefox inside a shadow dom getComputedStyle should be called on the right window element --- src/browser/input/Mouse.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/browser/input/Mouse.ts b/src/browser/input/Mouse.ts index c40a7cc782..da7eca35c2 100644 --- a/src/browser/input/Mouse.ts +++ b/src/browser/input/Mouse.ts @@ -1,3 +1,5 @@ +import * as dom from 'vs/base/browser/dom'; + /** * Copyright (c) 2017 The xterm.js authors. All rights reserved. * @license MIT @@ -5,7 +7,7 @@ export function getCoordsRelativeToElement(window: Pick, event: {clientX: number, clientY: number}, element: HTMLElement): [number, number] { const rect = element.getBoundingClientRect(); - const elementStyle = window.getComputedStyle(element); + const elementStyle = dom.getComputedStyle(element); const leftPadding = parseInt(elementStyle.getPropertyValue('padding-left')); const topPadding = parseInt(elementStyle.getPropertyValue('padding-top')); return [ From 0675b6f8f2f1c6f7be95bb5993068a927093a672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Mangeonjean?= Date: Tue, 23 Sep 2025 18:32:05 +0200 Subject: [PATCH 2/2] fix(fit-addon): call getComputedStyle on the right window element --- addons/addon-fit/src/FitAddon.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/addons/addon-fit/src/FitAddon.ts b/addons/addon-fit/src/FitAddon.ts index a282ed3f8c..2cc8485789 100644 --- a/addons/addon-fit/src/FitAddon.ts +++ b/addons/addon-fit/src/FitAddon.ts @@ -23,6 +23,17 @@ interface ITerminalDimensions { const MINIMUM_COLS = 2; const MINIMUM_ROWS = 1; +function getWindow(e: Node): Window { + if (e?.ownerDocument?.defaultView) { + return e.ownerDocument.defaultView.window; + } + + return window; +} +function getComputedStyle(el: HTMLElement): CSSStyleDeclaration { + return getWindow(el).getComputedStyle(el, null); +} + export class FitAddon implements ITerminalAddon , IFitApi { private _terminal: Terminal | undefined; @@ -69,10 +80,10 @@ export class FitAddon implements ITerminalAddon , IFitApi { ? 0 : (this._terminal.options.overviewRuler?.width || ViewportConstants.DEFAULT_SCROLL_BAR_WIDTH)); - const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement); + const parentElementStyle = getComputedStyle(this._terminal.element.parentElement); const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')); const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width'))); - const elementStyle = window.getComputedStyle(this._terminal.element); + const elementStyle = getComputedStyle(this._terminal.element); const elementPadding = { top: parseInt(elementStyle.getPropertyValue('padding-top')), bottom: parseInt(elementStyle.getPropertyValue('padding-bottom')),