Skip to content

Commit 4aba7c3

Browse files
chkp-ronizclaude
andcommitted
fix(cli): add Edge-not-found error handling and document --browser option
- Wrap launch_persistent_context to catch missing Edge with a helpful message pointing to microsoft.com/edge - Document --browser option in docs/cli-reference.md (Session: login) - Add test for Edge-not-installed error path Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d0aa720 commit 4aba7c3

File tree

3 files changed

+56
-3
lines changed

3 files changed

+56
-3
lines changed

docs/cli-reference.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ See [Configuration](configuration.md) for details on environment variables and C
3838

3939
| Command | Description | Example |
4040
|---------|-------------|---------|
41-
| `login` | Authenticate via browser | `notebooklm login` |
41+
| `login` | Authenticate via browser | `notebooklm login` / `notebooklm login --browser msedge` |
4242
| `use <id>` | Set active notebook | `notebooklm use abc123` |
4343
| `status` | Show current context | `notebooklm status` |
4444
| `status --paths` | Show configuration paths | `notebooklm status --paths` |
@@ -232,11 +232,24 @@ These CLI capabilities are not available in NotebookLM's web interface:
232232
Authenticate with Google NotebookLM via browser.
233233

234234
```bash
235-
notebooklm login
235+
notebooklm login [OPTIONS]
236236
```
237237

238238
Opens a Chromium browser with a persistent profile. Log in to your Google account, then press Enter in the terminal to save the session.
239239

240+
**Options:**
241+
- `--storage PATH` - Where to save storage_state.json (default: `$NOTEBOOKLM_HOME/storage_state.json`)
242+
- `--browser [chromium|msedge]` - Browser to use for login (default: `chromium`). Use `msedge` for Microsoft Edge.
243+
244+
**Examples:**
245+
```bash
246+
# Default (Chromium)
247+
notebooklm login
248+
249+
# Use Microsoft Edge (for orgs that require Edge for SSO)
250+
notebooklm login --browser msedge
251+
```
252+
240253
### Session: `use`
241254

242255
Set the active notebook for subsequent commands.

src/notebooklm/cli/session.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,21 @@ def login(storage, browser):
227227
if browser == "msedge":
228228
launch_kwargs["channel"] = "msedge"
229229

230-
context = p.chromium.launch_persistent_context(**launch_kwargs)
230+
try:
231+
context = p.chromium.launch_persistent_context(**launch_kwargs)
232+
except Exception as e:
233+
if browser == "msedge" and (
234+
"executable doesn't exist" in str(e).lower()
235+
or "no such file" in str(e).lower()
236+
or "failed to launch" in str(e).lower()
237+
):
238+
console.print(
239+
"[red]Microsoft Edge not found.[/red]\n"
240+
"Install from: https://www.microsoft.com/edge\n"
241+
"Or use the default Chromium browser: notebooklm login"
242+
)
243+
raise SystemExit(1) from None
244+
raise
231245

232246
page = context.pages[0] if context.pages else context.new_page()
233247
page.goto(NOTEBOOKLM_URL)

tests/unit/cli/test_session.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,32 @@ def test_login_chromium_default_no_channel(self, runner, mock_login_browser):
148148
mock_ensure.assert_called_once()
149149
assert "channel" not in mock_launch.call_args[1]
150150

151+
def test_login_msedge_not_installed_shows_helpful_error(self, runner, tmp_path):
152+
"""Test --browser msedge shows helpful error when Edge is not installed."""
153+
with (
154+
patch("notebooklm.cli.session._ensure_chromium_installed"),
155+
patch("playwright.sync_api.sync_playwright") as mock_pw,
156+
patch(
157+
"notebooklm.cli.session.get_storage_path", return_value=tmp_path / "storage.json"
158+
),
159+
patch(
160+
"notebooklm.cli.session.get_browser_profile_dir",
161+
return_value=tmp_path / "profile",
162+
),
163+
):
164+
mock_launch = (
165+
mock_pw.return_value.__enter__.return_value.chromium.launch_persistent_context
166+
)
167+
mock_launch.side_effect = Exception(
168+
"Executable doesn't exist at /ms-edge\nFailed to launch"
169+
)
170+
171+
result = runner.invoke(cli, ["login", "--browser", "msedge"])
172+
173+
assert result.exit_code == 1
174+
assert "Microsoft Edge not found" in result.output
175+
assert "microsoft.com/edge" in result.output
176+
151177

152178
# =============================================================================
153179
# USE COMMAND TESTS

0 commit comments

Comments
 (0)