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

New action for Back or close #69

Closed
ygoe opened this issue Oct 13, 2017 · 13 comments
Closed

New action for Back or close #69

ygoe opened this issue Oct 13, 2017 · 13 comments

Comments

@ygoe
Copy link

ygoe commented Oct 13, 2017

I'm using a custom action in FireGestures to go back but if it's the first page in history, then close the tab. Here's the custom JavaScript, in case it will be any useful in Firefox 57 (still on Firefox 56, evaluating replacements for November).

var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                   .getService(Components.interfaces.nsIWindowMediator);
var enumerator = wm.getEnumerator(null);
var winCount = 0;
var myWindow;
while(enumerator.hasMoreElements()) {
  myWindow = enumerator.getNext();
  winCount++;
}

if (getBrowser().canGoBack)
    //getBrowser().goBack();
    BrowserBack();
else if (getBrowser().mTabContainer.childNodes.length == 1)
{
    if (winCount > 1)
        window.close();
    else
    {
        getBrowser().removeTab(getBrowser().selectedTab);
        setTimeout(myWindow.minimize, 10);
   }
}
else
    getBrowser().removeTab(getBrowser().selectedTab);

Could this action be added to the addon?

@Robbendebiene
Copy link
Owner

I have to admit, that this would be an useful option for the backwards action, but the webextension API currently does not provide a proper way to get the history of a single tab. I would have to inject a little peace of code in the tab itself which checks, if there are any further entries in the history and then (in the case of no further entries) sends a message to my addon which indicates, that the tab should be closed (because a tab can not close itself).

Because of this complications I won't implement it, but I'm looking forward to a better history API by mozilla. For more information:
https://bugzilla.mozilla.org/show_bug.cgi?id=1378651
https://bugzilla.mozilla.org/show_bug.cgi?id=1381922

@ygoe
Copy link
Author

ygoe commented Oct 15, 2017

Thank you for the explanation. I voted for both Mozilla bugs. I guess Firefox will remain a noticeable bit less comfortable for a long while now.

@ygoe
Copy link
Author

ygoe commented Jun 5, 2020

Is this possible now? And could I write a custom script as gesture action to do it?

@Robbendebiene
Copy link
Owner

Sorry, but this is still not possible.

I plan to add some API to user scripts so you can close tabs via a user script. However even then the solution for your problem would still be a little bit hacky, since there is no proper history API provided by Firefox.

@Robbendebiene
Copy link
Owner

Robbendebiene commented Jun 25, 2020

The best workaround I found so far is the following user script:

window.history.back();
setTimeout(async () => { 
    const tabs = await API.tabs.query({active: true, currentWindow: true});
    API.tabs.remove(tabs[0].id);
}, 500);

@Robbendebiene
Copy link
Owner

After more than 2 years there is still no hope for the Firefox API that is required to properly solve this issue. Since the workaround kind of works, I consider this issue as solved.

@norill
Copy link

norill commented Dec 26, 2020

Sorry, but this is still not possible.

I plan to add some API to user scripts so you can close tabs via a user script. However even then the solution for your problem would still be a little bit hacky, since there is no proper history API provided by Firefox.

haven't tested it but looks like this api has the required functionality
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/history

@Robbendebiene
Copy link
Owner

haven't tested it but looks like this api has the required functionality
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/history

No, this API can only retrieve the browser history and not the history of individual tabs.

@ygoe
Copy link
Author

ygoe commented Jan 31, 2022

That workaround does nothing here. Neither will it go back, nor will it close anything. But I see this error in the page's console:

Content Security Policy: Die Einstellungen der Seite haben das Laden einer Ressource auf eval blockiert ("script-src").

@Robbendebiene
Copy link
Owner

@ygoe This is the reason for the error: #569

@ygoe
Copy link
Author

ygoe commented Jan 31, 2022

Great, I already came to that Firefox bug through a limitation of FireMonkey (and already noticed your name there). Doesn't look like Firefox is doing much for extensibility. I'm wondering what all those new versions every couple weeks are for.

@norill
Copy link

norill commented Apr 8, 2022

i have implemented the functionality required to make this possible, but the patch is stuck with no one to review it.
https://bugzilla.mozilla.org/show_bug.cgi?id=1760523

@ygoe
Copy link
Author

ygoe commented Nov 18, 2022

The best workaround I found so far is the following user script:

window.history.back();
setTimeout(async () => { 
    const tabs = await API.tabs.query({active: true, currentWindow: true});
    API.tabs.remove(tabs[0].id);
}, 500);

This has the limitation that intra-page back navigations will prematurely close the tab, even though the back navigation was executed and there would be more backwards history available. So unfortunately it's not suitable for production.

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

No branches or pull requests

3 participants