mcp-browser-dev-tools 0.0.1-beta.6 → 0.0.1-beta.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-browser-dev-tools",
3
- "version": "0.0.1-beta.6",
3
+ "version": "0.0.1-beta.7",
4
4
  "description": "Local MCP server for Chromium DevTools Protocol and Firefox WebDriver BiDi",
5
5
  "author": "Hinaser <rindo.hinase@gmail.com>",
6
6
  "type": "module",
@@ -349,6 +349,7 @@ export class FirefoxBidiSessionManager {
349
349
  this.capabilities = null;
350
350
  this.connectPromise = null;
351
351
  this.resolvedWebSocketUrl = null;
352
+ this.deleteSessionUrl = null;
352
353
  }
353
354
 
354
355
  async ensureConnected() {
@@ -374,6 +375,7 @@ export class FirefoxBidiSessionManager {
374
375
  async openConnection() {
375
376
  const endpoint = await this.resolveConnectionEndpoint();
376
377
  this.resolvedWebSocketUrl = endpoint.webSocketUrl;
378
+ this.deleteSessionUrl = endpoint.deleteSessionUrl ?? null;
377
379
  this.websocket = this.websocketFactory(endpoint.webSocketUrl);
378
380
 
379
381
  await new Promise((resolve, reject) => {
@@ -453,6 +455,7 @@ export class FirefoxBidiSessionManager {
453
455
  requiresSessionNew: true,
454
456
  sessionId: null,
455
457
  capabilities: null,
458
+ deleteSessionUrl: null,
456
459
  };
457
460
  }
458
461
 
@@ -495,9 +498,49 @@ export class FirefoxBidiSessionManager {
495
498
  requiresSessionNew: false,
496
499
  sessionId,
497
500
  capabilities,
501
+ deleteSessionUrl: joinUrlPath(sessionUrl, sessionId).toString(),
498
502
  };
499
503
  }
500
504
 
505
+ async waitForWebSocketClose(websocket, timeoutMs = 250) {
506
+ if (!websocket || websocket.readyState === WebSocket.CLOSED) {
507
+ return;
508
+ }
509
+
510
+ await new Promise((resolve) => {
511
+ let settled = false;
512
+ const done = () => {
513
+ if (settled) {
514
+ return;
515
+ }
516
+ settled = true;
517
+ resolve();
518
+ };
519
+
520
+ websocket.addEventListener("close", done, { once: true });
521
+ const timer = setTimeout(done, timeoutMs);
522
+ timer.unref?.();
523
+ });
524
+ }
525
+
526
+ async closeBrowserSession() {
527
+ if (!this.browserSessionId) {
528
+ return;
529
+ }
530
+
531
+ if (this.deleteSessionUrl) {
532
+ await this.fetchImpl(this.deleteSessionUrl, {
533
+ method: "DELETE",
534
+ signal: AbortSignal.timeout(2_000),
535
+ }).catch(() => {});
536
+ return;
537
+ }
538
+
539
+ if (this.websocket?.readyState === WebSocket.OPEN) {
540
+ await this.send("session.end", {}).catch(() => {});
541
+ }
542
+ }
543
+
501
544
  rejectPending(error) {
502
545
  for (const pending of this.pending.values()) {
503
546
  pending.reject(error);
@@ -1019,10 +1062,20 @@ export class FirefoxBidiSessionManager {
1019
1062
  ),
1020
1063
  );
1021
1064
 
1022
- if (this.websocket && this.websocket.readyState < WebSocket.CLOSING) {
1023
- this.websocket.close();
1065
+ const websocket = this.websocket;
1066
+
1067
+ await this.closeBrowserSession();
1068
+
1069
+ if (websocket && websocket.readyState < WebSocket.CLOSING) {
1070
+ websocket.close();
1071
+ await this.waitForWebSocketClose(websocket);
1024
1072
  }
1025
1073
 
1026
1074
  this.sessions.clear();
1075
+ this.websocket = null;
1076
+ this.browserSessionId = null;
1077
+ this.capabilities = null;
1078
+ this.resolvedWebSocketUrl = null;
1079
+ this.deleteSessionUrl = null;
1027
1080
  }
1028
1081
  }