feinstaub / webextension_local_filesystem_links

"Local Filesystem Links" is an addon for the Mozilla Firefox webbrowser. It will be ported soon to the WebExtension API and thus also might work for Chromium
https://addons.mozilla.org/en-US/firefox/addon/local-filesystem-links/
GNU General Public License v2.0
52 stars 27 forks source link

Issue 125 - Multiple windows opening #188

Closed AWolf81 closed 1 year ago

AWolf81 commented 1 year ago

Changes

Tests

Fixes

125

@maxm199 would be great if you could test the branch if this is working as expected.

maxm199 commented 1 year ago

Later I'll try this branch and then report back. Thanks

maxm199 commented 1 year ago

Tried several times with multiple windows and never had the issue. Seems to be fine, nice job!

AWolf81 commented 1 year ago

@maxm199 great, thanks for testing. I'll merge this today or tomorrow.

AWolf81 commented 1 year ago

@maxm199 Issue #113 was causing the same issue. The browser's back button caused it. Clicking a regular link and then using the back button was not correctly handled - multiple events were attached.

I think it's a cache issue. The page is with the content script as it's using the cached page.

One way to improve this is to force a reload with the following lines in content.js after $.noConflict():

    var perfEntries = performance.getEntriesByType("navigation");
    if (perfEntries[0].type === "back_forward") { 
        // force reload if browser history is used --> avoid duplicated event handlers
        location.reload();
    }

This would work but I don't like this.

Another solution is to add the webNavigation permission and add the cached tab to injectedTabs. So it won't inject the page again. In background script:

       const browserHistoryHandler = (details) => {
            if (details.transitionQualifiers.includes("forward_back"))
            {
                // console.log("using cached page");
                this.injectedTabs[details.tabId] = true; // Add tabId to keep track of cached injection.
                browser.storage.local.set({ injectedTabs: this.injectedTabs });
            }
        }

        browser.webNavigation.onCommitted.addListener(browserHistoryHandler);

I tested this and it looks OK. I think it's OK to only handle back & forward transition here. The only situation where it could fail is if someone disabled browser history caching. Probably a rare case and it can be fixed by a browser reload.

maxm199 commented 1 year ago

I can't see any issue. Unfortunately I won't be able to test it until tomorrow if you need it. Have a nice day.

maxm199 commented 1 year ago

Just checked from remote. I can confirm that the version I tested 3 days ago had that issue, with the back button on click it opened 2/3 windows. With the last changes it opens just 1 window on back/forward button, nice catch!

AWolf81 commented 1 year ago

OK, thanks for testing and your confirmation. Good to hear that this is working.