Skip to content

Commit 171586d

Browse files
committed
document --> WINDOW.document
1 parent 413ee5a commit 171586d

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

packages/feedback/src/integration.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WINDOW } from '@sentry/browser';
12
import type { Integration } from '@sentry/types';
23
import { isBrowser } from '@sentry/utils';
34
import { logger } from '@sentry/utils';
@@ -46,6 +47,8 @@ function isBrowser(): boolean {
4647
type FeedbackConfiguration = Partial<FeedbackConfigurationWithDefaults>;
4748
>>>>>>> 5fa9a4abb (ref: extract widget creation to function, allow handling of multiple widgets)
4849

50+
const doc = WINDOW.document;
51+
4952
/**
5053
* Feedback integration. When added as an integration to the SDK, it will
5154
* inject a button in the bottom-right corner of the window that opens a
@@ -184,8 +187,7 @@ export class Feedback implements Integration {
184187
if (this._host) {
185188
this.remove();
186189
}
187-
// eslint-disable-next-line no-restricted-globals
188-
const existingFeedback = document.querySelector(`#${this.options.id}`);
190+
const existingFeedback = doc.querySelector(`#${this.options.id}`);
189191
if (existingFeedback) {
190192
existingFeedback.remove();
191193
}
@@ -200,7 +202,6 @@ export class Feedback implements Integration {
200202

201203
this._widget = this._createWidget(this.options);
202204
} catch (err) {
203-
// TODO: error handling
204205
logger.error(err);
205206
}
206207
}
@@ -214,8 +215,7 @@ export class Feedback implements Integration {
214215

215216
return this._ensureShadowHost<Widget | null>(options, ([shadow]) => {
216217
const targetEl =
217-
// eslint-disable-next-line no-restricted-globals
218-
typeof el === 'string' ? document.querySelector(el) : typeof el.addEventListener === 'function' ? el : null;
218+
typeof el === 'string' ? doc.querySelector(el) : typeof el.addEventListener === 'function' ? el : null;
219219

220220
if (!targetEl) {
221221
logger.error('[Feedback] Unable to attach to target element');
@@ -294,8 +294,7 @@ export class Feedback implements Integration {
294294
const widget = createWidget({ shadow, options });
295295

296296
if (!this._hasInsertedActorStyles && widget.actor) {
297-
// eslint-disable-next-line no-restricted-globals
298-
shadow.appendChild(createActorStyles(document));
297+
shadow.appendChild(createActorStyles(doc));
299298
this._hasInsertedActorStyles = true;
300299
}
301300

@@ -333,8 +332,7 @@ export class Feedback implements Integration {
333332
const result = cb([this._shadow, this._host]);
334333

335334
if (needsAppendHost) {
336-
// eslint-disable-next-line no-restricted-globals
337-
document.body.appendChild(this._host);
335+
doc.body.appendChild(this._host);
338336
}
339337

340338
return result;

packages/feedback/src/widget/Icon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WINDOW } from '@sentry/browser';
12
import { setAttributesNS } from '../util/setAttributesNS';
23

34
const SIZE = 20;
@@ -12,8 +13,7 @@ interface IconReturn {
1213
*/
1314
export function Icon(): IconReturn {
1415
const cENS = <K extends keyof SVGElementTagNameMap>(tagName: K): SVGElementTagNameMap[K] =>
15-
// eslint-disable-next-line no-restricted-globals
16-
document.createElementNS(XMLNS, tagName);
16+
WINDOW.document.createElementNS(XMLNS, tagName);
1717
const svg = setAttributesNS(cENS('svg'), {
1818
class: 'feedback-icon',
1919
width: `${SIZE}`,

packages/feedback/src/widget/SuccessIcon.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WINDOW } from '@sentry/browser';
12
import { setAttributesNS } from '../util/setAttributesNS';
23

34
const WIDTH = 16;
@@ -13,8 +14,7 @@ interface IconReturn {
1314
*/
1415
export function SuccessIcon(): IconReturn {
1516
const cENS = <K extends keyof SVGElementTagNameMap>(tagName: K): SVGElementTagNameMap[K] =>
16-
// eslint-disable-next-line no-restricted-globals
17-
document.createElementNS(XMLNS, tagName);
17+
WINDOW.document.createElementNS(XMLNS, tagName);
1818
const svg = setAttributesNS(cENS('svg'), {
1919
class: 'success-icon',
2020
width: `${WIDTH}`,

packages/feedback/src/widget/createShadowHost.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { WINDOW } from '@sentry/browser';
12
import { logger } from '@sentry/utils';
23

34
import type { FeedbackConfigurationWithDefaults } from '../types';
@@ -7,12 +8,13 @@ import { createMainStyles } from './Main.css';
78
interface CreateShadowHostParams {
89
options: FeedbackConfigurationWithDefaults;
910
}
11+
1012
/**
11-
*
13+
* Creates shadow host
1214
*/
1315
export function createShadowHost({ options }: CreateShadowHostParams): [shadow: ShadowRoot, host: HTMLDivElement] {
14-
// eslint-disable-next-line no-restricted-globals
15-
const doc = document;
16+
const doc = WINDOW.document;
17+
1618
if (!doc.head.attachShadow) {
1719
// Shadow DOM not supported
1820
logger.warn('[Feedback] Browser does not support shadow DOM API');

packages/feedback/src/widget/util/createElement.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { WINDOW } from '@sentry/browser';
2+
13
/**
24
* Helper function to create an element. Could be used as a JSX factory
35
* (i.e. React-like syntax).
@@ -7,8 +9,8 @@ export function createElement<K extends keyof HTMLElementTagNameMap>(
79
attributes: { [key: string]: string | boolean | EventListenerOrEventListenerObject } | null,
810
...children: any
911
): HTMLElementTagNameMap[K] {
10-
// eslint-disable-next-line no-restricted-globals
11-
const element = document.createElement(tagName);
12+
const doc = WINDOW.document;
13+
const element = doc.createElement(tagName);
1214

1315
if (attributes) {
1416
Object.entries(attributes).forEach(([attribute, attributeValue]) => {
@@ -32,6 +34,7 @@ export function createElement<K extends keyof HTMLElementTagNameMap>(
3234
}
3335

3436
function appendChild(parent: Node, child: any): void {
37+
const doc = WINDOW.document;
3538
if (typeof child === 'undefined' || child === null) {
3639
return;
3740
}
@@ -43,12 +46,10 @@ function appendChild(parent: Node, child: any): void {
4346
} else if (child === false) {
4447
// do nothing if child evaluated to false
4548
} else if (typeof child === 'string') {
46-
// eslint-disable-next-line no-restricted-globals
47-
parent.appendChild(document.createTextNode(child));
49+
parent.appendChild(doc.createTextNode(child));
4850
} else if (child instanceof Node) {
4951
parent.appendChild(child);
5052
} else {
51-
// eslint-disable-next-line no-restricted-globals
52-
parent.appendChild(document.createTextNode(String(child)));
53+
parent.appendChild(doc.createTextNode(String(child)));
5354
}
5455
}

0 commit comments

Comments
 (0)