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

Viewed 1590

I am looking for a smart way to get active browser URL for a cross-platform electron app. I have found a solution using AppleScript for Mac OS Safari and Chrome but still no solution for Firefox, Windows, and Linux :(

A solution for Chrome and Safari on MacOS using AppleScript:

Using node-applescript I was able to get safari and chrome URLs. Unfortunately, Firefox does not support AppleScript and the way to obtain the URL is hacky and unusable in production. Also, I still have no clue how to get the URLs on Linux and Windows.

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`,
}
1 Answers
Related