proginosko / LeechBlockNG

LeechBlock NG (Next Generation) for Firefox is a simple productivity tool designed to block those time-wasting sites that can suck the life out of your working day. All you need to do is specify which sites to block and when to block them.
https://www.proginosko.com/leechblock/
Mozilla Public License 2.0
650 stars 61 forks source link

Page 'onunload' and 'onbeforeunload' - Prevents Block #386

Open HeyVern opened 6 months ago

HeyVern commented 6 months ago

Certain webpages use 'onunload' and 'onbeforeunload' to present such messages as "are you sure you want to leave this page"...etc. The issue is, if this is a page you are trying to block with a timer, the user can simple press 'cancel' and the page navigation to the block page is canceled effectively allowing the user to bypass the block until the page is manually refreshed. Is there any way to bypass such prompts and force the page to refresh anyway, or simply block the script execution by filtering it out?

Example page: taming.io

Thanks!

smayer97 commented 6 months ago

looks like this is the same or similar problem as presented for the Chrome version here: https://github.com/proginosko/LeechBlockNG-chrome/issues/61

proginosko commented 6 months ago

Do you have the option "Immediately block pages..." selected?

smayer97 commented 6 months ago

I do not know if he does, but I do on the Chrome version.

HeyVern commented 6 months ago

Yes. Works on every page except those that use onunload or onbeforeunload to present a dialog box. Leechblocker tries to navigate away from the page; however, the dialog box is presented about the page navigation, and the user can click cancel.

proginosko commented 6 months ago

This is an interesting problem to solve, at least on Firefox. Every time LB tries to block a page with an onbeforeunload listener, the "Leave page"/"Stay on page" dialog box pops up, but LB keeps trying to block the page, resulting in an ever-growing stack of dialog boxes (one for each attempt to block!). You can keep clicking "Stay on page" but LB will keep trying to block it, until you eventually click "Leave page". I'm not sure it's possible for an extension to bypass or disable the onbeforeunload listener, but I will keep investigating.

In the meantime, one workaround for Firefox is to completely disable the beforeunload event:

https://support.mozilla.org/en-US/questions/1338923

HeyVern commented 6 months ago

@proginosko thanks, but users are using chrome.

This site discusses the topic and suggests injecting $(window).off('beforeunload.windowReload'); into the page. It could disable the popups. Not sure if this is possible via the plugin, but it's said to work with Chrome and Edge.

proginosko commented 6 months ago

Thanks for doing some research on this. The downside of this solution is that it requires the jQuery library, and while LB uses that for its GUI, it wouldn't really be good practice to inject that entire library into a web page just to remove one event listener! I will continue to investigate alternative solutions.

HeyVern commented 1 month ago

Any news on this particular issue? Thanks!