balta2ar / brotab

Control your browser's tabs from the command line
MIT License
389 stars 27 forks source link

Determine the chrome/firefox profile of the client (feature) #71

Open bjohas opened 2 years ago

bjohas commented 2 years ago

I am trying to get certain tabs to open in certain profiles. E.g. in chrome, chrome://version/, gives me

Profile Path | /home/user/.config/google-chrome/Profile 1

However, when I query this tab, I only get this:

$ bt text a.1.1549
a.1.1549    About Version   chrome://version/

Is there a way to access the profile? E.g.,

$ bt profile a
Profile 1

or maybe

$ bt clients
a.  localhost:4625  4302    chrome/chromium    Default
b.  localhost:4626  8583    chrome/chromium    Profile 1

Many thanks!

bjohas commented 1 year ago

@balta2ar - any thoughts on this? I could look at this and do a PR - would that be welcome?

balta2ar commented 1 year ago

Sure! But before you start writing code, as the first phase, could you do a "research" phrase where you'd look into the available APIs in different browsers and estimate where this feature may incur changes in the code? Feel free to post the relevant links and ideas here. What I mean is something like a planning stage. And then when we're on the same page, it can follow with code.

bjohas commented 1 year ago

@balta2ar Hello again. I've looked at this. It doesn't seem to be possible to get the profile like this. However, I have another proposal.

The problem I am trying to solve is to make each instance of the brotab extension unique, so that I know which Profile it corresponds to. There doesn't seem to be unique id associated with each instance.

Would you be ok with the introduction of an option for the brotab browser extension, through which users can add a unique string to this instance? If the string is set, then, e.g., bt clients would return

$ bt clients
a.  localhost:4625  4302    chrome/chromium    string1
b.  localhost:4626  8583    chrome/chromium    string2

How does that sound?

balta2ar commented 1 year ago

add a unique string to this instance

How would you do that?

An alternative I've just thought about is the following. It's a bit hacky, but it doesn't require changes in brotab, only in your wrapper scripts.

In each profile that you have, you open a tab with a magic title, e.g. file:///home/user/profile1.html, then you use that magic string to figure out which mediator port corresponds to which profiles. It requires an extra tab, which should always be there, but if you are a tab hoarder like me, you wouldn't even notice 😅 What do you think?

bjohas commented 1 year ago

Hi @balta2ar,

I lost track of responding, but I actually made some local changes and have used them since last year. I've added "storage" to the permissions:

Manifest:

"options_page": "options.html",
...
"permissions": ["nativeMessaging", "tabs", "activeTab", "<all_urls>","storage"],

Then: background.js

     chrome.storage.sync.get({
       brotab_identifier: 'profile_1'
     }, function(items) {
       instID = items.brotab_identifier;
     });
     return "chrome/chromium\t"+instID;

Via the options page options.html, the identifier can be set.

Would you be happy for me to do a PR on this?

balta2ar commented 1 year ago

I guess if you have the changes locally it's no harm to make a PR :) Do you think you could also come up with a test for this?

bjohas commented 1 year ago

I've done a PR. As noted in the PR, this is initially for discussion. Needs more polishing/testing, and a test as well.

bjohas commented 11 months ago

Let us know if there's anything else we should do - we're keen to get this integrated into the code.