@react-ui-org/react-ui 0.64.1 → 0.66.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/README.md +3 -6
  2. package/dist/react-ui.css +16 -16
  3. package/dist/react-ui.d.ts +1936 -0
  4. package/dist/react-ui.development.css +3591 -3003
  5. package/dist/react-ui.development.js +2028 -1060
  6. package/dist/react-ui.js +1 -1
  7. package/package.json +74 -70
  8. package/src/components/Alert/{Alert.jsx → Alert.tsx} +8 -43
  9. package/src/components/Alert/Alert.types.ts +34 -0
  10. package/src/components/Alert/README.md +1 -1
  11. package/src/components/Alert/index.ts +2 -0
  12. package/src/components/Badge/Badge.tsx +30 -0
  13. package/src/components/Badge/Badge.types.ts +24 -0
  14. package/src/components/Badge/README.md +1 -1
  15. package/src/components/Badge/index.ts +5 -0
  16. package/src/components/Button/Button.tsx +110 -0
  17. package/src/components/Button/Button.types.ts +93 -0
  18. package/src/components/Button/README.md +1 -1
  19. package/src/components/Button/helpers/{getRootLabelVisibilityClassName.js → getRootLabelVisibilityClassName.ts} +5 -2
  20. package/src/components/Button/index.ts +6 -0
  21. package/src/components/ButtonGroup/{ButtonGroup.jsx → ButtonGroup.tsx} +9 -40
  22. package/src/components/ButtonGroup/ButtonGroup.types.ts +45 -0
  23. package/src/components/ButtonGroup/ButtonGroupContext.ts +4 -0
  24. package/src/components/ButtonGroup/README.md +1 -1
  25. package/src/components/ButtonGroup/{index.js → index.ts} +4 -0
  26. package/src/components/Card/Card.tsx +33 -0
  27. package/src/components/Card/Card.types.ts +46 -0
  28. package/src/components/Card/{CardBody.jsx → CardBody.tsx} +4 -11
  29. package/src/components/Card/{CardFooter.jsx → CardFooter.tsx} +4 -15
  30. package/src/components/Card/README.md +6 -7
  31. package/src/components/Card/{index.js → index.ts} +5 -0
  32. package/src/components/CheckboxField/CheckboxField.module.scss +7 -3
  33. package/src/components/CheckboxField/CheckboxField.tsx +81 -0
  34. package/src/components/CheckboxField/CheckboxField.types.ts +64 -0
  35. package/src/components/CheckboxField/README.md +92 -45
  36. package/src/components/CheckboxField/index.ts +5 -0
  37. package/src/components/FileInputField/FileInputField.module.scss +7 -3
  38. package/src/components/FileInputField/{FileInputField.jsx → FileInputField.tsx} +43 -129
  39. package/src/components/FileInputField/FileInputField.types.ts +101 -0
  40. package/src/components/FileInputField/README.md +21 -4
  41. package/src/components/FileInputField/index.ts +6 -0
  42. package/src/components/FormLayout/FormLayout.module.scss +5 -7
  43. package/src/components/FormLayout/{FormLayout.jsx → FormLayout.tsx} +15 -50
  44. package/src/components/FormLayout/FormLayout.types.ts +55 -0
  45. package/src/components/FormLayout/FormLayoutContext.ts +4 -0
  46. package/src/components/FormLayout/FormLayoutCustomField.module.scss +7 -3
  47. package/src/components/FormLayout/{FormLayoutCustomField.jsx → FormLayoutCustomField.tsx} +12 -67
  48. package/src/components/FormLayout/FormLayoutCustomField.types.ts +60 -0
  49. package/src/components/FormLayout/FormLayoutCustomFieldContext.ts +4 -0
  50. package/src/components/FormLayout/README.md +6 -15
  51. package/src/components/FormLayout/index.ts +14 -0
  52. package/src/components/Grid/Grid.module.scss +1 -1
  53. package/src/components/Grid/Grid.tsx +50 -0
  54. package/src/components/Grid/Grid.types.ts +108 -0
  55. package/src/components/Grid/GridSpan.tsx +36 -0
  56. package/src/components/Grid/README.md +2 -2
  57. package/src/components/Grid/_helpers/generateResponsiveCustomProperties.ts +33 -0
  58. package/src/components/Grid/index.ts +9 -0
  59. package/src/components/InputGroup/InputGroup.module.scss +7 -3
  60. package/src/components/InputGroup/{InputGroup.jsx → InputGroup.tsx} +25 -95
  61. package/src/components/InputGroup/InputGroup.types.ts +80 -0
  62. package/src/components/InputGroup/InputGroupContext.ts +4 -0
  63. package/src/components/InputGroup/README.md +40 -8
  64. package/src/components/InputGroup/{index.js → index.ts} +4 -0
  65. package/src/components/Modal/Modal.tsx +172 -0
  66. package/src/components/Modal/Modal.types.ts +181 -0
  67. package/src/components/Modal/ModalBody.tsx +34 -0
  68. package/src/components/Modal/{ModalCloseButton.jsx → ModalCloseButton.tsx} +6 -19
  69. package/src/components/Modal/{ModalContent.jsx → ModalContent.tsx} +4 -15
  70. package/src/components/Modal/ModalFooter.tsx +27 -0
  71. package/src/components/Modal/ModalHeader.tsx +27 -0
  72. package/src/components/Modal/ModalTitle.tsx +29 -0
  73. package/src/components/Modal/README.md +9 -9
  74. package/src/components/Modal/_helpers/{dialogOnCancelHandler.js → dialogOnCancelHandler.ts} +11 -1
  75. package/src/components/Modal/_helpers/{dialogOnClickHandler.js → dialogOnClickHandler.ts} +13 -7
  76. package/src/components/Modal/_helpers/{dialogOnCloseHandler.js → dialogOnCloseHandler.ts} +11 -1
  77. package/src/components/Modal/_helpers/{dialogOnKeyDownHandler.js → dialogOnKeyDownHandler.ts} +19 -6
  78. package/src/components/Modal/_helpers/{getJustifyClassName.js → getJustifyClassName.ts} +4 -1
  79. package/src/components/Modal/_helpers/getPositionClassName.ts +10 -0
  80. package/src/components/Modal/_helpers/getScrollingClassName.ts +14 -0
  81. package/src/components/Modal/_helpers/{getSizeClassName.js → getSizeClassName.ts} +4 -1
  82. package/src/components/Modal/_hooks/{useModalFocus.js → useModalFocus.ts} +9 -5
  83. package/src/components/Modal/_hooks/{useModalScrollPrevention.js → useModalScrollPrevention.ts} +4 -1
  84. package/src/components/Modal/{index.js → index.ts} +14 -0
  85. package/src/components/Paper/{Paper.jsx → Paper.tsx} +6 -26
  86. package/src/components/Paper/Paper.types.ts +19 -0
  87. package/src/components/Paper/README.md +3 -4
  88. package/src/components/Paper/index.ts +2 -0
  89. package/src/components/Popover/Popover.module.scss +1 -1
  90. package/src/components/Popover/Popover.tsx +61 -0
  91. package/src/components/Popover/Popover.types.ts +75 -0
  92. package/src/components/Popover/PopoverWrapper.tsx +27 -0
  93. package/src/components/Popover/README.md +34 -22
  94. package/src/components/Popover/_helpers/{cleanPlacementStyle.js → cleanPlacementStyle.ts} +4 -1
  95. package/src/components/Popover/_helpers/{getRootAlignmentClassName.js → getRootAlignmentClassName.ts} +4 -1
  96. package/src/components/Popover/_helpers/{getRootSideClassName.js → getRootSideClassName.ts} +4 -1
  97. package/src/components/Popover/index.ts +8 -0
  98. package/src/components/Radio/README.md +125 -48
  99. package/src/components/Radio/Radio.module.scss +7 -3
  100. package/src/components/Radio/Radio.tsx +116 -0
  101. package/src/components/Radio/Radio.types.ts +91 -0
  102. package/src/components/Radio/index.ts +5 -0
  103. package/src/components/ScrollView/README.md +1 -1
  104. package/src/components/ScrollView/ScrollView.module.scss +5 -0
  105. package/src/components/ScrollView/{ScrollView.jsx → ScrollView.tsx} +55 -166
  106. package/src/components/ScrollView/ScrollView.types.ts +121 -0
  107. package/src/components/ScrollView/_helpers/getElementsPositionDifference.ts +17 -0
  108. package/src/components/ScrollView/_hooks/{useLoadResizeHook.js → useLoadResizeHook.ts} +14 -3
  109. package/src/components/ScrollView/_hooks/{useScrollPositionHook.js → useScrollPositionHook.ts} +11 -4
  110. package/src/components/ScrollView/index.ts +6 -0
  111. package/src/components/SelectField/README.md +137 -51
  112. package/src/components/SelectField/SelectField.module.scss +7 -3
  113. package/src/components/SelectField/SelectField.tsx +139 -0
  114. package/src/components/SelectField/SelectField.types.ts +121 -0
  115. package/src/components/SelectField/_components/Option/Option.tsx +19 -0
  116. package/src/components/SelectField/_components/Option/Option.types.ts +21 -0
  117. package/src/components/SelectField/_components/Option/index.ts +2 -0
  118. package/src/components/SelectField/index.ts +7 -0
  119. package/src/components/Table/README.md +1 -1
  120. package/src/components/Table/{Table.jsx → Table.tsx} +4 -43
  121. package/src/components/Table/Table.types.ts +51 -0
  122. package/src/components/Table/_components/TableBodyCell/TableBodyCell.tsx +20 -0
  123. package/src/components/Table/_components/TableBodyCell/TableBodyCell.types.ts +20 -0
  124. package/src/components/Table/_components/TableBodyCell/index.ts +2 -0
  125. package/src/components/Table/_components/TableHeaderCell/{TableHeaderCell.jsx → TableHeaderCell.tsx} +3 -34
  126. package/src/components/Table/_components/TableHeaderCell/TableHeaderCell.types.ts +20 -0
  127. package/src/components/Table/_components/TableHeaderCell/index.ts +2 -0
  128. package/src/components/Table/index.ts +8 -0
  129. package/src/components/Tabs/README.md +2 -2
  130. package/src/components/Tabs/{Tabs.jsx → Tabs.tsx} +4 -20
  131. package/src/components/Tabs/Tabs.types.ts +19 -0
  132. package/src/components/Tabs/TabsItem.tsx +49 -0
  133. package/src/components/Tabs/TabsItem.types.ts +42 -0
  134. package/src/components/Tabs/index.ts +4 -0
  135. package/src/components/Text/README.md +1 -1
  136. package/src/components/Text/Text.module.scss +5 -7
  137. package/src/components/Text/Text.tsx +46 -0
  138. package/src/components/Text/Text.types.ts +31 -0
  139. package/src/components/Text/_helpers/getRootClampClassName.ts +13 -0
  140. package/src/components/Text/_helpers/getRootHyphensClassName.ts +14 -0
  141. package/src/components/Text/_helpers/getRootWordWrappingClassName.ts +14 -0
  142. package/src/components/Text/index.ts +6 -0
  143. package/src/components/TextArea/README.md +35 -14
  144. package/src/components/TextArea/TextArea.module.scss +7 -3
  145. package/src/components/TextArea/TextArea.tsx +95 -0
  146. package/src/components/TextArea/TextArea.types.ts +76 -0
  147. package/src/components/TextArea/index.ts +5 -0
  148. package/src/components/TextField/README.md +35 -13
  149. package/src/components/TextField/TextField.module.scss +7 -3
  150. package/src/components/TextField/TextField.tsx +112 -0
  151. package/src/components/TextField/TextField.types.ts +95 -0
  152. package/src/components/TextField/index.ts +6 -0
  153. package/src/components/TextLink/README.md +2 -2
  154. package/src/components/TextLink/{TextLink.jsx → TextLink.tsx} +4 -15
  155. package/src/components/TextLink/TextLink.types.ts +12 -0
  156. package/src/components/TextLink/index.ts +2 -0
  157. package/src/components/Toggle/README.md +92 -45
  158. package/src/components/Toggle/Toggle.module.scss +7 -3
  159. package/src/components/Toggle/Toggle.tsx +82 -0
  160. package/src/components/Toggle/Toggle.types.ts +59 -0
  161. package/src/components/Toggle/index.ts +5 -0
  162. package/src/components/Toolbar/README.md +3 -3
  163. package/src/components/Toolbar/Toolbar.tsx +41 -0
  164. package/src/components/Toolbar/Toolbar.types.ts +74 -0
  165. package/src/components/Toolbar/ToolbarGroup.tsx +38 -0
  166. package/src/components/Toolbar/{ToolbarItem.jsx → ToolbarItem.tsx} +5 -21
  167. package/src/components/Toolbar/_helpers/{getAlignClassName.js → getAlignClassName.ts} +8 -1
  168. package/src/components/Toolbar/_helpers/{getJustifyClassName.js → getJustifyClassName.ts} +4 -1
  169. package/src/components/Toolbar/{index.js → index.ts} +7 -0
  170. package/src/components/_helpers/{getRootColorClassName.js → getRootColorClassName.ts} +7 -2
  171. package/src/components/_helpers/{getRootPriorityClassName.js → getRootPriorityClassName.ts} +7 -2
  172. package/src/components/_helpers/{getRootSizeClassName.js → getRootSizeClassName.ts} +7 -2
  173. package/src/components/_helpers/getRootStateClassName.ts +24 -0
  174. package/src/components/_helpers/resolveContextOrProp.ts +13 -0
  175. package/src/helpers/classNames/{classNames.js → classNames.ts} +2 -2
  176. package/src/helpers/isChildrenEmpty/isChildrenEmpty.ts +5 -0
  177. package/src/helpers/transferProps/transferProps.ts +50 -0
  178. package/src/helpers/transferProps/transferProps.types.ts +11 -0
  179. package/src/index.ts +211 -0
  180. package/src/providers/globalProps/GlobalProps.types.ts +30 -0
  181. package/src/providers/globalProps/GlobalPropsContext.ts +6 -0
  182. package/src/providers/globalProps/{GlobalPropsProvider.jsx → GlobalPropsProvider.tsx} +8 -15
  183. package/src/providers/globalProps/{index.js → index.ts} +4 -0
  184. package/src/providers/globalProps/withGlobalProps.tsx +36 -0
  185. package/src/providers/translations/Translations.types.ts +26 -0
  186. package/src/providers/translations/TranslationsContext.ts +7 -0
  187. package/src/providers/translations/{TranslationsProvider.jsx → TranslationsProvider.tsx} +8 -15
  188. package/src/providers/translations/{index.js → index.ts} +5 -0
  189. package/src/styles/settings/_form-fields.scss +2 -1
  190. package/src/styles/theme/_form-fields.scss +16 -11
  191. package/src/styles/theme-constants/_colors.scss +21 -0
  192. package/src/styles/tools/_accessibility.scss +2 -2
  193. package/src/styles/tools/form-fields/_box-field-layout.scss +5 -8
  194. package/src/styles/tools/form-fields/_inline-field-elements.scss +0 -7
  195. package/src/styles/tools/form-fields/_inline-field-layout.scss +0 -8
  196. package/src/styles/tools/form-fields/_variants.scss +7 -7
  197. package/src/theme.scss +37 -12
  198. package/src/translations/{en.js → en.ts} +3 -1
  199. package/src/types/breakpoints.ts +1 -0
  200. package/src/types/colors.ts +7 -0
  201. package/src/types/index.ts +13 -0
  202. package/src/types/labelPositions.ts +1 -0
  203. package/src/types/layouts.ts +1 -0
  204. package/src/types/modules.d.ts +16 -0
  205. package/src/types/priorities.ts +1 -0
  206. package/src/types/sizes.ts +1 -0
  207. package/src/types/states.ts +1 -0
  208. package/src/types/styles.ts +4 -0
  209. package/src/utils/mergeDeep.ts +34 -0
  210. package/src/utils/mergeDeep.types.ts +4 -0
  211. package/.claude/agents/code-reviewer.md +0 -122
  212. package/.claude/rules/code.md +0 -22
  213. package/.claude/rules/docs.md +0 -35
  214. package/.claude/rules/frontend.md +0 -72
  215. package/.claude/rules/git.md +0 -13
  216. package/.claude/rules/safety-guards.md +0 -9
  217. package/.claude/rules/styling.md +0 -32
  218. package/.claude/rules/testing.md +0 -59
  219. package/.claude/settings.json +0 -32
  220. package/.claude/skills/commit/SKILL.md +0 -54
  221. package/.devcontainer/devcontainer.json +0 -23
  222. package/.eslintrc-ts +0 -40
  223. package/.mcp.json +0 -8
  224. package/.nvmrc +0 -1
  225. package/CLAUDE.md +0 -82
  226. package/docker-compose.base.yml +0 -93
  227. package/docker-compose.yml.dist +0 -41
  228. package/jest.config-ts.js +0 -34
  229. package/opencode.json +0 -10
  230. package/playwright-ct.config.ts +0 -68
  231. package/scripts/auto-start-mkdocs.sh +0 -5
  232. package/scripts/auto-start-node.sh +0 -33
  233. package/scripts/mcps/chrome-host/README.md +0 -118
  234. package/scripts/mcps/chrome-host/cdp_proxy.py +0 -90
  235. package/scripts/mcps/chrome-host/mcp-entry.sh +0 -33
  236. package/scripts/mcps/chrome-host/mcp-launch.sh +0 -36
  237. package/scripts/mcps/chrome-host/mcp-setup.sh +0 -70
  238. package/scripts/mcps/chrome-host/start-host-chrome.sh +0 -267
  239. package/setup.sh +0 -107
  240. package/src/CNAME +0 -1
  241. package/src/components/Alert/index.js +0 -1
  242. package/src/components/Badge/Badge.jsx +0 -51
  243. package/src/components/Badge/index.js +0 -1
  244. package/src/components/Button/Button.jsx +0 -203
  245. package/src/components/Button/helpers/getRootPriorityClassName.js +0 -15
  246. package/src/components/Button/index.js +0 -1
  247. package/src/components/ButtonGroup/ButtonGroupContext.js +0 -3
  248. package/src/components/Card/Card.jsx +0 -67
  249. package/src/components/CheckboxField/CheckboxField.jsx +0 -144
  250. package/src/components/CheckboxField/index.js +0 -1
  251. package/src/components/FileInputField/index.js +0 -1
  252. package/src/components/FormLayout/FormLayoutContext.js +0 -3
  253. package/src/components/FormLayout/FormLayoutCustomFieldContext.js +0 -3
  254. package/src/components/FormLayout/index.js +0 -4
  255. package/src/components/Grid/Grid.jsx +0 -225
  256. package/src/components/Grid/GridSpan.jsx +0 -88
  257. package/src/components/Grid/_helpers/generateResponsiveCustomProperties.js +0 -22
  258. package/src/components/Grid/index.js +0 -2
  259. package/src/components/InputGroup/InputGroupContext.js +0 -3
  260. package/src/components/Modal/Modal.jsx +0 -262
  261. package/src/components/Modal/ModalBody.jsx +0 -60
  262. package/src/components/Modal/ModalFooter.jsx +0 -42
  263. package/src/components/Modal/ModalHeader.jsx +0 -42
  264. package/src/components/Modal/ModalTitle.jsx +0 -42
  265. package/src/components/Modal/_helpers/getPositionClassName.js +0 -7
  266. package/src/components/Modal/_helpers/getScrollingClassName.js +0 -11
  267. package/src/components/Paper/index.js +0 -1
  268. package/src/components/Popover/Popover.jsx +0 -124
  269. package/src/components/Popover/PopoverWrapper.jsx +0 -38
  270. package/src/components/Popover/index.js +0 -2
  271. package/src/components/Radio/Radio.jsx +0 -212
  272. package/src/components/Radio/index.js +0 -1
  273. package/src/components/ScrollView/_helpers/getElementsPositionDifference.js +0 -11
  274. package/src/components/ScrollView/index.js +0 -1
  275. package/src/components/SelectField/SelectField.jsx +0 -272
  276. package/src/components/SelectField/_components/Option/Option.jsx +0 -46
  277. package/src/components/SelectField/_components/Option/index.js +0 -1
  278. package/src/components/SelectField/index.js +0 -1
  279. package/src/components/Table/_components/TableBodyCell/TableBodyCell.jsx +0 -46
  280. package/src/components/Table/_components/TableBodyCell/index.js +0 -1
  281. package/src/components/Table/_components/TableHeaderCell/index.js +0 -1
  282. package/src/components/Table/index.js +0 -1
  283. package/src/components/Tabs/TabsItem.jsx +0 -91
  284. package/src/components/Tabs/index.js +0 -2
  285. package/src/components/Text/Text.jsx +0 -76
  286. package/src/components/Text/_helpers/getRootClampClassName.js +0 -11
  287. package/src/components/Text/_helpers/getRootHyphensClassName.js +0 -11
  288. package/src/components/Text/_helpers/getRootWordWrappingClassName.js +0 -11
  289. package/src/components/Text/index.js +0 -1
  290. package/src/components/TextArea/TextArea.jsx +0 -174
  291. package/src/components/TextArea/index.js +0 -1
  292. package/src/components/TextField/TextField.jsx +0 -208
  293. package/src/components/TextField/index.js +0 -1
  294. package/src/components/TextLink/index.js +0 -1
  295. package/src/components/Toggle/Toggle.jsx +0 -144
  296. package/src/components/Toggle/index.js +0 -1
  297. package/src/components/Toolbar/Toolbar.jsx +0 -76
  298. package/src/components/Toolbar/ToolbarGroup.jsx +0 -64
  299. package/src/components/_helpers/getRootValidationStateClassName.js +0 -15
  300. package/src/components/_helpers/resolveContextOrProp.js +0 -10
  301. package/src/helpers/isChildrenEmpty/isChildrenEmpty.js +0 -3
  302. package/src/helpers/transferProps/transferProps.js +0 -38
  303. package/src/index.js +0 -67
  304. package/src/providers/globalProps/GlobalPropsContext.jsx +0 -5
  305. package/src/providers/globalProps/withGlobalProps.jsx +0 -38
  306. package/src/providers/translations/TranslationsContext.jsx +0 -6
  307. package/src/utils/mergeDeep.js +0 -28
  308. package/tsconfig.json +0 -27
  309. /package/src/helpers/classNames/{index.js → index.ts} +0 -0
  310. /package/src/helpers/isChildrenEmpty/{index.js → index.ts} +0 -0
  311. /package/src/helpers/transferProps/{index.js → index.ts} +0 -0
