no-restricted-globals rule prevents usage of browser globals that are not available in the sandboxed web worker environment.
Rule details
This rule blocks usage of the following globals:importScripts(): a worker function that doesn’t work in the UI extensions environment.addEventListener()/removeEventListener(): global event listeners don’t work for DOM events.location: not available in workers.history: not available in workers.
| Restricted Global | Alternative | Purpose |
|---|---|---|
importScripts('script.js') | import { module } from './script.js' | Use ES modules instead. |
addEventListener('click', handler) | <Button onClick={handler}> | Use React component event props. |
location | context | Access location information through context. |
history | <Link> or actions.openIframeModal() | Navigate using the Link component or actions. |
Examples
importScripts()
Instead of usingimportScripts():
Event listeners
Instead of using global event listeners:location and history
Instead of accessinglocation or history:
context for location information:
actions and <Link> for navigation: