javascript - 如何在 Linux/Mac/Windows 上的 Node/Electron 应用程序中获取浏览器事件选项卡 URL?

标签 javascript node.js linux firefox electron

我正在寻找一种智能方式来获取跨平台 Electron 应用程序的事件浏览器 URL。我找到了一个针对 Mac OS Safari 和 Chrome 使用 AppleScript 的解决方案,但仍然没有针对 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`,
}

最佳答案

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

关于javascript - 如何在 Linux/Mac/Windows 上的 Node/Electron 应用程序中获取浏览器事件选项卡 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47510161/

相关文章:

javascript - ID 未提交查询

javascript - React Native 如何知道我的默认类名?

javascript - 为什么 Components.classes 未定义?

node.js - 设置Nodejs WebRTC视频通话,并且Turn/ICE失败,CORS被阻止

python - 为什么 TravisCI 找不到我的许可证文件?

c - 多处理器系统上的线程

javascript - 使用javascript执行服务器端ruby文件

javascript - 从 Nodejs 流中删除或更改原始数据

node.js - NodeJS SQL Server - 如何使用将返回一个 promise 的数组输入参数进行查询

linux - 在使用 Git 提交之前检查代码中的注释以获取消息