How to enforce traditional behaviour on clicking Links?

General discussion and chat (archived)
DjogaRo

How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-01, 09:15

Hi,

on youtube when following links the url in the address bar doesn't change for me and there's no history entry created. When that started I thought that was an "awesome new idea" some google f*... employee had. That spreaded to google.com. And on github I get the same.

Today I noticed, that doesn't happen with Firefox (usually don't use that). There went my theory out the window. After some investigation, I found it's my settings "browser.history.allow*" all set to false enabling that extremely annoying behaviour. With that knowledge I found the thread https://forum.palemoon.org/viewtopic.php?f=3&t=9469, btw. :)

On github (happens there within a project) I tried to look into it, but only found that the hrefs look quite normal, and that the two scripts, of which one must be responsible, are together ~200kB long and sit comfortably in 24 loc - and I wouldn't know what to look for.

But my question now is a bit more general. I want to keep my settings the way they are, but have super modern sites like these in general behave traditionally regarding my browser's history.

So, how can I enforce that on clicking on links in sites my browser acts like I was clicking a link? Or, the culprits try to alter my browser's link click handling and said settings prevent part of it. How to prevent the rest? And btw, what would this rest be?

"Disable JS!" doesn't count. ;)

squarefractal

Re: How to enforce traditional behaviour on clicking Links?

Post by squarefractal » 2015-11-01, 10:25

This is a common technique used on many websites, where event listeners are added to links, and these function called by the firing of the event listener loads the contents of the new page using XHR.

You may have to use an addon which disables event handlers, like RightToClick.

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-01, 12:36

2. attempt: With this logout-timer here I'm too slow for the Pale Moon Forum (pun intended).
3. attempt: No, must be something else. Does this forum not like user agent spoofing? Who wouldn't like that?

Thanks for the info. RightToClick I cannot get to have an impact on the script imposed behavioural change. But prohibiting XHR via uMatrix does the trick at least on youtube.com and google.com. So that's a win.

Though, on github.com this way I get the addressbar's url changing orderly and following page reloads respect the new url. But somehow my browser's history stays untouched. Well I want the website's script to not get to the history, but the browser I want to. How is it the browser is still prevented from making history? :) And how, now, do I prevent the scripts from preventing ... you know what I mean. ?

User avatar
x-15a2
Keeps coming back
Keeps coming back
Posts: 825
Joined: 2014-03-19, 00:28
Location: Triskelion

Re: How to enforce traditional behaviour on clicking Links?

Post by x-15a2 » 2015-11-01, 13:27

It may be that your have browser.urlbar.trimURLs set to True, try setting it to false. I am seeing full URLs in YT and GH using Version: 25.7.3 (x86). I'll try in safe mode or with a test profile and see what I get...


... just tested with both Safe Mode and clean profile and I still get full URLs. Am I missing something (yet again)?

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-01, 13:44

No trimming nor url formatting nor any kind of browser settings related user misinformation, AFAIK.

Try setting those three "browser.history.allow*" settings to false, make sure you do not prohibit XHL nor javascript through uMatrix or anything and you should be able to reproduce. Say, you open any video on youtube in a new tab and then follow a link within youtube, your tab's url will remain the first one. If you then reload the page, you're back to the first video.

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-01, 14:05

I just learned that prohibiting XHR on github prevents me from commenting there. Wonder if that's also the case on youtube - have no account there. So that workaround isn't too acceptable. :problem:

superA
Lunatic
Lunatic
Posts: 310
Joined: 2014-07-03, 12:34
Location: Greece

Re: How to enforce traditional behaviour on clicking Links?

Post by superA » 2015-11-01, 19:49

Hi DjogaRo ,

you mentioned two sites. YouTube and Github.
As far as I could tested them in the past, there is no way to have the behavor you want while having the three "browser.history.allow*" settings to false.
My guess was that both sites need your history ( :D ), for ''unknown'' reason.

..and here comes a coincidence..
Easyprivacy, blocks youtube.com/api/stats/ but has in the whitelist the @@||s.youtube.com/api/stats/playback?$object-subrequest .
This request expose your browser version, plugins and HISTORY, as well as other stats.
http://forums.lanik.us/viewtopic.php?f=62&t=19083

As for Github,
there is another network request, https://api.github.com/_private/browser/stats (!!) , there is no blocking rule in Easyprivacy, blocking it doesnt affect your browsing there either.

User avatar
New Tobin Paradigm
Knows the dark side
Knows the dark side
Posts: 8850
Joined: 2012-10-09, 19:37
Location: Skaro

