@mozilla/firefox-devtools-mcp 0.9.3

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 (31) hide show
  1. package/LICENSE-APACHE +172 -0
  2. package/LICENSE-MIT +22 -0
  3. package/README.md +219 -0
  4. package/dist/index.js +33246 -0
  5. package/dist/snapshot.injected.global.js +1 -0
  6. package/package.json +116 -0
  7. package/plugins/claude/firefox-devtools/.claude-plugin/plugin.json +11 -0
  8. package/plugins/claude/firefox-devtools/.mcp.json +8 -0
  9. package/plugins/claude/firefox-devtools/README.md +82 -0
  10. package/plugins/claude/firefox-devtools/agents/e2e-tester.md +36 -0
  11. package/plugins/claude/firefox-devtools/agents/web-scraper.md +35 -0
  12. package/plugins/claude/firefox-devtools/commands/debug.md +32 -0
  13. package/plugins/claude/firefox-devtools/commands/navigate.md +31 -0
  14. package/plugins/claude/firefox-devtools/commands/screenshot.md +30 -0
  15. package/plugins/claude/firefox-devtools/skills/browser-automation/SKILL.md +65 -0
  16. package/scripts/_helpers/page-loader.js +121 -0
  17. package/scripts/demo-server.js +325 -0
  18. package/scripts/generate-moz-package.mjs +35 -0
  19. package/scripts/publish-moz-package.mjs +44 -0
  20. package/scripts/run-integration-tests-windows.mjs +188 -0
  21. package/scripts/setup-mcp-config.js +260 -0
  22. package/scripts/test-bidi-devtools.js +380 -0
  23. package/scripts/test-console.js +148 -0
  24. package/scripts/test-dialog.js +102 -0
  25. package/scripts/test-firefox-temp.js +21 -0
  26. package/scripts/test-input-tools.js +233 -0
  27. package/scripts/test-lifecycle-hooks.js +125 -0
  28. package/scripts/test-mozlog.js +112 -0
  29. package/scripts/test-navigation.js +57 -0
  30. package/scripts/test-privileged-context.js +99 -0
  31. package/scripts/test-screenshot.js +190 -0