@@ -1,118 +0,0 @@
1
- # Chrome-host bridge
2
-
3
- Lets an MCP-capable AI assistant in the `devcontainer` drive **Chrome on the
4
- host** via [`chrome-devtools-mcp`](https://github.com/ChromeDevTools/chrome-devtools-mcp)
5
- over the Chrome DevTools Protocol (CDP).
6
-
7
- ## Principles
8
-
9
- - The container reaches the host only via `host.docker.internal`.
10
- - Chrome's DevTools endpoint rejects any `Host` header that is not an IP literal
11
- (or the name `localhost`) — so the container cannot connect to it directly.
12
- - Fix: a loopback proxy **inside the container** (`127.0.0.1:9334`); the `Host`
13
- Chrome finally sees is `127.0.0.1`, an IP, which it accepts.
14
- - Chrome runs in a dedicated, persistent profile (separate from your everyday
15
- one) and is started **by hand** on the host — never from a Claude action,
16
- which can reap it with its process group.
17
-
18
- ## Architecture
19
-
20
- ```text
21
- Claude (devcontainer)
22
- │ .mcp.json → mcp-entry.sh → docker compose exec node mcp-launch.sh
23
- ▼
24
- node container
25
- ├─ cdp_proxy.py 127.0.0.1:9334 ──► host.docker.internal:9333
26
- └─ npx chrome-devtools-mcp --browser-url http://127.0.0.1:9334
27
- │
28
- ▼
29
- host: Chrome --remote-debugging-port=9333 (throwaway profile)
30
- ```
31
-
32
- | Script | Runs on | Purpose |
33
- | --- | --- | --- |
34
- | `start-host-chrome.sh` | host | Launch the debug Chrome on `:9333`. Idempotent; auto-detects Chrome/Chromium/Edge. On native Docker, also runs an `ncat` forwarder to expose `:9333` on the bridge gateway. |
35
- | `cdp_proxy.py` | node container | Loopback CDP proxy `:9334` → host `:9333`. Binds-or-exits. |
36
- | `mcp-launch.sh` | node container | Ensure the proxy is up, then `exec` `chrome-devtools-mcp`. |
37
- | `mcp-entry.sh` | host / devcontainer | The `.mcp.json` command; routes into the node container (adds `sudo` inside the container). |
38
- | `mcp-setup.sh` | host (setup) | Add the `host.docker.internal:host-gateway` mapping on native Docker Engine. Idempotent; no-op on Docker Desktop. |
39
-
40
- ## Registration
41
-
42
- Register `mcp-entry.sh` as an MCP server named `chrome-host`. Any MCP client
43
- works — point its config at the script.
44
-
45
- **Claude / GitHub Copilot CLI** — `.mcp.json` (repo root):
46
-
47
- ```json
48
- {
49
- "mcpServers": {
50
- "chrome-host": {
51
- "command": "sh",
52
- "args": ["scripts/mcps/chrome-host/mcp-entry.sh"]
53
- }
54
- }
55
- }
56
- ```
57
-
58
- **OpenCode** — `opencode.json` (repo root):
59
-
60
- ```json
61
- {
62
- "mcp": {
63
- "chrome-host": {
64
- "type": "local",
65
- "command": ["sh", "scripts/mcps/chrome-host/mcp-entry.sh"],
66
- "enabled": true
67
- }
68
- }
69
- }
70
- ```
71
-
72
- Requirements: a `docker-compose.yml` at the repo root, the repo mounted at
73
- `/workspace` in the container, and a Compose service named `node` that runs
74
- `node`/`npx`.
75
-
76
- ## Usage
77
-
78
- 1. Start host Chrome (from a host terminal, **not** from inside an AI action):
79
-
80
- ```sh
81
- ./scripts/mcps/chrome-host/start-host-chrome.sh
82
- ```
83
-
84
- 2. On first run, approve the `chrome-host` server in your MCP client.
85
-
86
- The proxy and MCP server are bootstrapped by `mcp-launch.sh`; you only start
87
- Chrome by hand.
88
-
89
- ## Platform support
90
-
91
- Decided by **Docker Desktop vs native Docker Engine**, not the OS.
92
-
93
- | Host setup | `host.docker.internal` reaches host loopback? | Extra steps |
94
- | --- | --- | --- |
95
- | Docker Desktop (macOS/Linux) | Yes (auto) | None. |
96
- | Native Docker Engine (Linux) | No (bridge gateway only) | `setup.sh` (via `mcp-setup.sh`) adds the host-gateway mapping; the launcher runs a host-side `ncat` forwarder (install `nmap-ncat`/`nmap`) to expose Chrome's loopback CDP port on the bridge gateway. **Firewall the port**: this exposes DevTools beyond loopback. |
97
-
98
- ## Configuration
99
-
100
- - Ports: host CDP `9333` (configurable), in-container proxy `9334` (fixed).
101
- - Overrides (host launcher), set in the repo `.env`: `CHROME_DEBUG_PORT` and
102
- `CHROME_BIN`. `CHROME_DEBUG_BIND` is an advanced escape hatch — the bind is
103
- auto-detected, so it is not listed in `.env.dist`; set it only when detection
104
- fails (e.g. a non-default daemon `host-gateway-ip`). **Security:** a
105
- non-loopback bind exposes the unauthenticated CDP port; firewall it.
106
- The proxy's listen port and target host are fixed constants; only its upstream
107
- port is configurable, and it follows the same `CHROME_DEBUG_PORT`.
108
- - Set these in the repo `.env`; Compose passes `CHROME_DEBUG_PORT` into the
109
- container, so a single knob drives both sides. Recreate the node container
110
- after editing. See `.env.dist`.
111
- - Profile: `~/.chrome-debug-profile-<COMPOSE_PROJECT_NAME>` (per project, fixed).
112
-
113
- ## Troubleshooting
114
-
115
- - Status: `claude mcp get chrome-host` (`✔ Connected` = healthy chain).
116
- - Chrome died? Re-run `start-host-chrome.sh` (it persists across sessions).
117
- - `claude mcp list` shows *Pending approval* until you approve project servers.
118
- - Disable: remove the `chrome-host` entry from `.mcp.json`.
@@ -1,90 +0,0 @@
1
- import os
2
- import socket
3
- import threading
4
-
5
- # Loopback CDP proxy. Runs INSIDE the node container.
6
- #
7
- # A container reaches host Chrome only via `host.docker.internal` (forwarded to
8
- # the host loopback on Docker Desktop; the bridge gateway on native Linux Docker,
9
- # where a host-side ncat forwarder exposes Chrome's loopback CDP port). But
10
- # Chrome's DevTools endpoint rejects any Host header that isn't an IP literal (or
11
- # the name "localhost") -- anti DNS-rebinding -- so connecting by that *name*
12
- # fails, and the IPv6 it may also resolve to is often not forwarded.
13
- #
14
- # So this proxy listens on 127.0.0.1:LISTEN_PORT and forwards raw bytes to host
15
- # Chrome. Clients reach it as "127.0.0.1:LISTEN_PORT", so the Host header Chrome
16
- # sees is an IP (accepted), and the webSocketDebuggerUrl it echoes back stays on
17
- # 127.0.0.1 too, so the follow-up WebSocket also works.
18
- #
19
- # The proxy's own endpoint is fixed: it always listens on the container loopback
20
- # and forwards to host Chrome over host.docker.internal. Only the upstream Chrome
21
- # port is configurable, via CHROME_DEBUG_PORT (set in the repo's .env, which
22
- # Compose passes into the container), so a single knob keeps both sides in sync.
23
-
24
- LISTEN_HOST = "127.0.0.1"
25
- LISTEN_PORT = 9334 # fixed; must match PROXY_PORT in mcp-launch.sh
26
- TARGET_HOST = "host.docker.internal" # fixed; how the container reaches the host
27
- TARGET_PORT = int(os.environ.get("CHROME_DEBUG_PORT") or "9333") # host Chrome CDP port
28
-
29
-
30
- def resolve_target():
31
- # Force IPv4: host.docker.internal may also resolve to an IPv6 address that
32
- # Docker does not forward to the host.
33
- try:
34
- infos = socket.getaddrinfo(TARGET_HOST, TARGET_PORT, socket.AF_INET, socket.SOCK_STREAM)
35
- return infos[0][4]
36
- except Exception:
37
- # Docker Desktop's well-known host-gateway IPv4 as a last resort.
38
- return ("192.168.65.254", TARGET_PORT)
39
-
40
-
41
- TARGET = resolve_target()
42
-
43
-
44
- def pipe(source, destination):
45
- try:
46
- while True:
47
- data = source.recv(65536)
48
- if not data:
49
- break
50
- destination.sendall(data)
51
- except Exception:
52
- pass
53
- finally:
54
- for sock in (source, destination):
55
- try:
56
- sock.close()
57
- except Exception:
58
- pass
59
-
60
-
61
- def handle(client):
62
- try:
63
- upstream = socket.create_connection(TARGET, timeout=10)
64
- except Exception:
65
- client.close()
66
- return
67
- threading.Thread(target=pipe, args=(client, upstream), daemon=True).start()
68
- threading.Thread(target=pipe, args=(upstream, client), daemon=True).start()
69
-
70
-
71
- def main():
72
- srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
73
- srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
74
- try:
75
- srv.bind((LISTEN_HOST, LISTEN_PORT))
76
- except OSError:
77
- # Another instance already owns the port; let it serve.
78
- raise SystemExit(0)
79
- srv.listen(128)
80
- print("chrome-host: proxy listening %s:%d -> %s:%d" % (LISTEN_HOST, LISTEN_PORT, TARGET[0], TARGET[1]), flush=True)
81
- while True:
82
- try:
83
- conn, _ = srv.accept()
84
- except Exception:
85
- continue
86
- handle(conn)
87
-
88
-
89
- if __name__ == "__main__":
90
- main()
@@ -1,33 +0,0 @@
1
- #!/bin/sh
2
-
3
- # Referenced by .mcp.json / opencode.json as the `chrome-host` MCP server command.
4
- #
5
- # Spawns chrome-devtools-mcp inside the node container (via mcp-launch.sh),
6
- # whether the assistant runs in the devcontainer or on the host. Docker needs
7
- # `sudo` inside the container (like the node/npx wrappers) but not on the host;
8
- # we tell them apart by /.dockerenv, which exists only in a container.
9
-
10
- set -eu
11
-
12
- # Compose service that runs the proxy + chrome-devtools-mcp.
13
- DOCKER_SERVICE_NAME=node
14
-
15
- script_dir="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
16
-
17
- # Walk up to the repo root (the directory holding docker-compose.yml) so
18
- # `docker compose` finds the compose files + .env regardless of the caller's cwd.
19
- root="$script_dir"
20
- while [ "$root" != "/" ] && [ ! -f "$root/docker-compose.yml" ]; do
21
- root="$(dirname "$root")"
22
- done
23
- cd "$root"
24
-
25
- # Path to mcp-launch.sh as seen inside the node container (repo mounted at /workspace).
26
- rel="${script_dir#"$root"/}"
27
- launch="/workspace/$rel/mcp-launch.sh"
28
-
29
- if [ -f /.dockerenv ]; then
30
- exec sudo docker compose exec -T "$DOCKER_SERVICE_NAME" "$launch"
31
- else
32
- exec docker compose exec -T "$DOCKER_SERVICE_NAME" "$launch"
33
- fi
@@ -1,36 +0,0 @@
1
- #!/bin/sh
2
-
3
- # Runs INSIDE the node container, invoked by mcp-entry.sh.
4
- #
5
- # Ensures the loopback CDP proxy (cdp_proxy.py) is running, then hands stdio over
6
- # to chrome-devtools-mcp pointed at the proxy. Resolves cdp_proxy.py next to
7
- # itself, so it works from any location under the repo.
8
-
9
- set -eu
10
-
11
- SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
12
- PROXY_PORT=9334 # fixed; must match LISTEN_PORT in cdp_proxy.py
13
- PROXY_SCRIPT="$SCRIPT_DIR/cdp_proxy.py"
14
-
15
- is_up() {
16
- python3 -c 'import socket,sys; s=socket.socket(); sys.exit(0 if s.connect_ex(("127.0.0.1",'"$PROXY_PORT"'))==0 else 1)' 2>/dev/null
17
- }
18
-
19
- if ! is_up; then
20
- # cdp_proxy.py binds-or-exits, so concurrent launches are safe.
21
- python3 "$PROXY_SCRIPT" >/tmp/cdp_proxy.log 2>&1 &
22
- i=0
23
- while [ "$i" -lt 25 ]; do
24
- if is_up; then
25
- break
26
- fi
27
- i=$((i + 1))
28
- sleep 0.2
29
- done
30
- fi
31
-
32
- # chrome-devtools-mcp is fetched on demand via npx rather than being added to
33
- # package.json: it is host/dev MCP tooling for this bridge, not an app build or
34
- # runtime dependency, so it deliberately stays out of the lockfile. `-y` confirms
35
- # the one-off npx install; `@latest` tracks upstream fixes for the dev tool.
36
- exec npx -y chrome-devtools-mcp@latest --browser-url "http://127.0.0.1:${PROXY_PORT}" "$@"
@@ -1,70 +0,0 @@
1
- #!/bin/sh
2
-
3
- # Run on the HOST during project setup (called from setup.sh).
4
- #
5
- # Native Docker Engine on Linux doesn't inject `host.docker.internal`, so the
6
- # proxy container can't reach host Chrome. This adds the host-gateway mapping to
7
- # the node service -- but only there. On Docker Desktop/macOS it's a no-op:
8
- # the name already works, and adding the mapping would repoint it to the bridge
9
- # gateway and break Desktop.
10
- #
11
- # Idempotent; after patching a running setup, recreate the service:
12
- # `docker compose up -d node`.
13
-
14
- set -eu
15
-
16
- ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd)"
17
- COMPOSE_FILE="$ROOT/docker-compose.yml"
18
- DOCKER_SERVICE_NAME=node
19
- MAPPING="host.docker.internal:host-gateway"
20
-
21
- # Only native Docker Engine on Linux needs the mapping. macOS is always Desktop.
22
- if [ "$(uname -s)" = "Darwin" ]; then
23
- exit 0
24
- fi
25
-
26
- DOCKER_OS="$(docker info --format '{{.OperatingSystem}}' 2>/dev/null || true)"
27
- if [ -z "$DOCKER_OS" ]; then
28
- echo "chrome-host: warning: could not query Docker (is it running?); skipping host-gateway setup." >&2
29
- exit 0
30
- fi
31
- case "$DOCKER_OS" in
32
- *"Docker Desktop"*) exit 0 ;;
33
- esac
34
-
35
- # Native Docker Engine from here on.
36
-
37
- # The host launcher forwards Chrome's loopback CDP port to the bridge gateway
38
- # with ncat (headed Chrome only binds loopback). Warn now rather than failing at
39
- # first browser launch; don't auto-install -- that needs sudo plus distro
40
- # detection, and adding host packages requires explicit approval.
41
- if ! command -v ncat >/dev/null 2>&1; then
42
- echo "chrome-host: warning: 'ncat' not found; install it (package 'nmap-ncat' or 'nmap'," >&2
43
- echo "chrome-host: depending on your distro) so start-host-chrome.sh can expose Chrome's" >&2
44
- echo "chrome-host: CDP port on the bridge gateway for the container." >&2
45
- fi
46
-
47
- [ -f "$COMPOSE_FILE" ] || exit 0
48
- if grep -q "$MAPPING" "$COMPOSE_FILE"; then
49
- exit 0
50
- fi
51
-
52
- # Insert extra_hosts under the `<service>:` block (sibling of `extends:`).
53
- TMP_FILE="$COMPOSE_FILE.tmp"
54
- awk -v service="$DOCKER_SERVICE_NAME" '
55
- { print }
56
- $0 ~ ("^ " service ":[[:space:]]*$") && !done {
57
- print " extra_hosts:"
58
- print " - \"host.docker.internal:host-gateway\""
59
- done = 1
60
- }
61
- ' "$COMPOSE_FILE" > "$TMP_FILE"
62
-
63
- if grep -q "$MAPPING" "$TMP_FILE"; then
64
- mv "$TMP_FILE" "$COMPOSE_FILE"
65
- echo "chrome-host: native Docker Engine detected -- added '$MAPPING' to the '$DOCKER_SERVICE_NAME' service in $COMPOSE_FILE."
66
- echo "chrome-host: if the '$DOCKER_SERVICE_NAME' container is already running, recreate it: docker compose up -d $DOCKER_SERVICE_NAME"
67
- else
68
- rm -f "$TMP_FILE"
69
- echo "chrome-host: warning: could not locate the '$DOCKER_SERVICE_NAME' service in $COMPOSE_FILE; add '$MAPPING' to its extra_hosts manually." >&2
70
- fi
@@ -1,267 +0,0 @@
1
- #!/bin/sh
2
-
3
- # Run on the HOST (macOS or Linux). Launches a dedicated, isolated Chrome with
4
- # the DevTools (CDP) endpoint enabled so a containerized assistant can drive it.
5
- #
6
- # It uses its own dedicated --user-data-dir, so your everyday Chrome and logins
7
- # are untouched. A separate profile is also required: Chrome only opens a debug
8
- # port for a fresh instance, not for an already-running default profile.
9
- #
10
- # That profile is persistent (reused across runs, kept under $HOME) -- not
11
- # ephemeral or sandboxed. Anything you sign in to here stays on disk and is
12
- # reachable over the unauthenticated CDP port, so avoid logging in to sensitive
13
- # accounts in this browser.
14
- #
15
- # Overrides (shell wins over the repo's .env); see README -> Platform support
16
- # for the bind/platform details:
17
- # CHROME_DEBUG_PORT CDP port (default 9333)
18
- # CHROME_BIN explicit browser binary (else auto-detected)
19
- # CHROME_DEBUG_BIND bind address (else auto-detected: loopback on Docker
20
- # Desktop, docker bridge gateway on native Engine).
21
- # SECURITY: a non-loopback bind exposes the port -- firewall it.
22
- #
23
- # Profile is always ~/.chrome-debug-profile-<COMPOSE_PROJECT_NAME> (not configurable).
24
-
25
- set -eu
26
-
27
- # Opens a real browser window, so it must run on the HOST, not in a container
28
- # (/.dockerenv exists only inside one).
29
- if [ -f /.dockerenv ]; then
30
- echo "chrome-host: error: run start-host-chrome.sh on your HOST, not in a container." >&2
31
- echo "chrome-host: it launches a Chrome window on your desktop for the containerized" >&2
32
- echo "chrome-host: assistant to drive. Open a host terminal and run it there." >&2
33
- exit 1
34
- fi
35
-
36
- # Fall back to the repo's .env (the file Docker Compose reads) so this launcher
37
- # and the in-container proxy share one source of truth. Precedence: shell > .env
38
- # > the defaults below.
39
- env_root="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
40
- while [ "$env_root" != "/" ] && [ ! -f "$env_root/docker-compose.yml" ]; do
41
- env_root="$(dirname "$env_root")"
42
- done
43
- ENV_FILE="$env_root/.env"
44
- # For each host knob, keep a value already set in the shell; otherwise eval the
45
- # matching .env line. Letting the shell run the assignment strips quotes and
46
- # inline comments for free. Values containing spaces must be quoted in .env.
47
- if [ -f "$ENV_FILE" ]; then
48
- for env_key in CHROME_DEBUG_PORT CHROME_BIN CHROME_DEBUG_BIND COMPOSE_PROJECT_NAME COMPOSE_DOCS_SERVER_PORT; do
49
- eval "[ -n \"\${$env_key+x}\" ]" && continue
50
- eval "$(grep -E "^[[:space:]]*$env_key=" "$ENV_FILE" | tail -n 1 || true)"
51
- done
52
- fi
53
-
54
- PORT="${CHROME_DEBUG_PORT:-9333}"
55
-
56
- # Preflight: curl drives every CDP readiness probe below, on every platform.
57
- if ! command -v curl >/dev/null 2>&1; then
58
- echo "chrome-host: error: 'curl' is required to probe Chrome's CDP endpoint but is not installed." >&2
59
- exit 1
60
- fi
61
-
62
- # Bind address. Explicit CHROME_DEBUG_BIND wins; otherwise auto-detect: loopback
63
- # on Docker Desktop (incl. macOS), else the docker bridge gateway for native
64
- # Engine. Binding to the gateway (not 0.0.0.0) keeps the port off your wider
65
- # network. See README -> Platform support.
66
- detect_bind() {
67
- if [ "$(uname -s)" = "Darwin" ]; then
68
- printf '127.0.0.1\n'
69
- return 0
70
- fi
71
- case "$(docker info --format '{{.OperatingSystem}}' 2>/dev/null || true)" in
72
- *"Docker Desktop"*)
73
- printf '127.0.0.1\n'
74
- return 0
75
- ;;
76
- esac
77
- # println each gateway on its own line, then take the first IPv4 -- an
78
- # IPv6-enabled bridge would otherwise concatenate the v4 and v6 gateways into
79
- # one malformed token that ncat cannot bind.
80
- gateway_ip="$(docker network inspect bridge --format '{{range .IPAM.Config}}{{println .Gateway}}{{end}}' 2>/dev/null | grep -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$' | head -n1 || true)"
81
- if [ -n "$gateway_ip" ]; then
82
- printf '%s\n' "$gateway_ip"
83
- return 0
84
- fi
85
- return 1
86
- }
87
- # Preflight: auto-detecting the bind address shells out to the docker CLI. Skip
88
- # the check when the bind is supplied explicitly, or on macOS (always loopback).
89
- if [ -z "${CHROME_DEBUG_BIND:-}" ] && [ "$(uname -s)" != "Darwin" ] && ! command -v docker >/dev/null 2>&1; then
90
- echo "chrome-host: error: auto-detecting the CDP bind address needs the 'docker' CLI, but it is" >&2
91
- echo "chrome-host: not installed. Install Docker, or set CHROME_DEBUG_BIND (e.g. 127.0.0.1 for" >&2
92
- echo "chrome-host: Docker Desktop) to skip detection." >&2
93
- exit 1
94
- fi
95
- if [ -n "${CHROME_DEBUG_BIND:-}" ]; then
96
- BIND="$CHROME_DEBUG_BIND"
97
- else
98
- BIND="$(detect_bind)" || true
99
- if [ -z "$BIND" ]; then
100
- echo "chrome-host: error: could not determine the Docker bridge gateway for the CDP forwarder" >&2
101
- echo "chrome-host: (is the Docker daemon running?). Set CHROME_DEBUG_BIND to your docker bridge" >&2
102
- echo "chrome-host: gateway IP to override, and retry." >&2
103
- exit 1
104
- fi
105
- fi
106
- case "$BIND" in
107
- 127.0.0.1 | ::1) ;;
108
- *)
109
- echo "chrome-host: warning: native Docker detected — exposing the CDP port on $BIND so the" >&2
110
- echo "chrome-host: container can reach it. This exposes browser control beyond" >&2
111
- echo "chrome-host: loopback; firewall the port. Native Docker also needs" >&2
112
- echo "chrome-host: 'host.docker.internal:host-gateway' in the node service's" >&2
113
- echo "chrome-host: extra_hosts. Set CHROME_DEBUG_BIND to override." >&2
114
- ;;
115
- esac
116
-
117
- # Preflight: a concrete non-loopback bind needs an ncat forwarder (see
118
- # ensure_forwarder). Check ncat now, before launching Chrome, so a missing tool
119
- # fails fast instead of orphaning a browser window. Skip it if a forwarder from
120
- # a previous run is already serving the bind.
121
- case "$BIND" in
122
- 127.0.0.1 | ::1 | 0.0.0.0 | ::) ;;
123
- *)
124
- if ! curl -s -m 2 "http://${BIND}:${PORT}/json/version" >/dev/null 2>&1 \
125
- && ! command -v ncat >/dev/null 2>&1; then
126
- echo "chrome-host: error: this run must expose Chrome's CDP port ${PORT} on ${BIND} via an" >&2
127
- echo "chrome-host: ncat forwarder, but 'ncat' is not installed. Install ncat (the 'nmap-ncat'" >&2
128
- echo "chrome-host: or 'nmap' package, depending on your distro)." >&2
129
- exit 1
130
- fi
131
- ;;
132
- esac
133
-
134
- # Profile is always per-project and not configurable. COMPOSE_PROJECT_NAME comes
135
- # from .env (or your shell); fall back to the repo directory name, like Compose.
136
- PROJECT="${COMPOSE_PROJECT_NAME:-$(basename "$env_root")}"
137
- PROFILE="$HOME/.chrome-debug-profile-$PROJECT"
138
-
139
- find_chrome() {
140
- if [ -n "${CHROME_BIN:-}" ]; then
141
- printf '%s\n' "$CHROME_BIN"
142
- return 0
143
- fi
144
- case "$(uname -s)" in
145
- Darwin)
146
- for candidate in \
147
- "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" \
148
- "/Applications/Google Chrome Beta.app/Contents/MacOS/Google Chrome Beta" \
149
- "/Applications/Chromium.app/Contents/MacOS/Chromium" \
150
- "/Applications/Microsoft Edge.app/Contents/MacOS/Microsoft Edge"; do
151
- if [ -x "$candidate" ]; then
152
- printf '%s\n' "$candidate"
153
- return 0
154
- fi
155
- done
156
- ;;
157
- *)
158
- for candidate in google-chrome google-chrome-stable chromium chromium-browser microsoft-edge brave-browser; do
159
- resolved="$(command -v "$candidate" 2>/dev/null || true)"
160
- if [ -n "$resolved" ]; then
161
- printf '%s\n' "$resolved"
162
- return 0
163
- fi
164
- done
165
- ;;
166
- esac
167
- return 1
168
- }
169
-
170
- # Headed Chromium pins DevTools to 127.0.0.1 and silently ignores
171
- # --remote-debugging-address (Fedora's build, among others), so the launcher no
172
- # longer passes that flag: Chrome always binds loopback, and ensure_forwarder
173
- # spawns an ncat hop on $BIND:$PORT to expose it for the container. Loopback and
174
- # wildcard binds need no hop -- loopback is already reachable, and a wildcard
175
- # would collide with Chrome's own loopback port.
176
- ensure_forwarder() {
177
- bind=$1
178
- port=$2
179
- pidfile=$3
180
-
181
- case "$bind" in 127.0.0.1 | ::1 | 0.0.0.0 | ::) return 0 ;; esac
182
-
183
- mkdir -p "$(dirname "$pidfile")"
184
-
185
- # A reachable bind:port means a forwarder from a previous run still serves it
186
- # (Chrome itself only binds loopback), so reuse it.
187
- if curl -s -m 2 "http://${bind}:${port}/json/version" >/dev/null 2>&1; then
188
- echo "chrome-host: forwarder already serving ${bind}:${port}"
189
- return 0
190
- fi
191
-
192
- if ! command -v ncat >/dev/null 2>&1; then
193
- echo "chrome-host: error: Chrome bound CDP to loopback only and 'ncat' is not installed." >&2
194
- echo "chrome-host: install ncat (the 'nmap-ncat' or 'nmap' package, depending on your distro)" >&2
195
- echo "chrome-host: so a host-side forwarder can expose ${port} on ${bind} for the container." >&2
196
- return 1
197
- fi
198
-
199
- if [ -f "$pidfile" ]; then
200
- kill "$(cat "$pidfile")" 2>/dev/null || true
201
- rm -f "$pidfile"
202
- fi
203
-
204
- log=${pidfile%.pid}.log
205
- nohup ncat -k -l "$bind" "$port" --sh-exec "ncat 127.0.0.1 $port" >"$log" 2>&1 &
206
- echo $! >"$pidfile"
207
-
208
- j=0
209
- while [ "$j" -lt 20 ]; do
210
- if curl -s -m 2 "http://${bind}:${port}/json/version" >/dev/null 2>&1; then
211
- echo "chrome-host: forwarder ${bind}:${port} -> 127.0.0.1:${port} (pid $(cat "$pidfile"))"
212
- return 0
213
- fi
214
- j=$((j + 1))
215
- sleep 0.5
216
- done
217
-
218
- echo "chrome-host: error: forwarder failed to bind ${bind}:${port}; see $log" >&2
219
- return 1
220
- }
221
-
222
- if curl -s -m 2 "http://127.0.0.1:${PORT}/json/version" >/dev/null 2>&1; then
223
- echo "chrome-host: debug Chrome already running on 127.0.0.1:${PORT}"
224
- ensure_forwarder "$BIND" "$PORT" "$PROFILE/forwarder.pid" || exit 1
225
- exit 0
226
- fi
227
-
228
- CHROME="$(find_chrome || true)"
229
- if [ -z "${CHROME:-}" ]; then
230
- echo "chrome-host: error: no Chrome/Chromium found. Set CHROME_BIN=/path/to/browser and retry." >&2
231
- exit 1
232
- fi
233
-
234
- mkdir -p "$PROFILE"
235
-
236
- # Build the argument list (quote the glob so the shell doesn't expand '*').
237
- # --ignore-certificate-errors skips the "Your connection is not private"
238
- # interstitial for local HTTPS dev servers with a self-signed/absent cert.
239
- # Acceptable here: this is a dedicated, isolated debug profile, not your
240
- # everyday browser.
241
- set -- \
242
- --remote-debugging-port="$PORT" \
243
- '--remote-allow-origins=*' \
244
- --user-data-dir="$PROFILE" \
245
- --no-first-run \
246
- --no-default-browser-check \
247
- --ignore-certificate-errors
248
- set -- "$@" --new-window "http://localhost:${COMPOSE_DOCS_SERVER_PORT:-8000}"
249
-
250
- nohup "$CHROME" "$@" >"$PROFILE/chrome-debug.log" 2>&1 &
251
-
252
- i=0
253
- while [ "$i" -lt 30 ]; do
254
- if curl -s -m 2 "http://127.0.0.1:${PORT}/json/version" >/dev/null 2>&1; then
255
- echo "chrome-host: debug Chrome ready on 127.0.0.1:${PORT}"
256
- echo "chrome-host: binary: $CHROME"
257
- echo "chrome-host: profile: $PROFILE"
258
- echo "chrome-host: log: $PROFILE/chrome-debug.log"
259
- ensure_forwarder "$BIND" "$PORT" "$PROFILE/forwarder.pid" || exit 1
260
- exit 0
261
- fi
262
- i=$((i + 1))
263
- sleep 0.5
264
- done
265
-
266
- echo "chrome-host: error: Chrome did not expose CDP on 127.0.0.1:${PORT}; see $PROFILE/chrome-debug.log" >&2
267
- exit 1