3096

Greasemonkey script only runs when page is reloaded

Question:

I am working on a Greasemonkey script to turn some text into links on a <a href="http://www.rallydev.com" rel="noreferrer">a Rally</a> page. The script works fine <em>only</em> when I reload the page. If I navigate to the page in any manner (links, browser forward/back) the script does not run, despite the fact that the Greasemonkey menu shows my script at the bottom, with a checkmark.

Here is an example URL:

https://rally1.rallydev.com/#/4745909548/detail/userstory/6138899084/changesets

My matching rule:

/^https://.*\.rallydev\.com/.*/changesets$/

I don't know if the hash is causing a problem, but everything is fine when I reload.

Not sure where to go from here. Any help is appreciated.

Answer1:

It's impossible to be sure what's going on, because the target page(s) are behind a pay-wall and their alleged "Free Trial" mechanism blows chunks.

Here are some possible causes of the current behavior:

<ol><li>The initial request is insecure (http) but redirects to a secure page (https).</li> <li>The first page load does a some other kind of redirect to the actual page.</li> <li>The target content is in an <iframe> that does not load right away.</li> <li>The target content is AJAXed-in.</li> <li>Something exotic that we would need to see the actual page to figure out.</li> <li>The initial URL does not really end in changesets.</li> </ol>

Also, get into the habit of escaping the /s in the <em>middle</em> of regular expressions. It's not always needed, but it will eventually bite you in the [censored] if you don't. So the script should use:

// @include /^https:\/\/.*\.rallydev\.com\/.*\/changesets$/

to start, but see below.

<br /> Steps to a solution:

<ol><li>

Change your @include to account for http and the Possibility of trailing space or trailing slash in the URL. Use:

// @include /^https?:\/\/.*\.rallydev\.com\/.*\/changesets(?:\s|\/)*$/ </li> <li>Examine the page with <a href="https://addons.mozilla.org/en-US/firefox/addon/firebug/" rel="nofollow">Firebug</a>. Is the content AJAXed-in? Is it in an <iframe>? If so, what is the iframe URL, if any?</li> <li>To also detect AJAX and/or redirects, use <a href="http://getfirebug.com/wiki/index.php/Net_Panel" rel="nofollow">Firebug's Net panel</a> and/or <a href="http://www.wireshark.org/" rel="nofollow">Wireshark</a>.</li> <li>If possible, provide us with login credentials so that we may see a problematic page.</li> <li>Snapshot a problematic page (Save it via Firefox) and link to that HTML and JS in <a href="http://pastebin.com/" rel="nofollow">Pastebin.com</a>.</li> <li>

Consider using code like:

if (window.top != window.self) { //--- Don't run on/in frames or iframes. return; }

To have the script run only in (or not in) iframes, as applicable.

</li> </ol>

<br /> If the problem is caused by AJAX delays (or loading of new content), get around that by using <a href="https://gist.github.com/2625891" rel="nofollow">the waitForKeyElements() utility</a> as shown in <a href="https://stackoverflow.com/q/8281441/331508" rel="nofollow">"Fire Greasemonkey script on AJAX request"</a>.

Recommend

  • In Mercurial what's the difference between hg graft and hg rebase
  • Translate the intent of this PHP regex for multiline strings, into Python/PERL
  • Create branch at specific change set, move changests after this point to different branch
  • Mercurial get branch name by changeset
  • Checkin policy to make sure changesets are associated with Tasks
  • swift afnetworking ssl pinning
  • Why is `mfix` not total in `MaybeT`
  • Counting open tickets for each day for a given period - Crystal Reports 11.0.0.895
  • Is there a limit to how many levels you can nest in JavaScript?
  • How do I differentiate between databases when using e.g. sequence
  • android test support flavors and build type variants?
  • Liquibase: changeset auto generate ID
  • PayPal REST API cross reference transaction with payment
  • as3 addChild into a generated triangle
  • Collecting wall posting permission when using the Facebook Registration plugin
  • Liquibase 3.3.3 refusing to run “due to maven configuration”
  • Braintree Dropin UI does not work with Ionic Framework unless force refresh
  • vue-router and Express
  • Creating a EditorTemplate MVC3
  • JSPM - Are there any advantages/disadvantages in including client side library files using import vs
  • What to use (best/good practice) for the secret key in HMAC solution?
  • How to search for a record and then delete it
  • FIR filter in CUDA (as a 1D convolution)
  • How does CoreLocation locate the device?
  • XGBOOST - DMATRIX
  • bcrypt-nodejs compare method returns false every time
  • How to set infinite shared access signature policy in azure?
  • Getting EOFError along with exceptions when using ftplib
  • update record in database using jdatabase
  • Unique SMS sender id?
  • Manually Timing out a C# Thread
  • Criterion causing memory consumption to explode, no CAFs in sight
  • Connecting bluetooth device to windows phone 8 application
  • DIV instruction jumping to random location?
  • TextToSpeech.setEngineByPackageName() triggers NullPointerException
  • Rails Find when some params will be blank
  • why overloaded new operator is calling constructor even I am using malloc inside overloading functio
  • JavaScriptCore crash on iOS9
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • How can I estimate amount of memory left with calling System.gc()?