我能以某种方式监听 URL 用户正在使用 Firefox 插件 SDK 进行输入吗?

Can I somehow listen on the URL user is typing with Firefox addon SDK?

当用户在位置字段中输入时,Firefox Add-on SDK 是否可以获取 URL?

是也不是。是的,这是可能的,但不在 SDK 标准内 API。

  1. 您需要枚举顶级浏览器 windows(又名。键入 navigator:browserchrome://browser/content/browser.xul)。 window/utils::windows() may help here, but it has the drawback that it will not notify you about new windows. However, you can use require("chrome") and nsIWindowWatcher.registerNotification 为此。
  2. 进入浏览器后 windows,只需使用常用的 addEventListener DOM API 添加常用的按键事件侦听器即可。您要查找的 browser.xul 中的 DOM 元素是 #urlbar.
  3. 由于 SDK 加载项无需重新启动,并且您将离开 managed 领域,使用低级 APIs,您需要在之后进行清理自己卸载,例如再次删除所有事件侦听器或观察器并恢复您触摸的任何内容。