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

Fixed syncTabsOrder() / Unclickable Tabs (#2199) + Many (Not all) of v3.0.7 Critical Issues (#2238) + Auto Reload Sidebar on Critical Tab Order Failures #2239

Closed
wants to merge 8 commits into from

Conversation

PowerWeb5
Copy link
Contributor

Fixes for #2199 (with syncTabsOrder) + many (but not all) of #2238 (v3.0.7 Critical Issues), including:

  • Fixed syncTabsOrder() never actually working (ever) due to always either deferring indefinitely or failing the initial conditions or comparing the wrong things, with a complete rewrite of it
  • Added support for automatic complete rebuild of trees when syncTabsOrder() fails
  • Added "Reload Sidebar" to context menu for sidebar, which users can use when encounter other critical issues like with unclickable tabs, or in wrong order, etc.
  • Fixed "Error: Could not establish connection. Receiving end does not exist" at least when either:
    A. caching is disabled (configs.useCachedTree = false) OR
    B. if configs.useCachedTreeBackgroundExport = false (left = true for now) (not exposed in Options UI)

Remaining Issues from #2238 still not fixed

  1. "Error: Could not establish connection. Receiving end does not exist" still occurs when caching is enabled
    • I added configs.useCachedTreeBackgroundExport option
    • I left true by default for now
    • I suggest you set = false after testing further with session restore cache use (may prevent that, or that may be already be prevented due to that error remaining anyways)
  2. Tabs opened soon after Firefox startup (with TST sidebar auto shown on startup) while TST is initializing
    • For example if was to open "https://trakt.tv/calendars/my/shows", end up with animated loading icon showing forever,
    • Sometimes (not always) also shows only URL (instead of title) and/or has FaviconLoader error
  3. sendMessage(kCOMMAND_PULL_TABS) in rebuildAll() in background.js is returning undefined

…en for New Tabs) After Throw Error Corrupts State - Need Auto Tab Resync, Not syncTabsOrder() throw Error"

-Now syncTabOrder() actually works
-Depends on changes committed in next commits (at least for the auto Reload Sidebar fallback auto-fix portion of this)
-Required complete syncTabOrders() rewrite, as it was never actually even attempting to reorder in all (or nearly all) cases, where only would execute it was already in-sync
-Now reordering occurs immediately, instead of being deferred (possibly indefinitely/forever) before
…remain out-of-sync

-with reloadSidebars() in background.js
-Required by previous commit fixing sortTabsOrder()
-This should be rarely needed now that sortTabsOrder() actually works, but is critical for auto handling all other cases (or if sortTabsOrder() is ever broken, etc.) especially if opening often or encounter issues with imported or cached results (eg. from previous sessions).
…n background in attempt to reduce frequency of initialization errors and attempt to fix the errors that occur on startup from piroor#2238

-- "Error: Could not establish connection. Receiving end does not exist"
--  "Tab opened during init never sets favicon or sometimes title"?
-After fixing those can try to remove some/all of those awaits, but may help to pinpoint, avoid or reduce the issues, so suggest keeping until then
--This defaults to true currently, to reduce impact, since may need to test to ensure doesn't prevent session restore caching.
--However, I suggest changing useCachedTreeBackgroundExport = false by default, as that avoids "Error: Could not establish connection. Receiving end does not exist"
…kground) as slower, but more complete alternative to reloadSidebars()

- if still fail to recover from tab sync or other critical issues, then could auto call this.
- Cloud also add context menu item for "Reload Sidebar (Full)" or "Reopen Sidebar" if wanted
Note: May need translation still for non-English languages (though added fallback to use English in those cases)
WARN: sendMessage(kCOMMAND_PULL_TABS) in rebuildAll is returning undefined (at least when called or auto-called early on during init, but maybe always).
-I fixed the error to handle undefined, but may be underlying issue causing this to happen which may relate to remaining unfixed startup issues described in piroor#2238
-Skipped importTabsFromBackground() when caching is disabled (especially since it has been causing errors) and also if/when configs.useCachedTreeBackgroundExport == false (which I suggest making the default after testing that further).
@piroor
Copy link
Owner

piroor commented Apr 23, 2019

On the branch https://github.com/piroor/treestyletab/tree/PowerAccess-master I'm trying to understand changes and reformat them to match to the design policy of TST's existing codes...

@piroor
Copy link
Owner

piroor commented Apr 23, 2019

@PowerAccess I've done reformatting of this PR at the branch https://github.com/piroor/treestyletab/tree/PowerAccess-master . Does it still work effectively as you expected? Did I misunderstood something?

@piroor
Copy link
Owner

piroor commented Apr 23, 2019

Sorry I'm still confusing. This PR looks to having too much things, and they looks should be separated to different changes - especially reducing of the "Error: Could not establish connection. Receiving end does not exist" warning. I think we need to think "waiting until completion to do things stability" and "waiting until completion to reduce warnings" separately. You added many "await" around the initialization process, but I thought that their purpose may be confused. How do you think about that point?

