How to disable JavaScript navigation for a domain?

Ask for help about NoScript, no registration needed to post
jez9999
Posts: 4
Joined: Mon Dec 29, 2014 2:11 pm

How to disable JavaScript navigation for a domain?

Post by jez9999 »

YouTube has recently introduced a damned annoying "feature" - when you're viewing a playlist, it immediately navigates to the next video when the current video ends. There doesn't seem to be any setting to stop this.

I think the easiest way to stop it would be to disable all JavaScript navigation on youtube.com, or preferably display a yes/no prompt each time it tries. Is there a way to do this with NoScript? If not, I think it would be a good addition. I want to continue allowing all other JavaScript, so I have set NoScript to allow scripts globally, and it doesn't stop YouTube from JS-navigating away from the page.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0 SeaMonkey/2.31
User avatar
therube
Ambassador
Posts: 7979
Joined: Thu Mar 19, 2009 4:17 pm
Location: Maryland USA

Re: How to disable JavaScript navigation for a domain?

Post by therube »

URL: https://www.youtube.com/watch?v=toHlMD5 ... jPbNs2M6Yo
> when you're viewing a playlist, it immediately navigates to the next video when the current video ends

I believe that "squiggly"-like icon is supposed to control that?
(I find it a PITA too cause I typically don't want it enabled, but am never sure in what state it is?)
Oh, it looks like they've removed it?
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.19) Gecko/20110420 SeaMonkey/2.0.14 Pinball NoScript FlashGot AdblockPlus
Mozilla/5.0 (Windows NT 5.1; rv:34.0) Gecko/20100101 SeaMonkey/2.31
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: How to disable JavaScript navigation for a domain?

Post by barbaz »

I think you will need to use a surrogate script to do what you want.

Would the following work for you? WARNING: UNTESTED

Code: Select all

noscript.surrogate.confirm_yt_exit.replacement : if (window.top.location.hostname == 'www.youtube.com') { window.addEventListener('beforeUnload', function(e){return 'Llllllll';}, false); }
noscript.surrogate.confirm_yt_exit.sources : @.youtube.com/watch?*
This would pop up a confirmation dialog *every time* you try (or the page tries) to leave a video page on YouTube, so it might be annoying...

I block so much on YouTube that I can't test this myself, sorry.
*Always* check the changelogs BEFORE updating that important software!
Mozilla/5.0 (X11; FreeBSD amd64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17
jez9999
Posts: 4
Joined: Mon Dec 29, 2014 2:11 pm

Re: How to disable JavaScript navigation for a domain?

Post by jez9999 »

barbaz wrote:I think you will need to use a surrogate script to do what you want.

Would the following work for you? WARNING: UNTESTED

Code: Select all

noscript.surrogate.confirm_yt_exit.replacement : if (window.top.location.hostname == 'www.youtube.com') { window.addEventListener('beforeUnload', function(e){return 'Llllllll';}, false); }
noscript.surrogate.confirm_yt_exit.sources : @.youtube.com/watch?*
This would pop up a confirmation dialog *every time* you try (or the page tries) to leave a video page on YouTube, so it might be annoying...

I block so much on YouTube that I can't test this myself, sorry.
Is there no way to detect whether it's JavaScript that's caused the navigation, as opposed to your manually changing the URL?
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0 SeaMonkey/2.31
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: How to disable JavaScript navigation for a domain?

Post by barbaz »

Well there are a number of different ways for JS to change the location, including but not limited to the following

Code: Select all

window.location.href = 'https://noscript.net/';

Code: Select all

document.getElementsByTagName('a')[0].click();

Code: Select all

document.location.href='https://noscript.net/';
*Always* check the changelogs BEFORE updating that important software!
Mozilla/5.0 (X11; FreeBSD amd64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17
jez9999
Posts: 4
Joined: Mon Dec 29, 2014 2:11 pm

Re: How to disable JavaScript navigation for a domain?

Post by jez9999 »

True, but it would be nice if the browser provided some kind of general "JS caused this navigation" flag.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0 SeaMonkey/2.31
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: How to disable JavaScript navigation for a domain?

Post by barbaz »

jez9999 wrote:True, but it would be nice if the browser provided some kind of general "JS caused this navigation" flag.
Nice but probably not technically possible (note the second one is actually just clicking on a link, which is a normal thing for a user to do)
*Always* check the changelogs BEFORE updating that important software!
Mozilla/5.0 (X11; FreeBSD amd64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17
jez9999
Posts: 4
Joined: Mon Dec 29, 2014 2:11 pm

Re: How to disable JavaScript navigation for a domain?

Post by jez9999 »

Sure, but the browser knows whether it's been triggered by JS or a user clicking.
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0 SeaMonkey/2.31
barbaz
Senior Member
Posts: 11143
Joined: Sat Aug 03, 2013 5:45 pm

Re: How to disable JavaScript navigation for a domain?

Post by barbaz »

I did a quick Internet search about how to check if firefox browser location was changed by javascript, and couldn't find anything on the subject...
*Always* check the changelogs BEFORE updating that important software!
Mozilla/5.0 (X11; FreeBSD amd64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.60 Safari/537.17
User avatar
Thrawn
Master Bug Buster
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: How to disable JavaScript navigation for a domain?

Post by Thrawn »

Probably a more practical, but still complex solution would be to find the piece of script that is actually performing the unwanted behavior, and write a surrogate that specifically targets it.
======
Thrawn
------------
Religion is not the opium of the masses. Daily life is the opium of the masses.

True religion, which dares to acknowledge death and challenge the way we live, is an attempt to wake up.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:34.0) Gecko/20100101 Firefox/34.0
Post Reply