# utils/dom/isshadowroot

module

<a id="functions">

## Functions

<a id="function-isNativeShadowRoot">

### `isNativeShadowRoot( obj ) → obj is ShadowRoot` _(internal)_

Checks whether the given object is a shadow root the platform itself accepts.

A page may run a shadow DOM polyfill that emulates the boundary in the light DOM instead of asking the engine for one – a _synthetic_ shadow root. Such a root passes [`isShadowRoot`](#function-isShadowRoot), because the polyfill replaces the global `ShadowRoot` with its own constructor and patches `Symbol.hasInstance` on it. It emulates the tree faithfully enough for traversal (`host`, `parentNode`, `contains`, `activeElement` all behave), which is why [`isShadowRoot`](#function-isShadowRoot) stays truthful about it, but being no platform object it cannot be:

* passed to a DOM API expecting a real root – `Selection#getComposedRanges()` and `Document#caretPositionFromPoint()` reject it while converting their arguments;
* asked for its selection or stylesheets – those are the members a polyfill cannot emulate, so it usually makes them throw;
* used as a mount target – its `appendChild()` delegates to the host element, so the node ends up in the surrounding tree rather than at the top of the one it was mounted in.

Use it wherever a root crosses into one of those, and [`isShadowRoot`](#function-isShadowRoot) everywhere else. Answering `false` here falls back to the light-DOM path, which is the correct answer for a synthetic root: the boundary it emulates is not one the engine actually has, so the document-level APIs already see the real nodes behind it.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/dom/isshadowroot.ts#L57)

#### Parameters

* `obj: unknown`

  The object to check.

#### Returns

* `obj is ShadowRoot`

<a id="function-isShadowRoot">

### `isShadowRoot( obj ) → obj is ShadowRoot`

Checks whether the given object is a native DOM `ShadowRoot`.

A type guard, safe to call on any value, and correct for a root belonging to another document or iframe.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-utils/src/dom/isshadowroot.ts#L17)

#### Parameters

* `obj: unknown`

  The object to check.

#### Returns

* `obj is ShadowRoot`

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
