繁体   English   中英

如何在Linux / Mac / Windows上的节点/电子应用程序中获取浏览器活动标签URL?

[英]How to get browser active tab URL in node/electron app on Linux/Mac/Windows?

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

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

使用node-applescript我能够获得safari和chrome URL。 不幸的是,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应该在标题栏中显示完整的网址。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM