fix: auto-close tabs after command, add login requirement reminders
- browser.ts: close all tabs opened during session (not just extension tabs)
uses _initialTabCount to restore Chrome to pre-command state
- README/README.zh-CN: add ⚠️ login requirement warning with examples
- SKILL.md: add login note and tab auto-close mention
This commit is contained in:
1 parent
129df91247
commit
fd94a5d27b
4 files changed
+18
-12
No files matched your search
@@ -55,7 +55,7 @@ npm install -g @jackwener/opencli@latest
|
||||
## 📋 Prerequisites
|
||||
|
||||
Browser commands need:
|
||||
1. **Chrome** running with the target site logged in
|
||||
1. **Chrome** running **and logged into the target site** (e.g. bilibili.com, zhihu.com, xiaohongshu.com)
|
||||
2. **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** extension installed
|
||||
3. Configure `PLAYWRIGHT_MCP_EXTENSION_TOKEN` (from the extension settings page) as an environment variable, or in your MCP config:
|
||||
|
||||
@@ -75,6 +75,8 @@ Browser commands need:
|
||||
|
||||
Public API commands (`hackernews`, `github search`, `v2ex`) need no browser at all.
|
||||
|
||||
> **⚠️ Important**: Browser commands reuse your Chrome login session. You must be logged into the target website in Chrome before running commands. If you get empty data or errors, check your login status first.
|
||||
|
||||
## 📦 Built-in Commands
|
||||
|
||||
| Site | Commands | Mode |
|
||||
|
||||
+3
-1
@@ -55,7 +55,7 @@ npm install -g @jackwener/opencli@latest
|
||||
## 📋 前置要求
|
||||
|
||||
浏览器命令需要:
|
||||
1. **Chrome** 浏览器正在运行,且已登录目标网站
|
||||
1. **Chrome** 浏览器正在运行,且**已登录目标网站**(如 bilibili.com、zhihu.com、xiaohongshu.com)
|
||||
2. 安装 **[Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm)** 扩展
|
||||
3. 配置 `PLAYWRIGHT_MCP_EXTENSION_TOKEN`(从扩展设置页获取),设为环境变量或写入 MCP 配置:
|
||||
|
||||
@@ -75,6 +75,8 @@ npm install -g @jackwener/opencli@latest
|
||||
|
||||
公共 API 命令(`hackernews`、`github search`、`v2ex`)无需浏览器。
|
||||
|
||||
> **⚠️ 重要**:浏览器命令复用你的 Chrome 登录状态。运行命令前,你必须已在 Chrome 中登录目标网站。如果获取到空数据或报错,请先检查登录状态。
|
||||
|
||||
## 📦 内置命令
|
||||
|
||||
| 站点 | 命令 | 模式 |
|
||||
|
||||
@@ -28,10 +28,12 @@ npm update -g @jackwener/opencli
|
||||
## Prerequisites
|
||||
|
||||
Browser commands require:
|
||||
1. Chrome browser running (logged into target sites)
|
||||
1. Chrome browser running **(logged into target sites)**
|
||||
2. [Playwright MCP Bridge](https://chromewebstore.google.com/detail/playwright-mcp-bridge/mmlmfjhmonkocbjadbfplnigmagldckm) extension
|
||||
3. Configure `PLAYWRIGHT_MCP_EXTENSION_TOKEN` env var (from extension settings) or in MCP config
|
||||
|
||||
> **Note**: You must be logged into the target website in Chrome before running commands. Tabs opened during command execution are auto-closed afterwards.
|
||||
|
||||
Public API commands (`hackernews`, `github search`, `v2ex`) need no browser.
|
||||
|
||||
## Commands Reference
|
||||
|
||||
+9
-9
@@ -199,19 +199,19 @@ export class PlaywrightMCP {
|
||||
|
||||
async close(): Promise<void> {
|
||||
try {
|
||||
// Close extension tab(s) opened during this session
|
||||
// Close tabs opened during this session (site tabs + extension tabs)
|
||||
if (this._page && this._proc && !this._proc.killed) {
|
||||
try {
|
||||
const tabs = await this._page.tabs();
|
||||
const tabStr = typeof tabs === 'string' ? tabs : JSON.stringify(tabs);
|
||||
// Find and close chrome-extension:// tabs (opened by MCP Bridge)
|
||||
const tabMatches = tabStr.match(/Tab (\d+).*?chrome-extension:\/\//g);
|
||||
if (tabMatches) {
|
||||
for (const match of tabMatches) {
|
||||
const idx = match.match(/Tab (\d+)/)?.[1];
|
||||
if (idx) {
|
||||
try { await this._page.closeTab(parseInt(idx)); } catch {}
|
||||
}
|
||||
const allTabs = tabStr.match(/Tab (\d+)/g) || [];
|
||||
const currentTabCount = allTabs.length;
|
||||
|
||||
// Close tabs in reverse order to avoid index shifting issues
|
||||
// Keep the original tabs that existed before the command started
|
||||
if (currentTabCount > this._initialTabCount && this._initialTabCount > 0) {
|
||||
for (let i = currentTabCount - 1; i >= this._initialTabCount; i--) {
|
||||
try { await this._page.closeTab(i); } catch {}
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
|
||||
Reference in new issue
Block a user