Jump to content

"Frontmost browser" automations don't work from other active apps


Recommended Posts

I'd like to get the title and url of the active tab in the frontmost browser, using the automation task "Get Current Frontmost Browser Tab".

 

I expected the automation to detect which browser is frontmost, no matter what app is active, but it doesn't seem to work that way.

 

For example, if I make a simple workflow with a keyword to trigger "Get Current Frontmost Browser Tab", and trigger it from the Alfred UI, the debugger shows

 

[Automation Task] Task Error: ../../../../com.alfredapp.automation.core/safari/.common/tabs-current: execution error: Error: Error: Alfred Preferences is not a supported browser: Safari, Webkit, Orion, Google Chrome, Chromium, Opera, Vivaldi, Brave Browser, Microsoft Edge, Arc (-2700)

 

Is that expected? It seems like it would be more useful for the automation task, and others like it, to find open browsers in the background, find the frontmost one, and get its active tab.

Link to comment

Thanks @Stephen_C. What you described is an example of the issue, but unfortunately not a solution for what I was looking for/expecting, which is that the automation would work even when an app that isn't a browser is active. I'm was trying adapt @dfay's very useful Browser snippets workflow to work with any browser, using Alfred's built-in automations rather than adding a bunch of extra scripting to account for other browsers.

 

I would have expected "Current Frontmost Browser Tab" to basically:

- determine what browsers are running

- determine which window among those browsers is in front of the others

- return the URL and/or Title of the current tab from that browser window 

 

This would allow the action to return the active tab of whatever browser I was most recently working with, even if I'm using a different app. Ause case would be to grab the url and title from the tab and paste it into a text document, for example, with one quick keyboard shortcut or snippet.

 

Instead, "frontmost browser" really seems to mean "frontmost app, which also must be a browser".

Link to comment
5 hours ago, paulw said:

Is that expected?

 

Correct. On the technical side, this is because AppleScript (needed for the action) can get either the frontmost app or a list of apps, but not a list of app windows in order. It is possible to get a list of app windows in order via other means (I already wrote the code) but when I tested it before it required asking for screen recording permissions so I debated on whether to add it. Testing further, I see I already had made it work without that requirement.


I’ll test a bit more, and if it continues to be viable this improvement will be available in the next Automation Tasks release. If you have auto updates set up, you’ll get the new behaviour without having to do any changes.

 

Note that as part of an unrelated improvement these will get shorter names for better fitting in the palette. That one will be “Current Front Browser Tab”. But again, you don’t have to do anything, the ones you have will get the new name without your intervention.

 

Edited by vitor
Link to comment
  • 1 month later...
4 hours ago, vitor said:

Just to let you know this has been added a couple of weeks ago.

Thanks! Works great without the need for the osascripts now. The only issue that I'm having is that I'm using Orion browser (actually, the Orion RC version) and I get the error 

Task Error: arm/get-frontmost-browser.swift:32: Fatal error: Did not find a supported web browser

I realize there are a ton of browsers out there, and some come and go, and it might be a chore to keep Alfred managing a list of them.

 

Perhaps:

1. Orion and Orion RC be added to the list of supported browsers, or

2. Possibly there's a more global way for Alfred to recognize browsers (Orion for example is basically Webkit plus added stuff)? or

3. Users could specify an app as a browser in Alfred preferences (similar to how Choosy.app allows you to specify an app that it may not have detected as a browser)?

Link to comment
1 hour ago, paulw said:

Orion and Orion RC be added to the list of supported browsers

 

Added in 2023.6. Orion was already supported by the Tasks, but not added in the code to detect frontmost browsers.

 

1 hour ago, paulw said:

Possibly there's a more global way for Alfred to recognize browsers (Orion for example is basically Webkit plus added stuff)?

 

Detecting browsers isn’t the issue, automating them is. There is no generic way to do it. For example, Firefox doesn’t have an AppleScript dictionary and Arc’s is still incomplete and inconsistent with other Chromium browsers. Orion’s was also inconsistent with Safari but those have been reported to the team and fixed. In other words, every browser has to be supported specifically and there’s no way around that.

 

1 hour ago, paulw said:

Users could specify an app as a browser in Alfred preferences

 

If you want to define a specific browser, there are other Automation Tasks groups for that. “Frontmost Browser” is just that, whichever is the frontmost without specifying it.

Link to comment
22 hours ago, vitor said:

It should still work with the Frontmost Browser Tasks. And in specific browsers, you can choose Custom… and write in the name of the browser directly.

 

Orion RC gives me "Orion RC is not a supported browser". 

 

Can you explain where the "Custom..." choice is to be found? I don't see it in the task options

