Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebug: how to cd to an iframe

I have a facebook canvas application that runs in an iframe. I would like to debug my page in firebug but can not get the javascript to scope to the iframe that is running my app.

the iframe:

<iframe frameborder="0" src="[app_url_removed]" name="iframe_canvas" id="iframe_canvas" class="canvas_iframe_util" style="height: 905px;"></iframe> 

i've tried all the following and none of them work:

cd(iframe_canvas) cd(window.iframe_canvas) cd(iframe_canvas.window) cd($('iframe_canvas')) 

I have firefox 3.6.13 and I have tried firebug 1.7a11 and firebug 1.6.2

also tried the bookmarklet and various other things from this link Firebug and jQuery selectors in an iFrame to no avail.

like image 446
Kalendae Avatar asked Feb 18 '11 22:02

Kalendae


People also ask

How do I inspect element in iframe?

We can detect if an element is inside an iframe by inspecting the element with the Chrome Developer Tools. An easier way is to perform a Right Click near the element in your browser and see if View Frame Source option is present in the context dropdown.

How to enable iframe in firefox?

You can change this behaviour in your own Firefox installation by typing about:config in the address bar and setting security. mixed_content. block_active_content to false .

How can I change frame in Javascript?

Using switchTo().defaultContent() The switchTo(). defaultContent() method will switch focus to the first frame on the page. In the case of iFrames, the context is switched back to the main (or Parent) document.


2 Answers

use one of these commands:

 cd(frames[0])   cd(frames["iframe_canvas"]) 

and

 cd(top) 

to return to the main window.

Still, due to a bug this currently doesn't work on cross-domain-iframes (http://code.google.com/p/fbug/issues/detail?id=3893). There are two test cases where you can test your evironment for both cases:

  • https://getfirebug.com/tests/content/commandLine/cd.html (same domain, works for me: FF 3.6.13, FB 1.6.2)
  • http://getfirebug.com/tests/issues/3893/issue3893.html (cross domain, fails)

Another possible source of surprise: if you execute more commands at once the cd command seems to not have an effect for the directly following commands:

 >>> cd(frames[0]); location.href;  ["Current window:", Window cdFrame.html]  "https://getfirebug.com/tests/content/commandLine/cd.html"  >>> location.href  "https://getfirebug.com/tests/content/commandLine/cdFrame.html" 
like image 52
tautologe Avatar answered Oct 19 '22 23:10

tautologe


In Chrome there is a dropdown at the bottom top* of the javascript console that lets you switch to a different frame to execute javascript in. Works cross-domain too!

*Updated 2/10/14: In more recent versions of Chrome, this dropdown has been moved from the bottom to the top of the console.

like image 40
Muhd Avatar answered Oct 19 '22 22:10

Muhd