Closed dorukkilitcioglu closed 6 years ago
--new-window
option launches a new Chrome window. We might run into the same problem as with SublimeText #3. --app-id [APP ID]
or even --load-extension
. The second sounds more applicable.chrome.windows.getAll({populate:true}, getAllOpenWindows);
function getAllOpenWindows(winData) {
var tabs = [];
for (var i in winData) {
if (winData[i].focused === true) {
var winTabs = winData[i].tabs;
var totTabs = winTabs.length;
for (var j=0; j<totTabs;j++) {
tabs.push(winTabs[j].url);
}
}
}
// do stuff with tabs
}
I'm pretty sure an extension can do this too.
window = get(id)
window.close()
Ideally, there are some weird CLI options, but after browsing them a bit that does not seem feasible. A very wild idea is to use communicate with Google API directly through Python, but that probably wouldn't be as flexible as a Chrome extension. Then again, I really don't want to build a Chrome extension...
So as expected, this was not a walk in the park. Or at least, it looks like the very simple way of just navigating to a desktop and opening up a new Chrome instance using the --new-window
option seems to work. However the pid
that returns is the process id of the tab that was created, and not of the window.
The reason seems to be that Chrome is technically a single "window", according to Windows. All "windowed" applications seem to be under a global explorer.exe
according to Process Explorer, which reminds me of the days when explorer.exe
used to crash so I had to restart it...
Anyways, under explorer.exe
, there is a single chrome.exe
level, and under that chrome.exe
level are the tabs. There is a pid
associated with that global chrome.exe
, which can be moved using VirtualDesktop. However, what that global chrome.exe
process points to changes dynamically when you browse through the tabs.
Specifically, that process points to the active tab in the active window. You can check it through the tasklist
command.
# tasklist /nh /v /fi "imagename eq chrome.exe"
chrome.exe 6160 Console 1 231,736 K Running DESKTOP-M0A49CK\doruk
0:25:20 chrome instant process - Google Search - Google Chrome
chrome.exe 1260 Console 1 5,848 K Running DESKTOP-M0A49CK\doruk
0:00:00 N/A
The first entry, which contains a window name instead of N/A
like all the others, is the global chrome.exe
. Since its pid
is 6160
in this case, I can move the process with pid=6160
to any VirtualDesktop. In practice, this only moves the active window, which is actually good for our use case.
What's bad is the fact that I don't think I can kill 6160
without taking down the whole thing, which brings us back to the whole Chrome extension thing.
Huh, doing taskkill /PID 6160
actually worked. It only killed the active window, which is nice. However, I wouldn't want to leave that to change (what if the user looked at another window before calling close
on a project?)
Anyways, for persisting the tabs, using an extension seems like the only way to go. What we need is a way of passing the name of the project to the said extension.
A couple of ideas:
http://www.somefakeurl.com/?the-project-name
, which the extension will intercept and load in the tabs associated with that project instead. Not sure what is the safest approach here for us to not hit any actual websites.
http://www.anything.idontthinkthisdomainwilleverexist
https://i❤.ws/
doesThis is now implemented using the URL approach above. Also as mentioned above, simply doing a --new-window
does open Chrome in the current virtual desktop, so it seems safe (for now).
I can probably move the window right after it is opened, since it will be the active window at that time. For that, I just need to find the pid
(as above). If that becomes necessary, the issue can be opened again.
Google Chrome is my browser of choice. There needs to be support for the following actions:
There might also be a need to find the windows that are in the current desktop, but that is in the back-burner for now.