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

`browsingContext.traverseHistory` command

· 52CE 我爱测

The `browsingContext.traverseHistory` command of the `browsingContext` module navigates back or forward in the session history of the specified top-level context, similar to a user clicking the browser's back and forward buttons.

The browsingContext.traverseHistory command of the browsingContext module navigates back or forward in the session history of the specified top-level context, similar to a user clicking the browser's back and forward buttons.

Syntax

{
  "method": "browsingContext.traverseHistory",
  "params": {
    "context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "delta": -1
  }
}

Parameters

The params field contains:

  • context
  • delta
    • : An integer that specifies the number of history entries to move in the session history. A positive value moves the context forward in history; a negative value moves it backward.

Return value

The result field in the response is an empty object ({}). The command returns once the traversal has been queued, before the resulting navigation is complete. The browsingContext.historyUpdated event fires when the traversal is complete.

Errors

  • invalid argument
    • : A required parameter is missing or has an invalid type. This error is also returned when the specified context is not a top-level context.
  • no such frame
    • : No context with the given context ID is found.
  • no such history entry
    • : The position in the session history specified by delta does not exist.

Examples

Navigating back in history

Assume you have a WebDriver BiDi connection and an active session.

Suppose you created a tab using browsingContext.create and navigated it through several pages using browsingContext.navigate: from https://example.com/page1.html to https://example.com/page2.html, and then to https://example.com/page3.html. To navigate two history entries back, that is, to skip https://example.com/page2.html and land at https://example.com/page1.html, send the following message:

{
  "id": 1,
  "method": "browsingContext.traverseHistory",
  "params": {
    "context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
    "delta": -2
  }
}

The browser queues the history traversal and responds as follows:

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

Navigating forward in history

Continuing from the previous example, to navigate one history entry forward, landing at https://example.com/page2.html, send the following message:

{
  "id": 2,
  "method": "browsingContext.traverseHistory",
  "params": {
    "context": "5e5e96e8-5247-4f22-9b35-a4a2d841cbaa",
    "delta": 1
  }
}

The browser queues the history traversal and responds as follows:

{
  "id": 2,
  "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

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

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