我正在寻找一种智能方式来获取跨平台 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/