@piroor
Copy link
Owner

piroor commented Apr 23, 2019

After a research, I've found an information about the warning: the "Could not establish connection" warning appears when runtime.sendMessage() is called before any listener is added to the runtime.onMessage. If the description is correct, I think I need to reduce the priority for suppressing of that, when such suppressing doesn't increase stability.

@piroor
Copy link
Owner

piroor commented Apr 23, 2019

Now I'm trying to import changes introduced with this PR to the master branch step by step.

piroor added a commit that referenced this pull request Apr 23, 2019
The main idea is inspired from #2239
@piroor
Copy link
Owner

piroor commented Apr 23, 2019

Based on the idea of this PR, I've added codes to rebuild all at both the master process and sidebars, when the list of tabs tracked by the master process is not matched to the native tabs. @PowerAccess, could you confirm that these changes are effective or not to solve "failed to sync" cases on your environment?

@PowerWeb5
Copy link
Contributor Author

Thanks for integrating some of those fixes from my PR, and continuing with that.
After your changes, some of the issues I had fixed remain fixed or improved, but others remain broken.

Tab sync issues still are occurring, though less often. Now, with latest in Git master, when a tab fails to sync and becomes "unclickable" it doesn't cause all the other tabs created after that to also become unclickable.

However, tabs still get out-of-sync and remain out-of-sync forever, even 10 minutes later.
The whole implementation of syncTabsOrder() was incorrect I'd found when debugging. It never actually corrected anything (for the few times it was called, which was very rare in the first place).

I explained why in past issue replies in more detail a few of the problems encountered with it, and then encountered even more, with the basic design of it even. That is why I ended up rewriting it, and would suggest you use the version I had written it to.

Can you use at least my implementation of syncTabsOrder() as-is vs. applying just parts of it?

Also, can you have syncTabsOrder() called automatically every configurable interval (defaulting to 10 seconds ideally, or at least 30 or 60 sec)?

Even my rebuildSidebars() implementation ended up with executing so fast and without even any kind of flicker (since it did a lightweight resync more then reload) so that there was no noticeable delay or performance overhead, so I think frequent calls to this should work well. Also, because syncTabsOrder() was almost never called (even when I changed reserveSyncTabsOrder() to execute it immediately, as I suggest you also do), it's even more critical to do that periodically.

