prasmussen / chrome-cli

Control Google Chrome from the command line
MIT License
2.61k stars 89 forks source link

Getting tab id's programatically #85

Closed tomdevlive closed 9 months ago

tomdevlive commented 1 year ago

Hello just wanted to say this is a great app! I do have a question though that involves the Id's of tabs. I have a script that will open 3 tabs , but then I would like to have a script that would refresh a specific tab. In order to do that I need to supply the tab Id which I can get if I do 'chrome-cli list tabs', but I would like to automate the process so I didint have to do that everyt time to get the newly changed tab Id.

I was thinking maybe save the tab Id's to a variable each time the 'open 3 tabs' script is ran, but wasnt sure if that was the best way. I'm open to any suggestions. I'm using terminal in mac with sh scripts but can use python if thats better?

tomdevlive commented 1 year ago

Ok it seems I'm having another issue in regards to reloading specific tabs.

I have 4 tabs open:

Running 'chrome-cli list tabs' gives me this: [105553122044512] New Tab [105553122231168] Official Site of the National Hockey League | NHL.com [105553122231104] The official site of the NBA for the latest NBA Scores, Stats & News. | NBA.com [105553122198624] MLB.com | The Official Site of Major League Baseball

Running 'OUTPUT_FORMAT="json" chrome-cli list tabs' gives me this: { "tabs" : [ { "id" : 105553153426240, "title" : "New Tab", "url" : "chrome://newtab/", "windowId" : 105553153477632, "windowName" : "MLB.com | The Official Site of Major League Baseball" }, { "id" : 105553153477664, "title" : "Official Site of the National Hockey League | NHL.com", "url" : "https://www.nhl.com/", "windowId" : 105553153426208, "windowName" : "MLB.com | The Official Site of Major League Baseball" }, { "id" : 105553153459488, "title" : "The official site of the NBA for the latest NBA Scores, Stats & News. | NBA.com", "url" : "https://www.nba.com/", "windowId" : 105553153477696, "windowName" : "MLB.com | The Official Site of Major League Baseball" }, { "id" : 105553153477728, "title" : "MLB.com | The Official Site of Major League Baseball", "url" : "https://www.mlb.com/", "windowId" : 105553153477600, "windowName" : "MLB.com | The Official Site of Major League Baseball" } ] }

Let's say I wanted to reload the mlb.com tab, which id do I use? OUTPUT json gives me a different one than the command without json. Just for testing I will try any id number associated with the mlb.com tab:

chrome-cli reload -t 105553122198624 chrome-cli reload -t 105553153477728 chrome-cli reload -t 105553153477600

None of those commands resulted in a rload of the mlb.com tab.

I just realized if I run 'chrome-cli list tabs' I get totally different Id numbers now. I'm confused, someone please help.

ahuggins commented 1 year ago

This is probably related to what seems to be a bug from Chrome. It seems that every time a request for chrome-cli list tabs is made, the ids that are returned are different for the "same" tab as the previous request. This might mean that when passing a tab id with -t from a previous tabId that you retrieved... is NOT going to work since the IDs seem to change all the time.

Since this seems to be the case since Chrome 112 (anything newer than that version). This is causing some things to break for many people. And would mean that you are unable to reload your desired Tab at the moment.

prasmussen commented 1 year ago

The issue with tab id's are fixed in 1.9.3

ahuggins commented 1 year ago

I agree with @prasmussen. This is resolved, should close the issue.