Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Tracking Multiple Sessions #1187

Closed
wants to merge 2 commits into from

Conversation

Swivelgames
Copy link

This fixes #1186 with the following changes:

  • Better New Window Tracking
    • FIX: Opening a saved session will no longer append itself to a tracking session
    • FIX: New Windows are tracked to the currently focused session
  • Closed Windows are now removed from tracking session
    • ADDED: Closed Window Tracking Setting
      • When enabled, windows attached to a tracking session will be deleted from the session when they're closed

This greatly improves the consistency of Session Tracking.

@sienori
Copy link
Owner

sienori commented Sep 8, 2023

Thank you for your PR.
The user closes all windows to close the browser. It would be inconvenient for the windows to be removed from the tracking session at that time.

@sienori sienori closed this Sep 8, 2023
@Swivelgames
Copy link
Author

Swivelgames commented Sep 17, 2023

@sienori I feel like there's a fundamental misunderstanding of what this PR does. I really wish you had given me some time to respond to this feedback so that we could have a discussion on the best way to move forward.

Please see the original issue (#1186) and review the PR more thoroughly. There are several issues at play here that amount to a bug.

First:

  • Opening two tracked sessions will append the windows to the first tracked session, effectively duplicating it. This is a bug.

This PR fixes both of these issues while providing multiple safeguards that doesn't ruin user's tracked sessions:

  • Opening multiple tracked sessions will track them separately, so that multiple tracked sessions can be open at once (which is broken right now)

Additionally, there's an settings option that can be turned if a user wants to be able to remove a window from a multi-window tracked session by closing one of the windows:

  • This option is guarded behind an option in settings that is disabled by default, so it will not affect users unless they explicitly opt-in to the feature
  • Quitting the browser does not remove windows from tracked sessions
  • Closing all windows does not remove the windows from the tracked session
  • Closing the last window in a tracked session will not remove it from the tracked session

If you'd like me to move the option to remove a window from a tracked session to a new PR, I can certainly do that and we can discuss whether or not it should be an option that users should be able to choose to have if they'd like.

But the original issue is still a bug that needs to be addressed.

Let me know how you'd like to proceed.

};