Re: How to enforce traditional behaviour on clicking Links?

Post by New Tobin Paradigm » 2015-11-01, 19:51

Isn't ajax wonderful?
How far are you prepared to go? How much are you prepared to risk? How many people are you prepared to sacrifice for victory?
Are you willing to die friendless, alone, deserted by everyone? Because that's what may be required of you in the war that is to come.

Image

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-01, 21:09

Hm, wonderful might be slightly overstated.

superA, are you suggesting, the i-net would come to a stop without us sharing our histories? :)
I'm having a hard time accepting this to be impossible. The target urls are exposed in the a-elements href-attributes. Deeming the endeavour impossible is giving up on having the last say on what to do with those.
One way that should work, would be to patch the browsers code to not expose any events to website scripts when clicking and an a-element are involved. I'm hoping for another way, though.

superA
Lunatic
Lunatic
Posts: 310
Joined: 2014-07-03, 12:34
Location: Greece

Re: How to enforce traditional behaviour on clicking Links?

Post by superA » 2015-11-01, 21:33

Good point.
..or just use... the ''all in one'' and ''just works'', Google Chrome..

User avatar
ketmar
Lunatic
Lunatic
Posts: 365
Joined: 2015-07-28, 11:10
Location: Earth

Re: How to enforce traditional behaviour on clicking Links?

Post by ketmar » 2015-11-01, 21:52

you can write userscript to stop that behavior. but i'd better simply disable js for sites (i did!).

Thrawn

Re: How to enforce traditional behaviour on clicking Links?

Post by Thrawn » 2015-11-02, 01:08

ketmar wrote:you can write userscript to stop that behavior. but i'd better simply disable js for sites (i did!).
Most people use Greasemonkey for this, but you can also use Noscript surrogate scripts; feel free to ask for help with those at https://forums.informaction.com

squarefractal

Re: How to enforce traditional behaviour on clicking Links?

Post by squarefractal » 2015-11-02, 06:09

DjogaRo wrote:I'm having a hard time accepting this to be impossible. The target urls are exposed in the a-elements href-attributes. Deeming the endeavour impossible is giving up on having the last say on what to do with those
You didn't even look into the options -- "Disarm event listeners" or so is the name of the preference you have to set from within RightToClick.

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-02, 15:47

@ketmar,@Thrawn: Userscripts is what I was thinking. Still, I was hoping there might have been a setting I don't know about, but others do. If I disable js per site, I might end up in need to write userscripts for lost functionality. :) I'll have a look at informaction. For userscripts I'll use Guer(r)illa Scripting, of course.

Since the evil eventlisteners, I'd have to hinder, might sit on any element between the root node and the leaf I clicked (if the inner workings are somewhat similar to JavaFX'), I guess the best general approach would be to add a listener myself to the root and consume events that involve left mouseclick and an a-element. At least the event system in JavaFX would make that possible. Is that also true for PM's event system? And can one userscript count for several specified sites?

Don't know yet, when I'm going to tackle that, but if I get somewhere, I'll post it here.

@squarefractal: By "I cannot get sth. to do sth." I meant to imply, that I tried some. So yes, I tried that option and also the option to circumvent website scripts' self-defense mechanisms. On google I could activate RTC, but it didn't have an effect. On github I couldn't even activate it. I've got a "Content Security Policies"-message in the browser console about preventing an inline script, when I tried. And since on AMO someone posted, it didn't work for PM, and I can be a sluggard at times, I gave it up after a while.

User avatar
ketmar
Lunatic
Lunatic
Posts: 365
Joined: 2015-07-28, 11:10
Location: Earth

Re: How to enforce traditional behaviour on clicking Links?

Post by ketmar » 2015-11-02, 16:03

DjogaRo wrote:I guess the best general approach would be to add a listener myself to the root and consume events that involve left mouseclick and an a-element. At least the event system in JavaFX would make that possible. Is that also true for PM's event system?
sure.

Code: Select all

window.addEventListener("mousedown", function (evt) {
  // here, you can eat only events for "a" elements, like this:
  // (`evt.target` is the node that should receive the event)
  // there are other ways to check node type, but i simply like using `tagName`
  if (evt.target.tagName === "A") {
    // this is my universal `cancelEvent()` function, inlined ;-)
    if (typeof(evt.preventDefault) === "function") evt.preventDefault();
    if (typeof(evt.stopPropagation) === "function") evt.stopPropagation();
    if (typeof(evt.stopImmediatePropagation) === "function") evt.stopImmediatePropagation();
  }
}, true);
ditto for other events like "mouseup", "click"...

