【发布时间】: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