sindresorhus / get-windows

Get metadata about the active window and open windows (title, id, bounds, owner, etc)
MIT License
798 stars 166 forks source link

I am not able to capture URLs in Firefox browser #172

Open raghavnaphade opened 1 year ago

vojtabohm commented 4 months ago

This is because it does not work with the approach this library uses (which is to use AppleScript to 'tell' the browser to return it's url). I solved this a while ago on my macOS project. You can actually use Accessibility API to get it.

  1. You need to set AXManualAccessibility on the Firefox process, which will enable it's DOM to be visible (this property tells the app a 'Screen reader' is present on the screen, so this is a sort of a hack).
  2. Traverse the Firefox's DOM (consisting of AXUIElement) using BFS until you find a node that has a url attribute and read that.

It's a hassle to add this, but unfortunately, no better way to do this for Firefox. I read their forums a while back.

jntstewart commented 2 months ago

@vojtabohm, hope you are doing well! Have you recently tested if your approach still works? I have tried setting AXManualAccessibility to true on the Firefox process, but get errors both on AppleScript and Swift. Thanks.

vojtabohm commented 2 months ago

Hey @jntstewart. I haven't tried it in a while but if I remember, even though it returned errors, it still worked.

I found one forum link I checked in the past. They say Firefox actually needs the AXEnhancedUserInterface attribute. But I believe some other people reported this attribute breaks window behavior on some other apps...

Just try it, experiment with these two attributes. I also remember I had a delay of 3 seconds after an app was opened (to wait for it to load) before I toggled these attributes.

Some combination of these things worked for Firefox in the end.