大网数据广告活动
Web 标准与前端开发

`session.unsubscribe` command

· 52CE 我爱测

The `session.unsubscribe` command of the `session` module cancels event subscriptions previously registered with `session.subscribe`, either by subscription ID or by event name.

The session.unsubscribe command of the session module cancels event subscriptions previously registered with session.subscribe, either by subscription ID or by event name.

Syntax

/* Using event name */
{
  "method": "session.unsubscribe",
  "params": {
    "events": ["log.entryAdded"]
  }
}

/* Using subscription ID */
{
  "method": "session.unsubscribe",
  "params": {
    "subscriptions": ["a1b2c3d4-e5f6-7890-abcd-ef1234567890"]
  }
}

Parameters

The params field contains one of the following fields:

  • events
    • : An array of one or more strings that specifies event names for canceling subscriptions. Each string can be either a specific event name (for example, "log.entryAdded") or a module name (for example, "log") that unsubscribes the client from all events in that module. Only global subscriptions can be removed using event names; those created using contexts or userContexts cannot be.
  • subscriptions
    • : An array of one or more subscription IDs that specifies the subscriptions to cancel, including both global and context-scoped subscriptions.

Return value

The result field in the response is an empty object ({}).

Errors

  • invalid argument
    • : When unsubscribing using IDs, a subscription ID is not found. When unsubscribing using event names, the events array is empty or omitted, or an event name does not match any active global subscription.

Examples

Unsubscribing using a subscription ID

With an active subscription, send the following message to cancel it by ID:

{
  "id": 3,
  "method": "session.unsubscribe",
  "params": {
    "subscriptions": ["c7b7b3a2-1f4b-4b4e-8a1f-2a3b4c5d6e7f"]
  }
}

After successfully unsubscribing, the browser responds as follows:

{
  "id": 3,
  "type": "success",
  "result": {}
}

Unsubscribing from an event globally using an event name

With a global subscription to log.entryAdded active, send the following message to stop receiving that event:

{
  "id": 4,
  "method": "session.unsubscribe",
  "params": {
    "events": ["log.entryAdded"]
  }
}

After successfully unsubscribing, the browser responds as follows:

{
  "id": 4,
  "type": "success",
  "result": {}
}

Unsubscribing from multiple events globally using event names

With global subscriptions active, send the following message to unsubscribe from all events in the log module and a specific event from the network module:

{
  "id": 5,
  "method": "session.unsubscribe",
  "params": {
    "events": ["log", "network.beforeRequestSent"]
  }
}

After successfully unsubscribing, the browser responds as follows:

{
  "id": 5,
  "type": "success",
  "result": {}
}

Specifications

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。