-
Notifications
You must be signed in to change notification settings - Fork 770
/
window-initialize.ts
62 lines (56 loc) · 1.49 KB
/
window-initialize.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type * as d from '../../declarations';
import { constrainTimeouts } from '@stencil/core/mock-doc';
import { renderCatchError } from './render-utils';
import { runtimeLogging } from './runtime-log';
export function initializeWindow(
win: Window & typeof globalThis,
doc: Document,
opts: d.HydrateDocumentOptions,
results: d.HydrateResults
) {
try {
win.location.href = opts.url;
} catch (e) {
renderCatchError(results, e);
}
if (typeof opts.userAgent === 'string') {
try {
(win.navigator as any).userAgent = opts.userAgent;
} catch (e) {}
}
if (typeof opts.cookie === 'string') {
try {
doc.cookie = opts.cookie;
} catch (e) {}
}
if (typeof opts.referrer === 'string') {
try {
(doc as any).referrer = opts.referrer;
} catch (e) {}
}
if (typeof opts.direction === 'string') {
try {
doc.documentElement.setAttribute('dir', opts.direction);
} catch (e) {}
}
if (typeof opts.language === 'string') {
try {
doc.documentElement.setAttribute('lang', opts.language);
} catch (e) {}
}
if (typeof opts.buildId === 'string') {
try {
doc.documentElement.setAttribute('data-stencil-build', opts.buildId);
} catch (e) {}
}
try {
// TODO(STENCIL-345) - Evaluate reconciling MockWindow, Window differences
// @ts-ignore
win.customElements = null;
} catch (e) {}
if (opts.constrainTimeouts) {
constrainTimeouts(win);
}
runtimeLogging(win, opts, results);
return win;
}