In Chrome this seems to be easy, in the source tree, you see al scripts, including those loaded by iframes, so you can open them and set debug breakpoints. In Safari inspector although, in the Resources tab, the tree only shows resources loaded on the top window. I know the console has a dropdown to evaluate an expression on the context of an iframe, but I need to debug using breakpoints, is there a way to do that in Safari?
Asked
Active
Viewed 1,219 times
1
-
did you try adding ```debugger;``` in your iframe source to prompt the browser to bring it up (when dev tools are open)?? – pherris Aug 13 '14 at 14:16
-
I haven't, but sadly I can't (neither adding console.log around), the code I want to debug is in a production site. – Benja Aug 13 '14 at 18:35
-
I would replace the questionable JS file from prod with a local copy using Fiddler and add your debugger to see if this triggers the debugger console. Check out this write up: http://stackoverflow.com/a/3936627/1861459 – pherris Aug 14 '14 at 21:24
-
sorry I didn't try that, I had to move on, that was just too much labor for something so simple, but feel free to fill it as an answer as other readers will find it a viable solution. – Benja Aug 26 '14 at 01:05
1 Answers
1
You can replace the questionable JS file from prod with a local copy using Fiddler (windows) or Charles (mac). These tools can be configured to serve the local copy when the browser requests the remote copy.
This allows you to modify or debug JS from any domain - even if you do not own the code. Adding your debugger to the local file should trigger the debugger console.
Fiddler: check out this write up for Fiddler details: stackoverflow.com/a/3936627/1861459
Charles: use the Map Files feature of Charles: http://www.charlesproxy.com/documentation/tools/map-local/

pherris
- 17,195
- 8
- 42
- 58
-
2thanks, so it seems Safari doesn't support debugging iframe scripts unless a `debugger;` break is triggered from the script itself, I also noticed if you console.log(), the traceback on the console will take you to the script source. – Benja Aug 26 '14 at 20:46