I think it's a timing problem. If you @grant GM_log, you get a success message with this code, but it took over 30 seconds for the page I tested:
var siteframe = window.frames[1]; function getTitle(e){ // Sometimes the frame's location is about:blank, // not that it makes any sense to me. if (siteframe.document.location !== "about:blank") { var sitetitleone = siteframe.document.title; var sitetitletwo = siteframe.document.getElementsByTagName("title")[0]; if (sitetitleone.length == 0 && !sitetitletwo) GM_log("Couldn't get the frame title."); else GM_log("Success!"); } } if (siteframe) { siteframe.addEventListener("load", getTitle, false); }
Yikes. It would be amusingly impractical for a script to take that long to work. I guess I'll just stick to making the bottom frame the top-level frame.
Thank you very much for solving the mystery.
Actually, after having tested this a bit more, I've never seen it take longer than 2 seconds to complete. So I'll be using it after all.
And a follow-up question if I may: why did you prefer GM_log over console.log? The Greasemonkey wiki says it's deprecated and the latter should be used instead.
http://wiki.greasespot.net/GM_log
Re: GM_log, it's just force of habit.
Can't get frame title
Firefox 31.0 • Greasemonkey 2.1
If you right-click the lower frame and choose This Frame → View Frame Info, you can see the original document title. Why doesn't the following script manage to fetch it?