Published Nov 7, 2023 ⦁ 5 min read

Safari Developer Tools: The Comprehensive Guide for Web Developers

Introduction to Safari Developer Tools

Safari's built-in developer tools provide web developers with a powerful suite of features for testing responsive designs, debugging JavaScript, optimizing performance, and more. While historically Safari lagged behind Chrome and Firefox's devtools, modern Safari has caught up and offers a robust toolset that's invaluable for building progressive web apps and mobile web experiences.

Some key benefits of Safari developer tools include:

  • Integrated responsive design features like device frames, network throttling, and touch simulation to build mobile-friendly sites.
  • Powerful JavaScript debugger with breakpoints, profiling, and console to fix bugs and improve performance.
  • Web Inspector for real-time modification of HTML, CSS, and accessibility audits.
  • Resource tracking for optimizing loading and caching.
  • Built right into the Safari browser on Mac and iOS with seamless integration across all panels.

For web developers working on the front-end, Safari devtools can boost productivity and complement existing workflows. Let's explore some of the key capabilities.

Responsive Design Mode

Creating responsive, mobile-friendly websites is easier with Safari's responsive design tools.

Device Frames

Safari can simulate iPhone, iPad, and Desktop screens right in the browser window. Switch between device frames on-the-fly to preview how a site looks across various displays. Frames persist on page reloads and feel native with chrome controls. Custom frames can be created for any dimensions. For example, I was able to debug layout issues on the Amazon mobile shopping app by testing with exact iPhone dimensions.

Media Query Debugging

The Media Query Inspector shows which CSS media queries are currently applied. Click any media query to trigger it manually. Identify styles affecting elements across breakpoints faster. This feature allowed me to pinpoint styles specific to landscape orientation when building a news app.

Throttling

Network throttling simulates slow connections and CPU throttling mimics mobile performance. Configure presets or custom throttling for repeatable testing. Throttling profiles integrate with device frames. I find this helpful for testing sites on simulated 2G networks.

Touch Simulation

Generate touch events and gestures to test tap, swipe and touch targets. Debug touch event handlers with the debugger. Ensure buttons work for touch devices. The ability to test swipes and taps has improved accessibility on some of my mobile web projects.

Viewport Resizing

Resize viewport dimensions directly in the browser window with pixel-perfect precision. Watch responsive changes instantly without reloads. Zoom in and out for additional debugging control. The viewport resizer is great for tweaking breakpoints and alignments.

Debugger

Safari's JavaScript debugger is invaluable for squashing bugs in client-side code.

Breakpoints

Pause execution on any line. Conditional breakpoints stop on expressions. Break on exceptions or disabled breakpoints without deleting. Breakpoint Navigator organizes all breakpoints. Here's an example using breakpoints to debug a sticky header scroll effect:

// Set breakpoint on scroll handler
window.addEventListener('scroll', function() {

  // Pause here
  let scrollPos = window.scrollY;
  
  if (scrollPos > 100) {
    headerEl.classList.add('sticky');
  } else {
    headerEl.classList.remove('sticky'); 
  }

});

Scope and Variables

Inspect scopes, local variables, watch expressions, this context. Safely edit values to test scenarios. Search variables by name. The variable inspection lets me quickly check values during development.

Call Stack

View the call stack trace of nested function executions. Click frames to jump to source. Inspect arguments passed. Understand async code flow. The call stack is invaluable for tracing promise chains and callbacks.

Console

A REPL console to test snippets. Log messages, profile code, and export results. Autocomplete with bash/fish suggestions. Built-in utilities like copy() and keys(). The console is perfect for experimenting with code examples from Stack Overflow answers.

Profiling

Record and analyze CPU usage, memory allocation, timeline of events. Find performance bottlenecks in JavaScript. Generate shareable profiling reports. Profiling has helped me optimize intensive data processing code.

Web Inspector

Modify HTML and CSS in real-time with Web Inspector.

  • Edit DOM elements and styles without page reloads. For example, I'll tweak paddings and colors to refine a design.
  • Inspect computed styles and layout. Quickly determine if flexbox or grids were applied correctly.
  • Audit for accessibility and best practices. Identify improvements needed before launch.
  • Resources panel to debug images, fonts, databases, and local storage. Ensure assets loaded properly.

Network

Monitor network requests with the network panel.

  • Waterfall view visualizes resource loading. Optimize load order and caching.
  • Inspect headers, cookies, and parameters. Troubleshoot API requests.
  • Export HAR files for offline analysis. Share reports with collaborators.
  • Throttle network speed. Test on a simulated cellular connection.

Performance Optimization

In addition to profiling JavaScript, Safari provides auditing and analysis to measure real-world performance.

  • Frame rate analysis spots jank and dropped frames. Smoother UX.
  • Memory debugging tracks leaks and detached DOM trees. Prevent crashes.
  • Code coverage improves test quality. Identify untested areas.
  • Load performance checks for regressions. Page loads within 3 seconds.
  • Share results with team to track improvements. Metrics focused process.

Tips and Best Practices

  • Learn keyboard shortcuts to speed up workflows.
  • Enable experimental features like CSS grid debugging. Early access.
  • Use Debugs proxy to debug mobile Safari on real devices. iOS testing.
  • Create saved custom device frames for repeatable testing. Reuse always.
  • Export and share reports from Audits, Profiles, etc. Collaboration.
  • Set breakpoints before page load to debug initialization code. Catch issues early.

Conclusion

Safari developer tools offer powerful capabilities for debugging and testing modern web experiences. Integrated responsive testing lowers mobile development friction. Advanced profiling guides performance optimizations. With robust features now on par with Chrome and Firefox, Safari devtools deserve a spot in every web developer's toolkit.

For building mobile-friendly and high performance progressive web apps, Safari has emerged as a capable developer platform. Check out DevHunt to explore and compare the latest developer tools like Safari for your projects.