browser-console-mcp 1.0.4 → 1.0.5

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.
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Copy browser-inject.js to dist/browser directory
3
+ */
4
+
5
+ import fs from "node:fs";
6
+ import path from "node:path";
7
+ import { fileURLToPath } from "node:url";
8
+
9
+ // Get current file directory
10
+ const __filename = fileURLToPath(import.meta.url);
11
+ const __dirname = path.dirname(__filename);
12
+ const projectRoot = path.resolve(__dirname, "..");
13
+
14
+ // Source file path
15
+ const sourcePath = path.join(
16
+ projectRoot,
17
+ "src",
18
+ "browser",
19
+ "browser-inject.js",
20
+ );
21
+
22
+ // Target directory
23
+ const targetDir = path.join(projectRoot, "dist", "browser");
24
+ const targetPath = path.join(targetDir, "browser-inject.js");
25
+
26
+ // Ensure target directory exists
27
+ function ensureDirectoryExists(dirPath) {
28
+ if (!fs.existsSync(dirPath)) {
29
+ fs.mkdirSync(dirPath, { recursive: true });
30
+ console.log(`Creating directory: ${dirPath}`);
31
+ }
32
+ }
33
+
34
+ // Copy file
35
+ function copyFile(source, target) {
36
+ try {
37
+ if (!fs.existsSync(source)) {
38
+ console.error(`Error: Source file not found: ${source}`);
39
+ process.exit(1);
40
+ }
41
+
42
+ const data = fs.readFileSync(source);
43
+ fs.writeFileSync(target, data);
44
+ console.log(`File copied successfully: ${source} -> ${target}`);
45
+ } catch (error) {
46
+ console.error(`Failed to copy file: ${error.message}`);
47
+ process.exit(1);
48
+ }
49
+ }
50
+
51
+ // Execute copy
52
+ console.log("Starting to copy browser-inject.js...");
53
+ ensureDirectoryExists(targetDir);
54
+ copyFile(sourcePath, targetPath);
55
+ console.log("browser-inject.js copy completed");
@@ -61,6 +61,25 @@ function copyFile(source, target) {
61
61
  const data = fs.readFileSync(source);
62
62
  fs.writeFileSync(target, data);
63
63
  console.log(`File copied successfully: ${source} -> ${target}`);
64
+
65
+ const duplicatePath = path.join(
66
+ targetDir,
67
+ "html2canvas",
68
+ "dist",
69
+ "html2canvas.min.js",
70
+ );
71
+ const duplicateDir = path.dirname(duplicatePath);
72
+
73
+ if (fs.existsSync(duplicatePath)) {
74
+ fs.unlinkSync(duplicatePath);
75
+
76
+ try {
77
+ fs.rmdirSync(duplicateDir);
78
+ fs.rmdirSync(path.dirname(duplicateDir));
79
+ } catch (e) {
80
+ // Ignore non-empty directory error
81
+ }
82
+ }
64
83
  } catch (error) {
65
84
  console.error(`Failed to copy file: ${error.message}`);
66
85
  // Don't exit process, just warn
@@ -1,34 +1,34 @@
1
1
  /**
2
- * Browser MCP 注入脚本
2
+ * Browser MCP Injection Script
3
3
  *
4
- * 这个脚本用于在浏览器中注入MCP客户端
4
+ * This script is used to inject the MCP client in the browser
5
5
  */
6
6
 
7
7
  (() => {
8
- // 检查是否已经加载了MCP客户端
8
+ // Check if MCP client is already loaded
9
9
  if (window.mcp) {
10
- console.log("[Browser MCP] MCP客户端已加载");
10
+ console.log("[BCM] MCP client already loaded");
11
11
  return;
12
12
  }
13
13
 
14
- // 获取当前脚本的URL,以确定服务器地址
14
+ // Get current script URL to determine server address
15
15
  const currentScript = document.currentScript;
16
16
  const scriptUrl = currentScript ? currentScript.src : "";
17
17
  const serverUrl = scriptUrl
18
18
  ? new URL(scriptUrl).origin
19
19
  : "http://localhost:7898";
20
20
 
21
- // 加载MCP客户端脚本
21
+ // Load MCP client script
22
22
  const script = document.createElement("script");
23
23
  script.src = `${serverUrl}/browser-console-mcp.js`;
24
24
  script.onload = () => {
25
- console.log("[Browser MCP] MCP客户端加载成功");
25
+ console.log("[BCM] MCP client loaded successfully");
26
26
  };
27
27
  script.onerror = (error) => {
28
- console.error("[Browser MCP] MCP客户端加载失败:", error);
28
+ console.error("[BCM] Failed to load MCP client:", error);
29
29
  };
30
30
 
31
31
  document.head.appendChild(script);
32
32
 
33
- console.log("[Browser MCP] 正在加载MCP客户端...");
33
+ console.log("[BCM] Loading MCP client...");
34
34
  })();