no-dom-access rule prevents usage of the document object and DOM APIs in UI extensions.
Rule details
UI extensions run in a sandboxed web worker environment where the DOM is intentionally unavailable. This architectural constraint ensures security and stability by preventing extensions from accessing sensitive host application data, modifying the main HubSpot interface, or interfering with other extensions. Thedocument object and DOM APIs don’t exist at runtime. Attempting to use them will cause runtime errors. Instead, build your UI entirely with React components and hooks from @hubspot/ui-extensions.
DOM alternatives
Use the following UI extension alternatives instead of DOM APIs:| DOM API | Alternative | Purpose |
|---|---|---|
document.querySelector() | UI components | Build interface with React components |
document.getElementById() | React refs | Reference elements within components |
document.body / document.title | Component props and state | Manage UI through React state |
element.innerHTML | JSX and UI components | Render content declaratively |
document.cookie | hubspot.fetch() + backend | Store data via backend APIs |
Examples
Querying elements
Instead of usingdocument.querySelector() or document.getElementById():
Element references
Instead of usingdocument.getElementById() in effects: