GithubHelp home page GithubHelp logo

Get url from browser about active-win HOT 9 CLOSED

sindresorhus avatar sindresorhus commented on April 28, 2024
Get url from browser

from active-win.

Comments (9)

sindresorhus avatar sindresorhus commented on April 28, 2024

That is app specific. On macOS, you could use AppleScript to get. On other systems, I have no idea.

https://stackoverflow.com/questions/2483033/get-the-url-of-the-frontmost-tab-from-chrome-on-os-x

from active-win.

uffou avatar uffou commented on April 28, 2024

Thanks for pointing me in the right direction!

I ended up using node applescript
which works perfectly. I am pasting my apple scripts incase someone else is looking for the same thing.

safari and chrome work perfectly. 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 = {
  'itunes': `tell application "iTunes" to get {name, artist, album} of current track`,
  'spotify': `tell application "Spotify" to get {name, artist, album} of current track`,
  '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`,
}

from active-win.

starsoftmongolia avatar starsoftmongolia commented on April 28, 2024

@uffou Did you solve your your problem ? I also need to detect URL of active window in Windows.
If you have a solution, please share it ?

from active-win.

tiangolo avatar tiangolo commented on April 28, 2024

There isn't a standard way to get the URL from a browser that works in all operating systems.

There are some possible "hacks" and scripts for macOS only.

Probably, the best way to solve it, while trying to be as "cross-platform" as possible, would be with a browser extension. That extension could talk to your Electron app via a local Electron (Node.js) server. Or it could talk directly to your backend server.

An extension is just JS. And I understand Firefox and Edge were about to support the same extension formats and APIs as Chrome, so you would probably be able to have only one code base. But I'm not aware of how that went.

Also, I understand that in Windows you can set a key in the registry that tells Chrome to install an extension the next time it opens, or something similar. I'm not sure how it works for macOS or Ubuntu (although Ubuntu is my main OS...)

from active-win.

starsoftmongolia avatar starsoftmongolia commented on April 28, 2024

Ok, then i will try to use OCR solution. We can get top side screenshot of active window and try to detect characters from image, i think it will be easiest way to solve my problem. I only need website domain name.

from active-win.

sindresorhus avatar sindresorhus commented on April 28, 2024

This is now available in the latest version: https://github.com/sindresorhus/active-win/releases/tag/v6.1.0

from active-win.

bharat303 avatar bharat303 commented on April 28, 2024

Any solution for getting URL of current browser tab in windows ???

from active-win.

creaz35 avatar creaz35 commented on April 28, 2024

Following up on windows thanks!

from active-win.

sachinsrinivas12 avatar sachinsrinivas12 commented on April 28, 2024

Can anyone say how can I get URL for active window in "Windows"?

from active-win.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.