2

This very simple userscript has been getting the best of me:

// ==UserScript==
// @name        TEMP
// @match       https://*.facebook.com/
// @match       https://*.facebook.com/?*
// @grant       none
// @run-at document-start
// ==/UserScript==

alert(window.location.href);

When loading a new tab with the Facebook homepage, it correctly prints the current URL. However, if I'm already on an existing Facebook page, and click the top left Facebook logo to go to the homepage, it'll wrongly print, for a brief moment, the pseudo-URL about:blank.

Why is it happening, and more importantly, how to fix it?

This is on Firefox 67 and GreaseMonkey 4.9.
(see the edit history for a longer demo.)

Updates:

  1. alert(document.URL) also prints "about:blank".

  2. document.addEventListener("DOMContentLoaded", function(){alert(window.location.href)}) prints nothing.

  3. window.addEventListener("load", function(){alert(window.location.href)}) prints a very long URL that does not match the one in the address bar; it's on the form:

    https://www.facebook.com/?ref=logo&fb_dtsg_ag=AAAAAAAAAAAAAAAAAAAAAAAAAAAA__BBBBBBBBBBBBBB_CC%3DDDDDDDDDDDDDD--MeetvEEEEEEEEEEEEE_FFFFFFFFFFHw&ajaxpipe=1&ajaxpipe_token=GGGGGGGGGGGGGGGG&no_script_path=1&quickling[version]=<very long string indeed...>&__spin_t=9999999999&__adt=2
    
  4. document.baseURI works! (why?) - but this is not an ideal solution because in the grand scheme of things I actually want to access other properties of the window.location object (path and search, to be precise). I could construct a new URL() with this, but to be honest I'd prefer to avoid doing so, if at all possible (also wanted to be consistent throughout the entire script). Update: Also only works for a split second.

Marc.2377
  • 7,807
  • 7
  • 51
  • 95
  • Was going to upvote this, but then installed that test script and tried to replicate for a minute or 2 (no FB login). It works fine for me on both GM 4.9 and Tampermonkey. Do you have specific target urls or a more exact recipe? Perhaps something else in your FF profile or computer is interfering? Try a new bare FF profile (with only TM/GM installed). Try a different PC. – Brock Adams Jun 25 '19 at 20:19
  • 1
    Hi @BrockAdams, I just verified, what you said is true. But the issue is reproducible when logged in. I tried it on TamperMonkey and ViolentMonkey as well. – Marc.2377 Jun 26 '19 at 01:48

0 Answers0