Edited by paulw
Link to comment

Oh I see. It seems that as long as I'm using Orion RC, I'd have to adapt the workflow to use the Webkit Automation Tasks, instead of Frontmost Browser Tasks. That's too bad, because I'd prefer to be able to use the workflow with non-Webkit browsers as well.

 

Yes, you're right, Orion RC is available on the paid plan.

Link to comment

If there's a way I can help you figure it out, I'd be happy to.

 

I don't know if the cause could be this simple but using Filemerge, I notice that in Contents/Info.plist for each app, Orion's includes

 

<key>CFBundleExecutable</key>
<string>Orion</string>
<key>CFBundleIconFile</key>
<string>AppIcon</string>
<key>CFBundleIconName</key>
<string>AppIcon</string>
<key>CFBundleIdentifier</key>
<string>com.kagi.kagimacOS</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Orion</string>

 

while Orion RC's has

 

<key>CFBundleExecutable</key>
<string>Orion RC</string>
<key>CFBundleIconFile</key>
<string>AppIcon-RC</string>
<key>CFBundleIconName</key>
<string>AppIcon-RC</string>
<key>CFBundleIdentifier</key>
<string>com.kagi.kagimacOS.RC</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>Orion RC</string>

 

 

Also in Contents/embedded.provisionprofile some of the differences are:

 

Orion:

<key>AppIDName</key>
<string>Kagi</string>

...

<key>DER-Encoded-Profile</key>
<string><<a long string>></string>

...

<key>com.apple.application-identifier</key>
<string>TFVG979488.com.kagi.kagimacOS</string>

...

<key>Name</key>
<string>Kagi macOS</string>

 

and Orion RC:

 

<key>AppIDName</key>
<string>Orion RC</string>

...

<key>DER-Encoded-Profile</key>
<string><<  a different long string >></string>

...

<key>com.apple.application-identifier</key>
<string>TFVG979488.com.kagi.kagimacOS.RC</string>

...

<key>Name</key>
<string>Orion macOS RC</string>

 

Edited by paulw
cleaned up code blocks
Link to comment
  • 2 months later...

Hello @vitor, unfortunately Frontmost Browser is no longer working again with the latest update of Orion RC. I checked the text samples that I sent you above, and none of those seem to have changed in the new version (except I didn't check <key>DER-Encoded-Profile</key>).

Link to comment

Make sure you’re on version 2024.1 of the Automation Tasks. Also, I need to know which ones are failing, with which error, and your Alfred and macOS versions.

 

But again, Orion RC isn’t generally available so it’s only supported in a best effort basis. If I can’t access it, I can’t diagnose it either.

Link to comment

Thanks. It's the same issue as before: "Current Front Browser Tab" fails with

 

Task Error: arm/get-frontmost-browser.swift:32: Fatal error: Did not find a supported web browser
../../../../com.alfredapp.automation.core/safari/.common/tabs-current: execution error: Error: Did not find a supported web browser (-2700)

 

I'm on Alfred 5.1.4 and MacOS 14.3.

 

Other Automation Tasks involving front browser run into the same error

 

Edit: and I'm using v 2024.1 of Automation Tasks

Edited by paulw
Link to comment

Nothing has changed about the detection. And without having access to the browser, there’s no way for me to investigate further.


I can tell you the detection works by checking if the kCGWindowLayer of a window is 0 and if its kCGWindowOwnerName starts with the name of a known web browser. In other words, it doesn’t matter if it’s called Orion, Orion RC, Orion Beta, or Orion The Huntsman Browser, they’ll all be detected. That may help you figure out what changed. Also try using the Webkit Browser Automation tasks and giving it specific names.

Link to comment

Thanks @vitor. I won't ask you to spend time troubleshooting a browser that you don't have access to, but just FYI, I used this script to confirm that kCGWindowLayer is 0 and kCGWindowOwnerName starts with Orion (Orion RC).

 

On 1/31/2024 at 6:32 AM, vitor said:

Also try using the Webkit Browser Automation tasks and giving it specific names.

 

I'm not sure what you mean by this. Could you explain?

Link to comment
4 hours ago, paulw said:

I'm not sure what you mean by this. Could you explain?


There’s a set of Automation Tasks to Script WebKit browsers. Try with that using the Custom browser option and seeing if it works.

Link to comment
11 hours ago, vitor said:

There’s a set of Automation Tasks to Script WebKit browsers. Try with that using the Custom browser option and seeing if it works.

 

Thanks. That does work, using "Orion RC" as the custom browser. Hopefully I can find a way to get the "Current Front Browser" working again with Orion RC, since it has the advantage of also working with other browsers I might have open.

Edited by paulw
added detail
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...