package/LICENSE-APACHE ADDED
@@ -0,0 +1,172 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included
37
+ in or attached to the work (an example is provided in the Appendix
38
+ below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean, as defined in Section 5, any work of
49
+ authorship, including the original version of the Work and any
50
+ modifications or additions to that Work or Derivative Works of the
51
+ Work, that is intentionally submitted to the Licensor for inclusion
52
+ in the Work by the copyright owner or by an individual or Legal Entity
53
+ authorized to submit on behalf of the copyright owner. For the purposes
54
+ of this definition, "submitted" means any form of electronic, verbal,
55
+ or written communication sent to the Licensor or its representatives,
56
+ including but not limited to communication on electronic mailing lists,
57
+ source code control systems, and issue tracking systems that are managed
58
+ by, or on behalf of, the Licensor for the purpose of discussing and
59
+ improving the Work, but excluding communication that is conspicuously
60
+ marked or otherwise designated in writing by the copyright owner as
61
+ "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
64
+ whom a Contribution has been received by the Licensor and incorporated
65
+ within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable by
80
+ such Contributor that are necessarily infringed by their Contribution(s)
81
+ alone or by combination of their Contribution(s) with the Work to which
82
+ such Contribution(s) was submitted. If You institute patent litigation
83
+ against any entity (including a cross-claim or counterclaim in a
84
+ lawsuit) alleging that the Work or any Contribution embodied within
85
+ the Work constitutes direct or contributory patent infringement, then
86
+ any patent licenses granted to You under this License for that Work
87
+ shall terminate as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the Work
90
+ or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or Derivative
95
+ Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, You must include a readable copy of the
108
+ attribution notices contained within such NOTICE file, in
109
+ at least one of the following places: within a NOTICE text
110
+ file distributed as part of the Derivative Works; within
111
+ the Source form or documentation, if provided along with the
112
+ Derivative Works; or, within a display generated by the
113
+ Derivative Works, if and wherever such third-party notices
114
+ normally appear. The contents of the NOTICE file are for
115
+ informational purposes only and do not modify the License.
116
+ You may add Your own attribution notices within Derivative
117
+ Works that You distribute, alongside or as an addendum to
118
+ the NOTICE text from the Work, provided that such additional
119
+ attribution notices cannot be construed as modifying the
120
+ License.
121
+
122
+ You may add Your own license statement for Your modifications and
123
+ may provide additional grant of rights to use, copy, modify, merge,
124
+ publish, distribute, sublicense, and/or sell copies of the Work.
125
+
126
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
127
+ any Contribution intentionally submitted for inclusion in the Work
128
+ by You to the Licensor shall be under the terms and conditions of
129
+ this License, without any additional terms or conditions.
130
+ Notwithstanding the above, nothing herein shall supersede or modify
131
+ the terms of any separate license agreement you may have executed
132
+ with Licensor regarding such Contributions.
133
+
134
+ 6. Trademarks. This License does not grant permission to use the trade
135
+ names, trademarks, service marks, or product names of the Licensor,
136
+ except as required for reasonable and customary use in describing the
137
+ origin of the Work and reproducing the content of the NOTICE file.
138
+
139
+ 7. Disclaimer of Warranty. Unless required by applicable law or
140
+ agreed to in writing, Licensor provides the Work (and each
141
+ Contributor provides its Contributions) on an "AS IS" BASIS,
142
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
143
+ implied, including, without limitation, any warranties or conditions
144
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
145
+ PARTICULAR PURPOSE. You are solely responsible for determining the
146
+ appropriateness of using or reproducing the Work and assume any
147
+ risks associated with Your exercise of permissions under this License.
148
+
149
+ 8. Limitation of Liability. In no event and under no legal theory,
150
+ whether in tort (including negligence), contract, or otherwise,
151
+ unless required by applicable law (such as deliberate and grossly
152
+ negligent acts) or agreed to in writing, shall any Contributor be
153
+ liable to You for damages, including any direct, indirect, special,
154
+ incidental, or exemplary damages of any character arising as a
155
+ result of this License or out of the use or inability to use the
156
+ Work (including but not limited to damages for loss of goodwill,
157
+ work stoppage, computer failure or malfunction, or all other
158
+ commercial damages or losses), even if such Contributor has been
159
+ advised of the possibility of such damages.
160
+
161
+ 9. Accepting Warranty or Additional Liability. While redistributing
162
+ the Work or Derivative Works thereof, You may choose to offer,
163
+ and charge a fee for, acceptance of support, warranty, indemnity,
164
+ or other liability obligations and rights consistent with this
165
+ License. However, in accepting such obligations, You may offer such
166
+ obligations only on Your own behalf and on Your sole responsibility,
167
+ not on behalf of any other Contributor, and only if You agree to
168
+ indemnify, defend, and hold each Contributor harmless for any liability
169
+ incurred by, or claims asserted against, such Contributor by reason of
170
+ your accepting any such warranty or additional liability.
171
+
172
+ END OF TERMS AND CONDITIONS
package/LICENSE-MIT ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Tomáš Grasl
4
+ Copyright (c) 2025–2026 Mozilla and Firefox DevTools MCP Contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # Firefox DevTools MCP
2
+
3
+ [![npm version](https://badge.fury.io/js/firefox-devtools-mcp.svg)](https://www.npmjs.com/package/firefox-devtools-mcp)
4
+ [![CI](https://github.com/mozilla/firefox-devtools-mcp/workflows/CI/badge.svg)](https://github.com/mozilla/firefox-devtools-mcp/actions/workflows/ci.yml)
5
+ [![codecov](https://codecov.io/gh/mozilla/firefox-devtools-mcp/branch/main/graph/badge.svg)](https://codecov.io/gh/mozilla/firefox-devtools-mcp)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE-MIT) [![License: Apache 2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE-APACHE)
7
+
8
+ <a href="https://glama.ai/mcp/servers/@mozilla/firefox-devtools-mcp"><img src="https://glama.ai/mcp/servers/@mozilla/firefox-devtools-mcp/badge" height="223" alt="Glama"></a>
9
+
10
+ Model Context Protocol server for automating Firefox via WebDriver BiDi (through Selenium WebDriver). Works with Claude Code, Claude Desktop, Cursor, Cline and other MCP clients.
11
+
12
+ Repository: https://github.com/mozilla/firefox-devtools-mcp
13
+
14
+ > **Note**: This MCP server requires a local Firefox browser installation and cannot run on cloud hosting services like glama.ai. Use `npx firefox-devtools-mcp@latest` to run locally, or use Docker with the provided Dockerfile.
15
+
16
+ ## Security
17
+
18
+ Browser MCP servers carry inherent risks. A few key practices:
19
+
20
+ - **Use a dedicated Firefox profile.** Never run the server against your regular profile — the agent has access to whatever the browser can reach, including cookies and saved sessions.
21
+ - **Be cautious about which sites you visit.** Pages can return content designed to manipulate the agent (prompt injection). Stick to sites you control or trust.
22
+ - **Avoid enabling extra flags unless needed.** `--enable-script` and `--enable-privileged-context` significantly expand what the agent can do.
23
+
24
+ See [SECURITY.md](SECURITY.md) for a full breakdown of risks and how to report vulnerabilities.
25
+
26
+ ## Requirements
27
+
28
+ - Node.js ≥ 20.19.0
29
+ - Firefox 100+ installed (auto‑detected, or pass `--firefox-path`)
30
+
31
+ ## Install and use with Claude Code (npx)
32
+
33
+ Recommended: use npx so you always run the latest published version from npm.
34
+
35
+ Option A — Claude Code CLI
36
+
37
+ ```bash
38
+ claude mcp add firefox-devtools npx firefox-devtools-mcp@latest
39
+ ```
40
+
41
+ Pass options either as args or env vars. Examples:
42
+
43
+ ```bash
44
+ # Headless + viewport via args
45
+ claude mcp add firefox-devtools npx firefox-devtools-mcp@latest -- --headless --viewport 1280x720
46
+
47
+ # Or via environment variables
48
+ claude mcp add firefox-devtools npx firefox-devtools-mcp@latest \
49
+ --env START_URL=https://example.com \
50
+ --env FIREFOX_HEADLESS=true
51
+ ```
52
+
53
+ Option B — Edit Claude Code settings JSON
54
+
55
+ Add to your Claude Code config file:
56
+
57
+ - macOS: `~/Library/Application Support/Claude/Code/mcp_settings.json`
58
+ - Linux: `~/.config/claude/code/mcp_settings.json`
59
+ - Windows: `%APPDATA%\Claude\Code\mcp_settings.json`
60
+
61
+ ```json
62
+ {
63
+ "mcpServers": {
64
+ "firefox-devtools": {
65
+ "command": "npx",
66
+ "args": ["-y", "firefox-devtools-mcp@latest", "--headless", "--viewport", "1280x720"],
67
+ "env": {
68
+ "START_URL": "about:home"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ```
74
+
75
+ Option C — Helper script (local dev build)
76
+
77
+ ```bash
78
+ npm run setup
79
+ # Choose Claude Code; the script saves JSON to the right path
80
+ ```
81
+
82
+ ## Try it with MCP Inspector
83
+
84
+ ```bash
85
+ npx @modelcontextprotocol/inspector npx firefox-devtools-mcp@latest --start-url https://example.com --headless
86
+ ```
87
+
88
+ Then call tools like:
89
+
90
+ - `list_pages`, `select_page`, `navigate_page`
91
+ - `take_snapshot` then `click_by_uid` / `fill_by_uid`
92
+ - `list_network_requests` (always‑on capture), `get_network_request`
93
+ - `screenshot_page`, `list_console_messages`
94
+
95
+ ## CLI options
96
+
97
+ You can pass flags or environment variables (names on the right):
98
+
99
+ - `--firefox-path` — absolute path to Firefox binary
100
+ - `--headless` — run without UI (`FIREFOX_HEADLESS=true`)
101
+ - `--viewport 1280x720` — initial window size
102
+ - `--profile-path` — use a specific Firefox profile
103
+ - `--firefox-arg` — extra Firefox arguments (repeatable)
104
+ - `--start-url` — open this URL on start (`START_URL`)
105
+ - `--accept-insecure-certs` — ignore TLS errors (`ACCEPT_INSECURE_CERTS=true`)
106
+ - `--connect-existing` — attach to an already-running Firefox instead of launching a new one (`CONNECT_EXISTING=true`)
107
+ - `--marionette-port` — Marionette port for connect-existing mode, default 2828 (`MARIONETTE_PORT`)
108
+ - `--pref name=value` — set Firefox preference at startup via `moz:firefoxOptions` (repeatable)
109
+ - `--enable-script` — enable the `evaluate_script` tool, which executes arbitrary JavaScript in the page context (`ENABLE_SCRIPT=true`)
110
+ - `--enable-privileged-context` — enable privileged context tools: list/select privileged contexts, evaluate privileged scripts, get/set Firefox prefs, and list extensions. Requires `MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1` (`ENABLE_PRIVILEGED_CONTEXT=true`)
111
+
112
+ > **Note on `--pref`:** When Firefox runs in automation, it applies [RecommendedPreferences](https://searchfox.org/firefox-main/source/remote/shared/RecommendedPreferences.sys.mjs) that modify browser behavior for testing. The `--pref` option allows overriding these defaults when needed.
113
+
114
+ ### Connect to existing Firefox
115
+
116
+ Use `--connect-existing` to automate your real browsing session — with cookies, logins, and open tabs intact:
117
+
118
+ ```bash
119
+ # Start Firefox with Marionette enabled
120
+ firefox --marionette
121
+
122
+ # Run the MCP server
123
+ npx firefox-devtools-mcp --connect-existing --marionette-port 2828
124
+ ```
125
+
126
+ Or set `marionette.enabled` to `true` in `about:config` (or `user.js`) to enable Marionette on every launch.
127
+
128
+ BiDi-dependent features (console events, network events) are not available in connect-existing mode; all other features work normally.
129
+
130
+ > **Warning:** Do not leave Marionette enabled during normal browsing. It sets
131
+ > `navigator.webdriver = true` and changes other browser fingerprint signals,
132
+ > which can trigger bot detection on sites protected by Cloudflare, Akamai, etc.
133
+ > Only enable Marionette when you need MCP automation, then restart Firefox
134
+ > normally afterward.
135
+
136
+ ## Tool overview
137
+
138
+ - Pages: list/new/navigate/select/close
139
+ - Snapshot/UID: take/resolve/clear
140
+ - Input: click/hover/fill/drag/upload/form fill
141
+ - Network: list/get (ID‑first, filters, always‑on capture)
142
+ - Console: list/clear
143
+ - Screenshot: page/by uid (with optional `saveTo` for CLI environments)
144
+ - Script: evaluate_script
145
+ - Privileged Context: list/select privileged ("chrome") contexts, evaluate_privileged_script (requires `MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1`)
146
+ - WebExtension: install_extension, uninstall_extension, list_extensions (list requires `MOZ_REMOTE_ALLOW_SYSTEM_ACCESS=1`)
147
+ - Firefox Management: get_firefox_info, get_firefox_output, restart_firefox, set_firefox_prefs, get_firefox_prefs
148
+ - Utilities: accept/dismiss dialog, history back/forward, set viewport
149
+
150
+ ### Screenshot optimization for Claude Code
151
+
152
+ When using screenshots in Claude Code CLI, the base64 image data can consume significant context.
153
+ Use the `saveTo` parameter to save screenshots to disk instead:
154
+
155
+ ```
156
+ screenshot_page({ saveTo: "/tmp/page.png" })
157
+ screenshot_by_uid({ uid: "abc123", saveTo: "/tmp/element.png" })
158
+ ```
159
+
160
+ The file can then be viewed with Claude Code's `Read` tool without impacting context size.
161
+
162
+ ## Local development
163
+
164
+ ```bash
165
+ npm install
166
+ npm run build
167
+
168
+ # Run with Inspector against local build
169
+ npx @modelcontextprotocol/inspector node dist/index.js --headless --viewport 1280x720
170
+
171
+ # Or run in dev with hot reload
172
+ npm run inspector:dev
173
+ ```
174
+
175
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for more details on local development, testing, and CI.
176
+
177
+ ## Troubleshooting
178
+
179
+ - Firefox not found: pass `--firefox-path "/Applications/Firefox.app/Contents/MacOS/firefox"` (macOS) or the correct path on your OS.
180
+ - First run is slow: Selenium sets up the BiDi session; subsequent runs are faster.
181
+ - Stale UIDs after navigation: take a fresh snapshot (`take_snapshot`) before using UID tools.
182
+ - Windows 10: Error during discovery for MCP server 'firefox-devtools': MCP error -32000: Connection closed
183
+ - **Solution 1** Wrap with `cmd /c` ([details](https://github.com/modelcontextprotocol/servers/issues/1082#issuecomment-2791786310)):
184
+
185
+ ```json
186
+ "mcpServers": {
187
+ "firefox-devtools": {
188
+ "command": "cmd",
189
+ "args": ["/c", "npx", "-y", "firefox-devtools-mcp@latest"]
190
+ }
191
+ }
192
+ ```
193
+
194
+ - **Solution 2** Use the absolute path to `npx` (adjust extension — `.cmd`, `.bat`, `.exe`, or `.ps1` — to match your setup):
195
+
196
+ ```json
197
+ "mcpServers": {
198
+ "firefox-devtools": {
199
+ "command": "C:\\nvm4w\\nodejs\\npx.ps1",
200
+ "args": ["-y", "firefox-devtools-mcp@latest"]
201
+ }
202
+ }
203
+ ```
204
+
205
+ ## Versioning
206
+
207
+ - Pre‑1.0 API: versions start at `0.x`. Use `@latest` with npx for the newest release.
208
+
209
+ ## Contributing
210
+
211
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for how to file issues, run tests, and work on the project locally.
212
+
213
+ ## Author
214
+
215
+ Maintained by [Mozilla](https://www.mozilla.org).
216
+
217
+ ## License
218
+
219
+ Licensed under either of [MIT](LICENSE-MIT) or [Apache 2.0](LICENSE-APACHE) at your option.