views:

465

answers:

1

I have created a Greasemonkey script that runs fine in the firebug editor, with the Greasemonkey specifics removed, but not when I try to package it as a userscript. The Firefox error console is reporting that an iframe I am trying to use is undefined.

I've cut the userscript down to a minimum case where it should be printing the iframe html into the firebug console, and does when run in the firebug editor, but is not working as a userscript:

// ==UserScript==
// @name          Movies
// @include       http://*.princecharlescinema.com/*
// @include       http://princecharlescinema.com/*
// ==/UserScript==

// stop script loading multiple times
if (top !=self) return;

var iframeHTML = window.frames['iframe2'].document.documentElement.innerHTML;
unsafeWindow.console.log(iframeHTML);

An example page the script is intended for

If it's of any use the gist of the full script is I collect all the td tags from this iframe, get some information from them, and then insert some new html into some of the same td tags.

Any help would be appreciated.

+1  A: 

Perhaps you need to wait for DOMFrameContentLoaded

Jeremy Stein
I tried using a long timer, but the problem is not with some content inside the iframe not being ready, but Greasemonkey is acting like the actual iframe tag itself doesn't exist.
aston
Testing a long timer and identifying the frame by its array position, [2], instead of its name attribute got it working. DOMFrameContentLoaded is a better solution than a setTimeOut.
aston