| 28 | */ |
| 29 | @Injectable() |
| 30 | export class PlatformState { |
| 31 | /* @internal */ |
| 32 | _enableDomEmulation = enableDomEmulation(inject(Injector)); |
| 33 | |
| 34 | constructor(@Inject(DOCUMENT) private _doc: any) {} |
| 35 | |
| 36 | /** |
| 37 | * Renders the current state of the platform to string. |
| 38 | */ |
| 39 | renderToString(): string { |
| 40 | if (ngDevMode && !this._enableDomEmulation && !window?.document) { |
| 41 | throw new RuntimeError( |
| 42 | RuntimeErrorCode.DISABLED_DOM_EMULATION_IN_NON_BROWSER, |
| 43 | (typeof ngDevMode === 'undefined' || ngDevMode) && |
| 44 | 'Disabled DOM emulation should only run in browser environments', |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | const measuringLabel = 'renderToString'; |
| 49 | startMeasuring(measuringLabel); |
| 50 | const rendered = this._enableDomEmulation |
| 51 | ? serializeDocument(this._doc) |
| 52 | : // In the case we run/test the platform-server in a browser environment |
| 53 | this._doc.documentElement.outerHTML; |
| 54 | stopMeasuring(measuringLabel); |
| 55 | return rendered; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Returns the current DOM state. |
| 60 | */ |
| 61 | getDocument(): any { |
| 62 | return this._doc; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | export function enableDomEmulation(injector: Injector): boolean { |
| 67 | return injector.get(ENABLE_DOM_EMULATION, true); |
nothing calls this directly
no test coverage detected
searching dependent graphs…