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

关于windows.create弹窗定位、非模态设置及alwaysOnTop异常的技术咨询

Hey there, let's unpack your two questions with what I know about browser extension window APIs, especially since you're migrating an older Chrome project:

1. Why windows.create() top/left properties fail to position the window (it stays centered)

This boils down to modern Chromium browser (Chrome/Edge/etc.) behavior changes and built-in restrictions, especially when creating windows with type: "popup":

  • Popup type constraints: Chromium prioritizes user experience for popup windows by automatically centering small-sized popups, ignoring explicit top/left values. This is a deliberate change from older Chrome versions where popups allowed free positioning.
  • Window state defaults: If you don't explicitly set state: "normal", the browser might fall back to default popup positioning rules that override your coordinates.
  • Screen visibility checks: The browser will adjust your top/left values if the window would be partially or fully off-screen, which can sometimes result in centering as a fallback.

To make top/left work as expected, try switching the window type to "normal" (instead of "popup") and explicitly set state: "normal", along with a reasonable window size (avoid tiny dimensions that trigger auto-centering). Example:

browser.windows.create({
  url: "your-popup.html",
  type: "normal",
  state: "normal",
  top: 150,
  left: 200,
  width: 450,
  height: 350
});

2. Can the popup be non-modal, and why does alwaysOnTop return false but the window stays on top?

Non-modal setup

Yes, you can make it non-modal, but you need to adjust the window type:

  • Windows created with type: "popup" have built-in modal-like behavior in modern Chromium—they're forced to stay above their parent context (like the extension's background page or the tab that triggered them). To get a non-modal window that can be covered by other apps/windows, use type: "normal" instead. This matches the non-modal behavior you had in older Chrome versions.

The alwaysOnTop discrepancy

The reason alwaysOnTop returns false but the window stays on top is because:

  • For type: "popup" windows, Chromium enforces a "stays above parent" rule independently of the alwaysOnTop property. The API returns false because your explicit setting is ignored by the browser's internal popup handling logic. When you switch to type: "normal", the alwaysOnTop property will work as expected—set it to false and the window will no longer stay pinned on top.

Putting this together, here's a code snippet for a non-modal, positionable window:

const nonModalWindow = await browser.windows.create({
  url: "your-content.html",
  type: "normal",
  state: "normal",
  top: 100,
  left: 100,
  width: 400,
  height: 300,
  alwaysOnTop: false
});
// Now nonModalWindow.alwaysOnTop will correctly reflect your setting, and the window won't stay pinned

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 06:45:25