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:
alert(document.URL)
also prints "about:blank".document.addEventListener("DOMContentLoaded", function(){alert(window.location.href)})
prints nothing.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
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 theUpdate: Also only works for a split second.window.location
object (path
andsearch
, to be precise). I could construct anew 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).