The problem is AJAX. When you enter a URL or refresh the page, your script works. When you click the Activity Log button, the script is not. Iframes are not a factor for the symptoms you report.
This is because clicking this link never loads a new page; it calls AJAX calls that replace part of the content, making it look like a new page, but it is not.
So, if you want your script to catch fire on the "new" "main pages", you should use methods like this answer .
In the case of Facebook, the only thing that usually changes is the reported URL (but without running hashchange!) And the contents of the #mainContainer div.
You should also @include use all FB pages, since pages like https://www.facebook.com/*/allactivity* are often accessed only through AJAX, so your script should be run on the previous page.
This script will solve the problem posed in your question:
// ==UserScript== // @name Purge My Facebook // @namespace http://www.ardaterekeci.com // @description test // @include http://www.facebook.com/* // @include https://www.facebook.com/* // @version 1 // ==/UserScript== var pageURLCheckTimer = setInterval ( function () { if ( this.lastPathStr !== location.pathname || this.lastQueryStr !== location.search || this.lastPathStr === null || this.lastQueryStr === null ) { this.lastPathStr = location.pathname; this.lastQueryStr = location.search; gmMain (); } } , 222 ); function gmMain () { if (window.self === window.top) alert ('"New" main (top) page loaded.'); else alert ('"New" iframed page loaded.'); }
However, since the page is heavily AJAXed, you will find that firing when the first page loads will almost always be too early.
The smart thing is to use waitForKeyElements on the part of the page that you really need. (which is not indicated in the question.)
Here is an example of using waitForKeyElements . Note that in order to use @require in Chrome, you must use Tampermonkey (which you should do anyway).
Brock adams
source share