Streaming is available in most browsers,
and in the WWDC app.
Auditing Web Content with Web Inspector
Discover a new way to ensure your web content meets team coding standards and that you can deliver better code even without reliance on automated test systems. Find out how to use the Audit tool in Web Inspector to quickly and easily audit your web content during development so important compliance details don't slip by.
Hello. I'm Jonathan Davis, web technologies evangelist for the Safari and WebKit teams. Welcome to Auditing Web Content with Web Inspector. In the process of building web content, developers have a lot of details to check. Maybe it's following a CSS class name convention or ensuring good accessibility on the page. There can be so many details that they're easy to forget and tedious to find the issues. A built-in checklist would be ideal. Some teams set up automated testing in a continuous integration system using technologies like Safari's WebDriver, available for macOS and now iOS. WebDriver is a great tool for catching code changes that break expected functionality for users. But for web developers who want to check that their in-progress work meets code expectations, Web Inspector now includes a new audit system available with Safari 13 on macOS that provides a quick, easy and more convenient way to check web content. In this video, I'll show you how to use audits in Web Inspector, how to work with tests and understand their results, and finally I'll cover how to create custom audits for your projects. To get started, you'll need to enable the Develop menu to access Web Inspector.
Just load up Safari Preferences, click on Advanced and click to enable the Show Develop Menu in Menu Bar option.
Now just load up a web page and open Web Inspector from the Develop menu. Or use the keyboard shortcut Command-Option-I.
Let's take a look at WebKit.org as an example. Click over to the audit tab.
And in the left sidebar is a list of audits. Click the arrow to the left of an audit to expand it. An audit is a collection of test groups and tests. Test groups don't have any functionality except to act as organizational containers for a collection of individual tests. It's easy to run audits. Click the Start button to run all of the available audits. Or you can right click on an audit for a contextual menu with more actions. To run a single audit, right click on the audit and select Start. Or you can hover over the right area of the side bar and a play button will appear. Or click to select it and press the space bar. Audits are fast and update in real time as tests are completed.
Another way to control which audits are run is to click the Edit button at the bottom of the navigation sidebar.
Here you can toggle the checkboxes on the row next to individual tests, test groups or entire audits to selectively enable or disable them. Click the done button at the bottom when you're finished editing. A list of any collected results will appear below the audits in a results folder with each of the results collected into Run folders.
Expand the Run folder to access the results of the audit for that run. The result runs are kept available across reloads of the page so you can modify the webpage and rerun the audit for updated results. That way you can compare the pass rate for example. Results will be cleared when Web Inspector is closed.
Clicking on the results of the demo audit run displays a report that shows example result levels and result data.
The first three result levels should be familiar if you've ever used XCode. The passed level shows a test that's passed, meaning the code met the expectations of the test. Warning is a soft pass. It says even though the code passed the test, there are things that could be changed. Failed tells you the code did not pass the test.
Web Inspector includes some built-in audits by default which can be disabled but not deleted. One of the default audits provides tests that check a webpage for mark-up that meets some common guidelines for good accessibility.
Let's dig into the results of running the accessibility audit on WebKit.org.
The overall score shows that WebKit does fairly well. But there's room for improvement.
In the failure cases shown in the results, the DOM node where the failure was detected is shown as an interactive DOM tree. Expanding the DOM tree for the node allows you to access child nodes. And hovering over them will highlight the specific elements on the page, just like using the elements tab.
This makes it trivially easy to understand what code in your web content needs improvement.
To fix this, I can simply click this arrow to go right to the node in the elements tab. The problem is elements with the role of menu need their child elements to have a role of menu item.
So I simply need to add a new role attribute with a value of menu item to each of the child elements of the menu. I'm going to quickly add the missing attribute to each of these elements.
Just a couple more.
Okay. Now I'll switch back to the audit tab so I can rerun the audit and see the new results with these changes in the DOM.
Perfect. The page now passes all of the tests. I simply need to incorporate those changes into the actual code for the site.
You can see how easy it is to spot problems and fix them all conveniently within Web Inspector. Audits and audit results can be exported and re-imported. Click the Export button to save the results into a JSON file. They can be re-imported into Web Inspector with complete access to the results, including interactive DOM nodes, when elements on the page match the nodes in the report.
You can also export the built-in audits to see an example of how to write your own audits. As most teams will have their own unique code objectives, writing your own custom audits is one of the most powerful aspects of using the audit framework in Web Inspector.
Audits in Web Inspector are quick and convenient, so I hope you'll give them a try using the built-in accessibility audit on your own web pages.
Use the portable audit format to create your own audits and ensure in-progress code meets your project standards. And we love hearing from you and hope you'll file bug reports for any issues you find or feature requests you might have. For more information and additional resources about what I've covered, use the links in the resources section associated with this video.
Looking for something specific? Enter a topic above and jump straight to the good stuff.
An error occurred when submitting your query. Please check your Internet connection and try again.