Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the context of the Safari 6 console to an iframe on the page

I know that Chrome let's you pick the context for the console's execution with a dropdown menu and that Firebug let's you cd() into an iframe. I can't figure out how to change the context in Safari's console. Does anyone know how to do this?

like image 492
Aaron Gibralter Avatar asked Feb 19 '13 16:02

Aaron Gibralter


People also ask

How do I change the console in Safari?

To do that, go into Safari's preferences (Safari Menu > Preferences) and select the Advanced Tab. Once that menu is enabled, you will find the developer console by clicking on Develop > Show Javascript Console. You can also use the shortcut Option + ⌘ + C .

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.

How do I change JavaScript settings in Safari?

Open the Settings app on your iPhone. Scroll down until you see "Safari," and tap it. At the bottom of the page, tap "Advanced." On the Advanced page, turn JavaScript on by swiping the button to the right.


1 Answers

Safari, unlike chrome and firefox, has no real support for this functionality and the only option seems to be to access the window object from the console. As you correctly point this will trigger cross domain policy issues, however provided you're running on mac (this does not work for some reason on windows) you can use

open -a '/Applications/Safari.app' --args --disable-web-security

to bypass this. And next on your jsbin you could use something along the lines of

window.frames[0]

to access the window of the page. As far as I can see there is no similar solution for windows, as

Safari.exe --disable-web-security

apparantly does not work.

like image 137
David Mulder Avatar answered Oct 17 '22 04:10

David Mulder