Plus, I would suggest providing Reload Sidebar like I had implemented, to allow users to recover from more rare issues, to workaround remaining issues (like still have now) and as a workaround for if/when syncing gets broken (as I've noticed more and more tab sync issues occur over time, and can easily get broken again).

@PowerWeb5
Copy link
Contributor Author

Errors Occurring for Remaining Unclickable Tabs Issue

Here are some of the errors I'm encountering with latest from Git master, when I found some tabs unclickable.

For example, in this case, when I try to click on "v3.0.7" tab (which is the parent of the active tab in this screenshot below) then it activates the tab I clicked on (at least, which is better than a random tab like before) for like 100ms before auto-switching back to whatever the previous tab was.

image

Errors in Console with Latest Git Master

15:24:39.745 Error: Incorrect argument types for tabs.query. 2 sidebar-tabs.js:408:18
15:29:52.626 TypeError: "tab is null"
onClick moz-extension://d9f19977-38ac-4464-a14f-a0309441d127/background/context-menu.js:257
results moz-extension://d9f19977-38ac-4464-a14f-a0309441d127/extlib/EventListenerManager.js:61
dispatchWithDetails moz-extension://d9f19977-38ac-4464-a14f-a0309441d127/extlib/EventListenerManager.js:54
dispatch moz-extension://d9f19977-38ac-4464-a14f-a0309441d127/extlib/EventListenerManager.js:43
onMessage moz-extension://d9f19977-38ac-4464-a14f-a0309441d127/background/tab-context-menu.js:759
EventListenerManager.js:87:17
15:29:52.633 TypeError: result is undefined
EventListenerManager.js:102:11
15:30:10.028 Error: Incorrect argument types for tabs.query. 2 sidebar-tabs.js:408:18

@PowerWeb5
Copy link
Contributor Author

Tabs Opened During TST Init Issues

Also, the Remaining Issue with "Tabs Opened Early During TST Init Always having Loading Animated Favicon" still remains, as detailed in my last reply to Issue #2238.

This might apply to tabs opened before TST sidebar fully initializes too, but I tested with TST sidebar always auto opening on Firefox startup so it least occurs for any tabs you open while TST sidebar is shown but still initializing (eg. with progress bar shown).

See Steps to Reproduce provided and try using a bookmark in Bookmark Toolbar for "https://trakt.tv/calendars/my/shows" specifically (in case easier to reproduce with that) so that you can click on it to open it very quickly before TST finishes initializing.

This is part of why I spent time on the errors like "Could not establish connection" and waiting for complete initialization, because tabs opened early during TST init end up corrupted, so that even Reload Sidebar would not fix them (though Reload Tab did).

Please note that my PR did not fix (or at least not completely fix) this issue, though I made some changes which I hoped would help narrow down possible causes of the issue or avoid other issues with tabs opening tabs during TST init, since those tabs always have major issues with them currently, that even Reload Sidebar can't fix.

One issue I found which may be relevant to that, when debugging latest from Git master, is:
"SecurityError: The operation is insecure." occurs at
data = this.canvas.toDataURL('image/png');

at onLoad() (TabFavIconHelper.js line 207) 
called by getEffectiveUrl() (TabFavIconHelper.js line 281)

If you enable "Pause on Exceptions" and follow Steps to Reproduce from linked to reply, then you may be able to see that as well:
image

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

Thank you for comments. I've not read all yet, but I think we need to build a consensus about the basic strategy of this project.

  • Basically I'm negative to add a context menu command "Reload Sidebars". It will help development actually, but I think that it shouldn't be exposed to users by default. For example I rejected proposals about adding "open TST options" command for a long time, because I have a policy; if people need to open options page too frequently, something wrong. Less accessibiltiy to the options page is not the problem we should resolve, instead, we need to struggle to reduce need to change options , with implementing of intelligent behaviors and other efforts.
  • I agree that periodical sync will increase stability. But I need to investigate about other solutions before activating it by default. Periodical sync is a supportive care, but something definitive therapy is better than that. Supportive care enabled by default may reduce motivation to solve the problem fundamentally. (For example I didn't try to optimize the initialization process for a long time because the cache system worked well for me.)

From now I try to read your comments to understand things you actually did...

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

Oops, sorry there were some careless mistakes as you commented at #2239 (comment) , and I've fixed them.

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

After reading the comment #2238 (comment) I've tried the step "Once sidebar is shown, but while still shows loading progress (before fully initialized) I immediately click on a bookmark for:" and I successfully reproduce a failure case: some tabs are not tracked by the master process. Those tabs are opened at the timing between browser.windows.getAll() and ApiTabsListener.startListen():

// background/background.js
    waitUntilCompletelyRestored().then(() => {
      // don't wait at here for better performance
      promisedWindows = browser.windows.getAll({
        populate:    true,
        windowTypes: ['normal']
      }).catch(ApiTabs.createErrorHandler());
    }),
  ...
  // here!
  ...
  ApiTabsListener.startListen();

This problem looks unsolvable, because any fundamental solution may make the initialization process blocked and slow. Now I agree that "reload all" operation is required on such cases as a workaround, and I've introduced more fixes to do the auto-reload-all operation triggered by the function syncTabsOrder().

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

One issue I found which may be relevant to that, when debugging latest from Git master, is:
"SecurityError: The operation is insecure." occurs at

After a research I've realized that it happens when I open a new tab about:newtab. The favicon of the page is chrome://branding/content/icon32.png and toDataURL() raises a security error on such cases. It should be suppressed with the commit piroor/webextensions-lib-tab-favicon-helper@f92cedd

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

After more research I've realized that TabsUpdate.completeLoadingTabs() didn't worked as I expected. Tabs opened while TST is initializing itself will be completed their "loading" state correctly, with the commit 1e54567.

@piroor
Copy link
Owner

piroor commented Apr 24, 2019

Remaining Issues from #2238 still not fixed

  1. "Error: Could not establish connection. Receiving end does not exist" still occurs when caching is enabled

As I commented at #2238 (comment) , I think this kind warning on initialization is a side effect of optimizations.

  1. Tabs opened soon after Firefox startup (with TST sidebar auto shown on startup) while TST is initializing

I thought that it looked impossible to be "resolved" completely due to TST's internal design. After a reconsideration I've realized that those tabs can be tracked without auto-reload. The commit aaf9e11 does that. Now all tab events notified while TST is building tree with tabs fetched via windows.getAll() are listened and stacked until initialization is finished. On my environment, without auto-reload, all tabs I opened while initialization are tracked as expected. Wow!

This should be fixed with the commit 1e54567. ( #2239 (comment) )

  • Sometimes (not always) also shows only URL (instead of title) and/or has FaviconLoader error

I think that the error should be suppressed with some changes I already did. ( #2239 (comment) )

  1. sendMessage(kCOMMAND_PULL_TABS) in rebuildAll() in background.js is returning undefined

As I commented at #2238 (comment) , I think they are not bugs and just side effects from aggressive optimizations.

@piroor piroor mentioned this pull request Apr 25, 2019
@PowerWeb5
Copy link
Contributor Author

@piroor

Thanks for your help. I've been testing versions from Git and then XPI releases for a while, which now include much of my fixes from this PR, and seems like all major issues are now resolved in v3.0.11 XPI release for #2199 and #2238.

@PowerWeb5 PowerWeb5 closed this May 16, 2019
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.

2 participants