bit2pixel / chrome-control

A JXA script and an Alfred Workflow for controlling Google Chrome
https://medium.com/@bit2pixel/how-i-navigate-hundreds-of-tabs-on-chrome-with-jxa-and-alfred-9bbf971af02b
MIT License
189 stars 25 forks source link

Any way to improve list efficiency? #6

Open AnthoPakPak opened 4 years ago

AnthoPakPak commented 4 years ago

Hi!

First, thanks a lot for this awesome Alfred workflow, I really enjoy using it! 👌 The only thing I struggle with is the fact that listing the tabs is too slow. I have hundreds of opened tabs and it takes several seconds before showing the tabs list (sometimes up to 10seconds). So unfortunately, I lose a lot of time waiting the loading…

I've looked at the code, but from what I see the logic is nice, and I don't see a straightforward way to improve the efficiency. I guess the slow part is the looping through windows/tabs, but I can't find a better way to do it.

Do you have any advice, idea, which could lead to improved efficiency?

mschmidtkorth commented 4 years ago

I've had the same issue. Code looks nice, but performance for a heavy tab user is too slow - around 7-10 seconds for me to wait for results, so I am much faster to open Chrome myself and use an extension to search for my tab. As my main intent was opening a specific tab, I've automated this extension via Alfred and osascript.

AnthoPakPak commented 4 years ago

@mschmidtkorth Oh yeah, I didn't thought of doing it! I would be really interested to know how you did this! If you don't mind, could you please tell me the extension used, and maybe share the script? Would be awesome!

mschmidtkorth commented 4 years ago

@AnthoPakPak Sure! The Chrome extension is Tab Ahead, which has a keycombo of Opt+T. The Alfred Workflow (as attached) simply opens Chrome, presses Opt+T, and then pastes "mail.google.com" + Enter to open my Gmail tab. You could send a dynamic string instead if you want to use this as a way to search for tabs. The disadvantage obviously is that you will have no list of tabs in Alfred.

Gmail-Opener.alfredworkflow.zip

AnthoPakPak commented 4 years ago

@mschmidtkorth Thanks a lot! I'll take a look at it. Indeed, not having the list in Alfred could be a major drawback… I think one major improvement to chrome-control would have been to cache tabs, I'll see if if I can do something like this someday. Like storing opened tabs in a file every minute, so that Alfred will show them instantly (while still refreshing the list to make sure opened tabs less than a minute ago are still showed). I was thinking of listening for new Chrome tabs event, but from what I've seen it can only be done with a Chrome extension. And unfortunately, Chrome extensions can't write on disk, so it would not be able to store tabs list… So currently I don't have a better idea than automatic caching every minute 😕

mschmidtkorth commented 4 years ago

@AnthoPakPak Yes, it is quite cumbersome. One option would be:

AnthoPakPak commented 4 years ago

@mschmidtkorth Wow this tool seems awesome! I've managed to get it working, thanks for the instructions! The only issue is that Current Tabs doesn't seem to include all opened tabs… In my case it is missing a lot of tabs. Even the currently focused tab isn't always present in the results. I currently haven't found any other file that could contain reliable tabs information...

AnthoPakPak commented 4 years ago

@mschmidtkorth BOOM! After searching hours into Chromagnon and SNSS (and even other ways), I've came back to initial script, to see if I can improve the JXA. And I've ended up finding out a way to improve drastically the performances! I've just made a pull request (#7) with the required changes. The loading is now blazing fast! You should be able to change the code yourself to try it out now. I'm using it for a few hours now and it is sooooo good! 🤙

mschmidtkorth commented 4 years ago

@AnthoPakPak Nice!! It is MUCH faster now, great! However, for me this has removed the ability to search for URLs instead of tab names (example: Google Mail's tab title changes if someone sends you a chat message, then I can no longer switch). Was this intended?

AnthoPakPak commented 4 years ago

@mschmidtkorth Hi! Are you sure? I've noticed this also but when trying the initial version it was the same results (some are missing…). But I also wanted to improve this, I'll take a look!

mschmidtkorth commented 4 years ago

@AnthoPakPak Actually I'm not sure whether this was part of the original implementation. Might just have been wishful thinking :-)

Edit: See attached for a version with fuzzy matching on title and subtitle. Chrome Control.alfredworkflow.zip

AnthoPakPak commented 3 years ago

@mschmidtkorth Funnily enough I'm only seeing your edit now 😅 I had meanwhile made the changes on my side so that the search works in title and subtitle, but I'm glad to found your fuzzy version! I've just integrated the required changes in my workflow and it works perfectly! 👌 So, a bit late to the party, but thanks a lot for sharing this fuzzy version ✌️

luckman212 commented 3 years ago

@AnthoPakPak I played around with this and the matching wasn't working great for URLs that start with www because of the way Alfred's anchoring works. I didn't try adding @deanishe 's fuzzy into the mix because honestly that was overkill for my use case.

I forked and uploaded a version that extracts the base URL and breaks it up into words so e.g. searching npm will match on https://www.npmjs.org as well as https://blog.npmjs.org. In case anyone wants to try...

luckman212/chrome-control

unknownbreaker commented 2 years ago

Comments

@mschmidtkorth implementation is great. Indexing is super fast, and my tab searches are reliable. Oddly, I think dashes were not working so well in the original version? One of my tab titles had a dash in it, and as soon as I typed the dash, I lost all search results. But this one fixes it.

However, I think the fuzzy search is a bit finicky. I'm not sure why this is my top search result over the second result. image

Request

This issue alone now has two separate chrome-control solutions floating around. Anyway these can be merged into the original chrome-control? It'll be less confusing and people who don't read GitHub issues will also benefit from these improvements.