【问题标题】:How to get browser active tab URL in node/electron app on Linux/Mac/Windows?如何在 Linux/Mac/Windows 上的节点/电子应用程序中获取浏览器活动选项卡 URL?
【发布时间】:2018-05-10 15:30:29
【问题描述】:

我正在寻找一种智能方法来获取跨平台电子应用程序的活动浏览器 URL。我找到了一个使用 AppleScript for Mac OS Safari 和 Chrome 的解决方案,但仍然没有适用于 Firefox、Windows 和 Linux 的解决方案:(

在 MacOS 上使用 AppleScript 的 Chrome 和 Safari 解决方案:

使用 node-applescript 我能够获得 safari 和 chrome 网址。不幸的是,Firefox 不支持 AppleScript,而且获取 URL 的方式很麻烦,无法在生产环境中使用。此外,我仍然不知道如何在 Linux 和 Windows 上获取 URL。

const scripts = {
  'chrome': `tell application "Google Chrome" to get URL of active tab of front window as string`,
  'vivaldi': `tell application "Vivaldi" to return URL of active tab of front window`,
  'safari': `tell application "Safari" to return URL of front document as string`,
  'firefox': `tell application "Firefox" to activate
  tell application "System Events"
    keystroke "l" using command down
    keystroke "c" using command down
  end tell
  delay 0.5
  return the clipboard`,
}

【问题讨论】:

  • 您好,请问您有什么解决方案吗...
  • 恐怕不行。还在寻找...
  • 嗨,你找到解决办法了吗?
  • 任何人都有解决方案

标签: javascript node.js linux firefox electron


【解决方案1】:

对于 Linux,请尝试命令 wmctrl。如果网页上没有标题标签,wmctrl 应该在标题栏中显示完整的 url。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 2011-05-09
    • 2012-07-23
    • 1970-01-01
    相关资源
    最近更新 更多