@pokutuna/mcp-chrome-tabs 0.2.0 → 0.3.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 pokutuna
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -7,7 +7,7 @@ Model Context Protocol (MCP) server that provides direct access to your browser'
7
7
  ## Key Features
8
8
 
9
9
  - **Direct browser tab access** - No web scraping needed, reads content from already open tabs
10
- - **Content optimized for AI** - Automatic readability processing and markdown conversion to reduce token usage
10
+ - **Content optimized for AI** - Automatic content extraction and markdown conversion to reduce token usage
11
11
  - **Active tab shortcut** - Instant access to currently focused tab without specifying IDs
12
12
  - **MCP listChanged notifications** - Follows MCP protocol to notify tab changes (support is limited in most clients)
13
13
 
@@ -1,7 +1,5 @@
1
- import { JSDOM } from "jsdom";
2
- import { Readability } from "@mozilla/readability";
3
- import TurndownService from "turndown";
4
- import turndownPluginGfm from "turndown-plugin-gfm";
1
+ import { Defuddle } from "defuddle/node";
2
+ import { withMockConsole } from "../util.js";
5
3
  import { escapeAppleScript, executeAppleScript, separator, } from "./osascript.js";
6
4
  async function getChromeTabList(applicationName) {
7
5
  const sep = separator();
@@ -82,23 +80,23 @@ async function getPageContent(applicationName, tab) {
82
80
  return "ERROR" & "${sep}" & errMsg
83
81
  end try
84
82
  `;
85
- const result = await executeAppleScript(appleScript);
86
- if (result.startsWith(`ERROR${sep}`))
87
- throw new Error(result.split(sep)[1]);
88
- const parts = result.split(sep).map((part) => part.trim());
89
- if (parts.length < 3)
83
+ const scriptResult = await executeAppleScript(appleScript);
84
+ if (scriptResult.startsWith(`ERROR${sep}`)) {
85
+ throw new Error(scriptResult.split(sep)[1]);
86
+ }
87
+ const parts = scriptResult.split(sep).map((part) => part.trim());
88
+ if (parts.length < 3) {
90
89
  throw new Error("Failed to read the tab content");
90
+ }
91
91
  const [title, url, content] = parts;
92
- const dom = new JSDOM(content, { url });
93
- const reader = new Readability(dom.window.document, {
94
- charThreshold: 10,
95
- });
96
- const article = reader.parse();
97
- if (!article?.content)
92
+ // Suppress defuddle's console.log output during parsing
93
+ const { result: defuddleResult } = await withMockConsole(() => Defuddle(content, url, {
94
+ markdown: true,
95
+ }));
96
+ if (!defuddleResult?.content) {
98
97
  throw new Error("Failed to parse the page content");
99
- const turndownService = new TurndownService();
100
- turndownService.use(turndownPluginGfm.gfm);
101
- const md = turndownService.turndown(article.content);
98
+ }
99
+ const md = defuddleResult.content;
102
100
  return {
103
101
  title,
104
102
  url,
@@ -2,6 +2,7 @@ import { execFile } from "child_process";
2
2
  import { promisify } from "util";
3
3
  const execFileAsync = promisify(execFile);
4
4
  export function escapeAppleScript(str) {
5
+ // https://discussions.apple.com/thread/4247426?sortBy=rank
5
6
  return str
6
7
  .replace(/\\/g, "\\\\")
7
8
  .replace(/"/g, '\\"')
@@ -9,7 +10,7 @@ export function escapeAppleScript(str) {
9
10
  .replace(/\r/g, "\\r");
10
11
  }
11
12
  export async function retry(fn, options) {
12
- const { maxRetries = 2, retryDelay = 1000 } = options || {};
13
+ const { maxRetries = 1, retryDelay = 1000 } = options || {};
13
14
  for (let attempt = 0; attempt <= maxRetries; attempt++) {
14
15
  try {
15
16
  return await fn();
@@ -1,7 +1,5 @@
1
- import { JSDOM } from "jsdom";
2
- import { Readability } from "@mozilla/readability";
3
- import TurndownService from "turndown";
4
- import turndownPluginGfm from "turndown-plugin-gfm";
1
+ import { Defuddle } from "defuddle/node";
2
+ import { withMockConsole } from "../util.js";
5
3
  import { escapeAppleScript, executeAppleScript, separator, } from "./osascript.js";
6
4
  async function getSafariTabList(applicationName) {
7
5
  const sep = separator();
@@ -82,23 +80,23 @@ async function getPageContent(applicationName, tab) {
82
80
  return "ERROR" & "${sep}" & errMsg
83
81
  end try
84
82
  `;
85
- const result = await executeAppleScript(appleScript);
86
- if (result.startsWith(`ERROR${sep}`))
87
- throw new Error(result.split(sep)[1]);
88
- const parts = result.split(sep).map((part) => part.trim());
89
- if (parts.length < 3)
83
+ const scriptResult = await executeAppleScript(appleScript);
84
+ if (scriptResult.startsWith(`ERROR${sep}`)) {
85
+ throw new Error(scriptResult.split(sep)[1]);
86
+ }
87
+ const parts = scriptResult.split(sep).map((part) => part.trim());
88
+ if (parts.length < 3) {
90
89
  throw new Error("Failed to read the tab content");
90
+ }
91
91
  const [title, url, content] = parts;
92
- const dom = new JSDOM(content, { url });
93
- const reader = new Readability(dom.window.document, {
94
- charThreshold: 10,
95
- });
96
- const article = reader.parse();
97
- if (!article?.content)
92
+ // Suppress defuddle's console.log output during parsing
93
+ const { result: defuddleResult } = await withMockConsole(() => Defuddle(content, url, {
94
+ markdown: true,
95
+ }));
96
+ if (!defuddleResult?.content) {
98
97
  throw new Error("Failed to parse the page content");
99
- const turndownService = new TurndownService();
100
- turndownService.use(turndownPluginGfm.gfm);
101
- const md = turndownService.turndown(article.content);
98
+ }
99
+ const md = defuddleResult.content;
102
100
  return {
103
101
  title,
104
102
  url,
package/dist/cli.js CHANGED
@@ -94,11 +94,21 @@ function parseCliArgs(args) {
94
94
  };
95
95
  return parsed;
96
96
  }
97
- const options = parseCliArgs(process.argv.slice(2));
98
- if (options.help) {
99
- showHelp();
100
- process.exit(0);
97
+ async function main() {
98
+ const options = parseCliArgs(process.argv.slice(2));
99
+ if (options.help) {
100
+ showHelp();
101
+ process.exit(0);
102
+ }
103
+ const server = await createMcpServer(options);
104
+ const transport = new StdioServerTransport();
105
+ await server.connect(transport);
106
+ const shutdown = async () => {
107
+ await transport.close();
108
+ await server.close();
109
+ process.exit(0);
110
+ };
111
+ process.on("SIGINT", shutdown);
112
+ process.on("SIGTERM", shutdown);
101
113
  }
102
- const server = await createMcpServer(options);
103
- const transport = new StdioServerTransport();
104
- await server.connect(transport);
114
+ await main().catch(console.error);
package/dist/util.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export declare function withMockConsole<T>(fn: () => Promise<T>): Promise<{
2
+ result: T;
3
+ logs: unknown[][];
4
+ }>;
package/dist/util.js ADDED
@@ -0,0 +1,14 @@
1
+ export async function withMockConsole(fn) {
2
+ const originalConsoleLog = console.log;
3
+ const logs = [];
4
+ console.log = (...args) => {
5
+ logs.push(args);
6
+ };
7
+ try {
8
+ const result = await fn();
9
+ return { result, logs };
10
+ }
11
+ finally {
12
+ console.log = originalConsoleLog;
13
+ }
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pokutuna/mcp-chrome-tabs",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/pokutuna/mcp-chrome-tabs"
@@ -23,21 +23,20 @@
23
23
  "lint:fix": "prettier --write .",
24
24
  "prepublishOnly": "npm run build",
25
25
  "start": "node dist/index.js",
26
- "test": "vitest",
27
- "test:run": "vitest run"
26
+ "test": "vitest run",
27
+ "test:watch": "vitest",
28
+ "test:e2e": "playwright test"
28
29
  },
29
30
  "dependencies": {
30
31
  "@modelcontextprotocol/sdk": "^1.16.0",
31
- "@mozilla/readability": "^0.6.0",
32
- "jsdom": "^26.1.0",
33
- "turndown": "^7.2.0",
34
- "turndown-plugin-gfm": "^1.0.2",
32
+ "defuddle": "^0.6.4",
33
+ "jsdom": "^24.0.0",
35
34
  "zod": "^3.25.76"
36
35
  },
37
36
  "devDependencies": {
38
- "@types/jsdom": "^21.1.7",
37
+ "@playwright/test": "^1.54.1",
39
38
  "@types/node": "^20.11.17",
40
- "@types/turndown": "^5.0.5",
39
+ "playwright": "^1.54.1",
41
40
  "prettier": "^3.6.2",
42
41
  "tsx": "^4.7.1",
43
42
  "typescript": "~5.8.3",