mcp-web-inspector 0.4.0 → 0.4.1

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.
@@ -5,6 +5,7 @@ import { getToolInstance, isBrowserTool, executeTool } from './tools/common/regi
5
5
  let browser;
6
6
  let page;
7
7
  let currentBrowserType = 'chromium';
8
+ let currentDevice;
8
9
  let networkLog = [];
9
10
  let sessionConfig = {
10
11
  saveSession: false,
@@ -39,6 +40,7 @@ export function resetBrowserState() {
39
40
  browser = undefined;
40
41
  page = undefined;
41
42
  currentBrowserType = 'chromium';
43
+ currentDevice = undefined;
42
44
  networkLog = [];
43
45
  }
44
46
  /**
@@ -308,6 +310,17 @@ export async function ensureBrowser(browserSettings) {
308
310
  // Reset browser and page references
309
311
  resetBrowserState();
310
312
  }
313
+ // Check if device preset has changed (requires browser restart)
314
+ if (browser && browserSettings?.device && browserSettings.device !== currentDevice) {
315
+ console.error(`Device preset changed from ${currentDevice || 'none'} to ${browserSettings.device}. Restarting browser...`);
316
+ try {
317
+ await browser.close().catch(err => console.error("Error closing browser on device change:", err));
318
+ }
319
+ catch (e) {
320
+ // Ignore errors when closing browser
321
+ }
322
+ resetBrowserState();
323
+ }
311
324
  // If browser exists and viewport settings changed, resize the viewport
312
325
  if (browser && page && !page.isClosed() && browserSettings?.viewport) {
313
326
  const { width, height } = browserSettings.viewport;
@@ -344,11 +357,16 @@ export async function ensureBrowser(browserSettings) {
344
357
  deviceConfig = CUSTOM_DEVICE_CONFIGS[playwrightDeviceName] || devices[playwrightDeviceName];
345
358
  if (deviceConfig) {
346
359
  console.error(`Using device preset: ${device} (${playwrightDeviceName})`);
360
+ currentDevice = device;
347
361
  }
348
362
  else {
349
363
  console.error(`Warning: Device preset ${playwrightDeviceName} not found`);
364
+ currentDevice = undefined;
350
365
  }
351
366
  }
367
+ else {
368
+ currentDevice = undefined;
369
+ }
352
370
  console.error(`Launching new ${browserType} browser instance...`);
353
371
  // Use the appropriate browser engine
354
372
  let browserInstance;
@@ -487,6 +505,15 @@ export async function ensureBrowser(browserSettings) {
487
505
  const playwrightDeviceName = DEVICE_PRESETS[device];
488
506
  // Check custom configs first, then Playwright's built-in devices
489
507
  deviceConfig = CUSTOM_DEVICE_CONFIGS[playwrightDeviceName] || devices[playwrightDeviceName];
508
+ if (deviceConfig) {
509
+ currentDevice = device;
510
+ }
511
+ else {
512
+ currentDevice = undefined;
513
+ }
514
+ }
515
+ else {
516
+ currentDevice = undefined;
490
517
  }
491
518
  // Use the appropriate browser engine
492
519
  let browserInstance;
@@ -14,7 +14,7 @@ export class ScreenshotTool extends BrowserToolBase {
14
14
  const screenshotsDir = sessionConfig?.screenshotsDir || './.mcp-web-inspector/screenshots';
15
15
  return {
16
16
  name: "screenshot",
17
- description: `⚠️ RARELY NEEDED: Screenshots are NOT useful for LLMs to analyze layouts, margins, or alignment issues. Use inspect_dom(), compare_positions(), or measure_element() instead - they provide precise numerical data. Only take screenshots for: (1) sharing with humans for visual confirmation, (2) documenting test results, or (3) verifying colors/images. Screenshots are saved to ${screenshotsDir}. Example: { name: "login-page", fullPage: true } or { name: "submit-btn", selector: "testid:submit" }`,
17
+ description: `📸 VISUAL OUTPUT TOOL - Captures page/element appearance and saves to file. Essential for: visual regression testing, sharing with humans, confirming UI appearance (colors/fonts/images). ⚠️ NOT for layout debugging (positions/sizes/alignment/margins) - use inspect_dom/compare_positions/inspect_ancestors/get_computed_styles instead (structural data is token-efficient, screenshots require ~1,500 tokens to read). Screenshots saved to ${screenshotsDir}. Example: { name: "login-page", fullPage: true } or { name: "submit-btn", selector: "testid:submit" }`,
18
18
  inputSchema: {
19
19
  type: "object",
20
20
  properties: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-web-inspector",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
4
4
  "description": "Web Inspector MCP: Give LLMs visual superpowers to see, debug, and test any web page.",
5
5
  "license": "MIT",
6
6
  "author": "Anton",