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

`browsingContext.contextCreated` event

· 52CE 我爱测

The `browsingContext.contextCreated` event of the `browsingContext` module fires when a new context is created in the browser.

The browsingContext.contextCreated event of the browsingContext module fires when a new context is created in the browser.

Event data

The params field in the event notification is an object with the following fields:

  • children
  • clientWindow
    • : A string that contains the ID of the client window that contains this context.
  • context
    • : A string that contains the ID of the newly created context.
  • originalOpener
    • : A string that contains the ID of the context that originally opened this context. The value is null if the context was opened directly (not by another context).
  • parent
    • : A string that contains the ID of the parent context. The value is null if the context has no parent (that is, it is a top-level context).
  • url
    • : A string that contains the URL of the context, including the fragment, at the time it was created. For newly created contexts, the value is "about:blank" because the event fires before any navigation has occurred and content has loaded. For existing contexts at subscription time, the value reflects their current URL.
  • userContext
    • : A string that contains the ID of the user context associated with this context.

Description

When you subscribe to this event, the browser immediately fires the event recursively for all contexts that already exist at the time of subscription, starting from top-level contexts down through their children.

If the subscription was scoped to specific contexts using the contexts parameter, only child contexts created within those contexts will fire the event.

Examples

Receiving an event for a new tab

Assume you have a WebDriver BiDi connection, an active session, and a subscription to browsingContext.contextCreated active.

When your automation script creates a tab using browsingContext.create, the browser sends the following notification:

{
  "type": "event",
  "method": "browsingContext.contextCreated",
  "params": {
    "context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "children": null,
    "originalOpener": null,
    "url": "about:blank",
    "userContext": "default",
    "clientWindow": "08c697a1-2664-447d-9c88-52bcee3bb386",
    "parent": null
  }
}

Receiving an event for a child context

Assume you have a WebDriver BiDi connection, an active session, and a subscription to browsingContext.contextCreated active.

Suppose a page containing an <iframe> loads. The browser sends the following notification for the new child context:

{
  "type": "event",
  "method": "browsingContext.contextCreated",
  "params": {
    "context": "6442450945",
    "children": null,
    "originalOpener": null,
    "url": "about:blank",
    "userContext": "default",
    "clientWindow": "08c697a1-2664-447d-9c88-52bcee3bb386",
    "parent": "93ee5bd6-d256-4608-a002-9a8995cc0e5f"
  }
}

Identifying the opener of a context

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

Consider a scenario where two tabs are already open: Tab 1 at https://example.com/page1.html, and Tab 2 at https://example.com/page2.html, which was opened from Tab 1 using window.open(). When you subscribe to browsingContext.contextCreated, the browser fires events for the two existing contexts. The originalOpener field in Tab 2's notification identifies the context that opened it.

The browser sends the following notification for Tab 1:

{
  "type": "event",
  "method": "browsingContext.contextCreated",
  "params": {
    "context": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "children": null,
    "originalOpener": null,
    "url": "https://example.com/page1.html",
    "userContext": "default",
    "clientWindow": "08c697a1-2664-447d-9c88-52bcee3bb386",
    "parent": null
  }
}

This is immediately followed by the notification for Tab 2:

{
  "type": "event",
  "method": "browsingContext.contextCreated",
  "params": {
    "context": "32ed30da-24ad-459d-8f0d-660526e92d96",
    "children": null,
    "originalOpener": "93ee5bd6-d256-4608-a002-9a8995cc0e5f",
    "url": "https://example.com/page2.html",
    "userContext": "default",
    "clientWindow": "08c697a1-2664-447d-9c88-52bcee3bb386",
    "parent": null
  }
}

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

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

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