7

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`,
}
4
  • Hi, did you get any solution for this ... Feb 4, 2018 at 16:44
  • I am afraid not. Still looking... Feb 5, 2018 at 6:41
  • Hi, have you found any solution?
    – zxch3n
    Nov 12, 2019 at 5:58
  • any one has solution for this
    – jan_kiran
    Oct 12, 2021 at 7:51

1 Answer 1

1

For Linux try command wmctrl. if there is no title tag on the web page, wmctrl should show you full url in the title bar.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.