Add support for the parent element (what is passed to Terminal.open) being in a different (same origin) window. Accesses to DOM APIs such as requestAnimationFrame and devicePixelRatio thus need to be scoped to the corrent window, instead of assuming that it's the same as the window/global scope where the code is running. This is done by inferring a parent window at the creation time, and then storing it in CoreBrowserService, which is already passed to most places that need it. To catch future regressions, an ESLint rule that checks for global accesses is added (it uses AST selectors via the no-restricted-syntax rule). This should also be applicable when the parent element is an iframe. Fixes #3758
26 lines
730 B
TypeScript
26 lines
730 B
TypeScript
/**
|
|
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
|
* @license MIT
|
|
*/
|
|
|
|
import { ICoreBrowserService } from './Services';
|
|
|
|
export class CoreBrowserService implements ICoreBrowserService {
|
|
public serviceBrand: undefined;
|
|
|
|
constructor(
|
|
private _textarea: HTMLTextAreaElement,
|
|
public readonly window: Window & typeof globalThis
|
|
) {
|
|
}
|
|
|
|
public get dpr(): number {
|
|
return this.window.devicePixelRatio;
|
|
}
|
|
|
|
public get isFocused(): boolean {
|
|
const docOrShadowRoot = this._textarea.getRootNode ? this._textarea.getRootNode() as Document | ShadowRoot : this._textarea.ownerDocument;
|
|
return docOrShadowRoot.activeElement === this._textarea && this._textarea.ownerDocument.hasFocus();
|
|
}
|
|
}
|