You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TestCafe中聚焦iframe时focusin事件冒泡至主页面问题咨询

补充说明:此为Bug,已提交至相关Issue

我有一个包含iframe子元素的容器div,该div设置了tabindex="-1"并监听focusin事件。

测试场景

测试模拟点击iframe内部的按钮,该iframe是container-div的子元素。

<button>random button</button>
<div class="container-div" tabindex="-1">
 <iframe id="iframe" /> <!--- with button el inside -->
</div>
containerDiv.addEventListener('focusin', () => console.log('focusin fired'))
test("Dont fire focusin event", async (t) => {
  await t
    .switchToIframe(`.container-div #iframe`)
    .click("button");
  await t.switchToMainWindow();
  const { error, log } = await t.getBrowserConsoleMessages();
  log.forEach((log) => console.log(log));
  await t.debug();
});

当前行为

focusin事件被触发,控制台打印出"focusin fired"

预期行为

在非测试浏览器中聚焦iframe时,focusin事件不会冒泡至主页面,因此container-div元素不应触发focusin事件。

环境信息

  • "testcafe": "^2.2.0"
  • node v18.12.1
let os = require("os");

const path = "tests";
module.exports = {
  skipJsErrors: false,
  hostname: os.hostname(),
  browsers: ["chrome"],
  src: [
    `${path}/iframes.ts`,
  ],
  speed: 1,
  current: 1,

};

内容的提问来源于stack exchange,提问作者Caleb Taylor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 06:35:45