DjogaRo wrote:And can one userscript count for several specified sites?
of course. there is "//@include" meta, you can use simple masks there, and specify as many metas as you want to.

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-02, 21:57

Thanks a lot. I haven't gotten far, yet. I'm puzzled by the script not being executed on youtube and github, while it does on google.

Code: Select all

// ==UserScript==
// @name           Revive History
// @namespace      DjogaRo
// @description    Userscript to counter evil event listeners.
// @include        https://www.youtube.com/?*
// @include        https://github.com/?*
// @include        http://www.google.com/?*
// @include        http://www.google.de/?*
// @include        https://www.google.com/?*
// @include        https://www.google.de/?*
// @include        http://*.google.*/*q=*
// @include        https://*.google.*/*q=*
// @run-at         document-start
// ==/UserScript==

console.log("__test");

window.addEventListener("click", function (evt) {
  var el = evt.target;
  while ( el.tagName !== "A" && (el = el.parentElement) );
  if ( el.tagName === "A" ) {
    if ( typeof(evt.stopPropagation) === "function" ) evt.stopPropagation();
    if ( typeof(evt.stopImmediatePropagation) === "function" ) evt.stopImmediatePropagation();
  }
}, true);

User avatar
ketmar
Lunatic
Lunatic
Posts: 365
Joined: 2015-07-28, 11:10
Location: Earth

Re: How to enforce traditional behaviour on clicking Links?

Post by ketmar » 2015-11-02, 23:14

i didn't looked deeply at it, but:
1. parentNode, not parentElement
2. use `GM_log` instead of `console.log` for GreaseMonkey/GS scripts (and watch Error Console for messages). `GM_log` is the "official" API.

p.s. parentNode due to possible text nodes in the tree.

p.p.s. youtube may use "mousedown" instead on "click", i don't know.

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-03, 06:18

1. Thanks, I thought parentElement would always give the closest ancestor, which happens to be an element. Now I know better. Will adapt.

Weither the script was executed or not, I judged on getting a "__test" in the browser console or not. Can there be a reason for not getting the log message other than the script not being executed? (Considering that I get the message when loading google.com, it couldn't be about PM's settings.)

User avatar
ketmar
Lunatic
Lunatic
Posts: 365
Joined: 2015-07-28, 11:10
Location: Earth

Re: How to enforce traditional behaviour on clicking Links?

Post by ketmar » 2015-11-03, 06:30

DjogaRo wrote:1. Thanks, I thought parentElement would always give the closest ancestor, which happens to be an element. Now I know better. Will adapt.
it works like that (at least it should), but i remember some problems with `parentElement`. this can be a false memory, though.
DjogaRo wrote:Can there be a reason for not getting the log message other than the script not being executed?
yes. invalid "include" mask, for example. youtube links usually looks like "www.youtube.com/watch?", and you're expecting "www.youtube.com/?" — so no hit. the same for github. ;-)

p.s. but thechnically, it's "script not executed", yes. so no. i'm lost. ;-)

DjogaRo

Re: How to enforce traditional behaviour on clicking Links?

Post by DjogaRo » 2015-11-03, 06:54

ketmar wrote:
DjogaRo wrote:1. Thanks, I thought parentElement would always give the closest ancestor, which happens to be an element. Now I know better. Will adapt.
it works like that (at least it should), but i remember some problems with `parentElement`. this can be a false memory, though.
No, after your comment I looked it up. On
https://developer.mozilla.org/en-US/docs/Web/API/Node/parentElement
it says
The Node.parentElement read-only property returns the DOM node's parent Element, or null if the node either has no parent, or its parent isn't a DOM Element.
A not thought through design I'd say. So your memory seems to serve you well.

ketmar wrote:
DjogaRo wrote:Can there be a reason for not getting the log message other than the script not being executed?
yes. invalid "include" mask, for example. youtube links usually looks like "www.youtube.com/watch?", and you're expecting "www.youtube.com/?" — so no hit. the same for github. ;-)

p.s. but thechnically, it's "script not executed", yes. so no. i'm lost. ;-)
Since my include mask spells "www.youtube.com/?*" I thought the asterisk would cover everything url-valid character. Plus I always started out on page "https://www.youtube.com/".

So there is no case, that maybe the script works fine on google, but causes something like an exception on youtube retroactively undoing the console.log()?

Locked