const deleteWindowFromSession = async (sessionId, originalWindowId, openedWindowId) => {
if (!getSettings("shouldTrackDeletedWindows")) return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless the user has explicitly turned on shouldTrackDeletedWindows, no windows will removed from a tracked session.

if (!getSettings("shouldTrackDeletedWindows")) return;

// If this was the last window for this session, we don't want to remove it
if (trackingWindows.filter(x => x.sessionId === sessionId).length === 0) return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevents the last window in a tracked session from being removed from a tracked session.

Comment on lines +70 to +72
const focusedWindow = trackingWindows.find(x => x.openedWindowId === trackedWindowId || x.originalWindowId === trackedWindowId);
// If the last window that we were in isn't being tracked, don't track the new window
if (!focusedWindow) return;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BUG FIX for #1186: Prevents a tracked session from hijacking another session's window.

@gldrk
Copy link

gldrk commented Oct 29, 2023

It’s not obvious to me that shoving new windows into sessions based on where the last focused window came from is any better than lumping them together into one session. Most importantly, how does it handle things like window.open or running firefox --new-window https://www.google.com/xdg-open https://www.google.com? The latter use case is extremely important. A quick skimming of your code suggests that if no window happened to be currently focused, such windows won’t get tracked at all, which I would definitely want them to.

As things stand, opening additional ‘tracking’ sessions behaves in a way consistent with other state modifications and doesn’t require any special casing.

Frankly, mapping browser state onto several active sessions seems like an inherently bad model to me. The browsers and window systems that we have today weren't designed with that in mind. It’s almost like instead of these per-session tracking flags there should be a single global flag that causes a continuous session reflecting whatever is currently opened to be maintained, with all other sessions treated as simple static snapshots.

On the other hand, it does seem bad that closed windows pile up in tracking sessions until they are manually removed. This is particularly useless when the option for saving the former as bespoke sessions is active. The same logic that guides the ‘Save the session when exiting browser’ option can likely be reused to account for the exit scenario.

@Swivelgames
Copy link
Author

Swivelgames commented Oct 30, 2023

@gldrk As I've been using this as my daily driver version of Tab Session Manager since I wrote the PR, I can tell you its very stable and intuitive, although it may not be immediately obvious simply by looking at the code given how simple the implementation of the solution was.

The bug exists, the question is how do we handle it?

First, the original issue in #1186 is still present. Opening up multiple tracked sessions appends the original session with the newly opened session's windows.

Expand to see the original reproduction steps

Short description

While tracking a Session in Tab Session Manager, opening up another session should not add it to the tracked session.

Steps to reproduce

This can be reproduced regardless of whether or not Session 2 is also tracked.

  1. Open a new window with the following tabs: Github.com, Amazon.com
  2. Save the window it as a session called Session 1
  3. Enable Tracking
  4. Repeat steps 1-5, but instead open: Google.com and name it Session 2
  5. Close Session 1 and Session 2
  6. In Tab Session Manager, open Session 1
  7. In Tab Session Manager, notice the Session 1 is tracking
  8. In Tab Session Manager, open Session 2
  9. In Tab Session Manager, notice the Session 2 appears to be tracking
  10. In Tab Session Manager, review Session 1

Expected result

Session 1 has 1 Window, 2 Tabs

  • Github.com
  • Amazon.com

Session 2 has 1 Window, 1 Tab

  • Google.com

Actual result

Session 1 has 2 Window, 2 Tabs

  • Window 1
    • Github.com
    • Amazon.com
  • Window 2
    • Google.com

Session 2 has 1 Window, 1 Tab

  • Google.com

As the extension sits right now, there can realistically only be a single tracked session open at once. Any additional sessions that are opened affect the first tracked session. This is incredibly dubious and requires manual intervention to "clean" sessions that have been polluted by another session's windows.

The proposed solution is not to change the behavior, but to maintain it.

Remember, opening multiple tracked sessions already exists. And, tracking new windows on a tracked session already exists. The difference is that Tab Session Manager does not properly track against multiple sessions. It falsely shows that both are being tracked, but tracks changes to the second session against the first. Opening a second tracked session adds all those windows to the first tracked session. It's bugged.

This fix only affects users who are trying to use multiple tracked sessions at once. Tracking new windows against tracked sessions already exists. window.open, --new-window, and xdg-open all affect the session (if any) of the currently focused session. I personally use --new-window on a daily basis, and it's quite intuitive, and behaves as it does today, but it's now smart enough to understand which session you're dealing with.

  • If I'm working within a particular session, opening a new window via hotkey or other means appends it to the currently focused tracking session.
  • If I'm focused on an orphaned window or a non-tracked window, it doesn't append it to any tracked session.
  • If I open a new tracked session from the extension, it does not append it to the currently tracked session (the original bug in question).

This behavior is because I have already made the conscious decision as a user to enable "Track New Windows" for tracked sessions. In the event that I open a particular window that I don't want tracked to a session, the workflow is the same as it exists today: Removing the new window from the tracked session ensures that it is no longer tracked. This manual intervention is already required today, and it's an edge case that exists when you're breaking out of your normal workflow and there's a specific new window that you don't want tracked against your tracked session.

Give it a try! 🙂

If you're worried that it might not behave intuitively, I would encourage you to pull it down and test it yourself. Again, I use this on a daily basis, and it has definitely maximized my use-case and workflows while using this extension.

Alternative: Allow it, or don't.

If the alternative is to not allow opening multiple tracked sessions altogether, then that should be implemented, but I don't see the benefit in limiting a user to only one tracked session at a time. Either way, #1186 is an entirely valid bug, and I would highly recommend reading through it to get a better understanding of the root of the problem.

Bonus: Keeping sessions clean

The only bonus of this PR was the ability to turn on an option to automatically remove closed windows. That's not a bug, but it is a feature, and it too is gated, meaning that a user has to opt-in to this functionality.

Bonus for the Bonus: "Close Session" option

Additionally, if the worry is that a user should have the ability to close all windows in a session in one go without closing the entire browser, there's absolutely room to add an option to "Close Session", which would close all windows in an open session without removing them from the tracked session.

@Swivelgames
Copy link
Author

Swivelgames commented Oct 30, 2023

Refocusing

Remember, this bug is for:

  • Opening more than one Tracked Session with Track newly opened windows enabled (existing functionality).

This PR ensures that:

  • New Tracked Sessions track against themselves

The only thing new that this PR introduces is an optional feature that will:

  • Optionally remove tracked windows from a session when they're closed

Current Functionality

This is existing behavior, not the behavior after this PR.

bug-1186-current

After this PR

This is how it functions with this PR

bug-1186-fixed

@Swivelgames
Copy link
Author

Swivelgames commented Oct 30, 2023

@gldrk

To demonstrate this, using the Current Version of Tab Session Manager, I did the following:

  1. Create Session 1 with Amazon.com and Github.com, enabled Tracking
  2. Create Session 2 with Google.com, enabled Tracking
  3. Close both windows (because they don't auto-track)
  4. Open Session 1
  5. Open Session 2
  1. Focus on Session 2 window, and open a new tab and navigate to Microsoft.com
  • Notice that the Microsoft.com tab is added to both Session 1 and Session 2
  1. Focus on Session 2 window, and open a new window and navigate to Apple.com
  • Notice that the New Window is tracked against Session 2 and NOT by Session 1
  • This is Current Functionality and is working as expected.
  1. Now focus instead on the Session 1 window, and open a new window and navigate to Yahoo.com
  • Notice that the New Window is still tracked against Session 2 and NOT by Session 1
  • This is NOT _working as expected.
  • Because the new window was opened from Session 1, the new window should be tracked against Session 1, not against Session 2.
  1. Notice that ANY new window that ever gets opened is now tracked against Session 2, even though both are sessions are opened and tracked, regardless of which Session is being actively used. That's a Bug 🙂

This PR also fixes that bug by making sure that New Windows are tracked against the Session you're actively working in.

Screenshots

Session 1 after opening both sessions and creating the first new window for Apple.com
image

Session 2 after opening both sessions and creating the first new window for Apple.com
image

Session 2 after opening both sessions and creating two new windows for Apple.com and Yahoo.com (the latter while focused on the Session 2 window)
image

@Binly42
Copy link

Binly42 commented Nov 12, 2023

for me, a more ideal solution might be:

  • always treat all windows as inside a workspace
  • some windows belong to a being tracked session session A(which belongs to the workspace)
  • some other windows belong to another being tracked session session B(which belongs to the workspace)
  • if not yet opened any tracking session, all windows just simply directly belong to a untitled session(which belongs to the workspace of course as well)
    • additionally, from my opinion, is not this untitled session should just also be as like a unsaved temporary tracking session ?
  • for those new opened windows that are not reasonable enough to tell 'which tracking session they should belong to', better to pop up to ask user
    • or, default put them into the untitled session ?

well, if default tracking the workspace (excluding those windows already belong to some certain tracking session),
plus the diff and merge feature between sessions,
how great!

Wonderful, a git for browser session created ...

@Swivelgames
Copy link
Author

@Binly42 That simply adds complexity and ambiguity. The methods I outlined simply implement the way that the browser currently behaves already in all scenarios. Introducing an additional layer will simply confuse a user.

If I focus on a specific browser window, Alt+Tab to a different application, and open a link, the browser creates a tab on the last window I focused. This is true when I'm using Firefox and Chrome.

The same is true if I'm running multiple profiles in Chrome. If my Work Profile is focused and I click on a link in another application, or I open a new window, that window or tab is tied to my Work Profile. The same is true if I then tab over a window that's attached to my Personal Profile and open a new window, or a link from an outside application.

Last focused is the default behavior for all browsers when tracking this type of functionality, and it's most intuitive for the user.

The last thing you want to do is add more layers of complexity. That doesn't solve the ambiguity, it adds to it.

@sienori
Copy link
Owner

sienori commented May 27, 2024

@Swivelgames
I deeply apologize for mistakenly closing this PR, not listening to the subsequent discussions, and leaving it unattended for such a long time. The behavior in session tracking for new windows was clearly a bug. I fixed this issue by referring to your PR while migrating TSM to the service worker. de63159
I understand that there is a demand for window deletion as well, but due to the high implementation cost, it will be excluded from this release scope. Thank you for your contribution.

@Swivelgames
Copy link
Author

@sienori I appreciate that! I tried to keep emotion out of it, because it would've been unprofessional and wouldn't have helped anything, but I'll admit I was quite frustrated that it was closed so abruptly 😂

No hard feelings, though, honestly! I understand it takes quite a bit of effort to continue to maintain popular repos.

But I am quite glad this issue was fixed! I actually stopped using Tab Session Manager because of the issue after a while. I kept finding myself coming back to this and reimplementing my patch in order to continue to be able to use it on a daily basis, though. Tab Session Manager is incredibly useful, on top of the built-in Profiles.


As for window deletion, I was daily driving this PR for quite a while with the option to delete windows intuitively, and it was quite intuitive and wasn't destructive 🙂

Let me know if you'd be interested in an additional contribution to add an optional setting to allow for window deletion. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] [Tab Tracking] Opening a session tracks it twice
4 participants