devtools-docs/docs/blackboxing.html

97 строки
5.1 KiB
HTML

{{+bindTo:partials.standard_devtools_article}}
<p class="caution">
<strong style="font-weight: normal; font-size: 110%; display:block;">The DevTools docs have moved!</strong>
For the latest tutorials, docs and updates <a href="https://developers.google.com/web/tools/chrome-devtools">head over to the new home of Chrome DevTools</a>.
</p>
<h1>Blackbox JavaScript Source Files</h1>
<p>Like everyone, you get bugs in your application code. You start debugging, but when you step through your code line-by-line, the debugger sometimes jumps into a source file that's not your focus (such as a third-party JS library). I'm sure you've experienced the annoyance of stepping through the library code before getting back to your own application code.</p>
<p>Blackboxing gives you a first-class way to denote library (or other abstraction) code so that the debugger can route around it. When you blackbox a source file, the debugger will not jump into that file when stepping through code you're debugging. </p>
<figure class="screenshot">
<img src="blackboxing-files/blackboxing-unblackboxed.png" />
<figcaption>The screenshot above shows that app.js opened, where a breakpoint was set. When stepping into that code, backbone.js opened, then underscore.js. This can be a time-consuming process and an undesirable one, too.</figcaption>
</figure>
<div class="collapsible">
<h2 id="what-happens">What happens when you blackbox a script?</h2>
<ul>
<li>Exceptions thrown from library code will not pause (if <b>Pause on exceptions</b> is enabled),</li>
<li>Stepping into/out/over bypasses the library code,</li>
<li>Event listener breakpoints don't break in library code,</li>
<li>The debugger will not pause on any breakpoints set in library code.</li>
</ul>
<p>The end result is you are debugging your application code instead of third party resources.</p>
</div>
<div class="collapsible">
<h2 id="how-to-blackbox">How to blackbox scripts</h2>
<p>There are two ways you can add scripts to the blackbox blacklist:</p>
<ol>
<li>Using the Settings panel</li>
<li>Right-clicking on any script in the Sources panel</li>
</ol>
<h3 id="settings-panel">Settings panel</h3>
<p>Use the Settings panel to configure blackboxed scripts. Open the DevTools Settings and under Sources click <strong>Manage framework blackboxing</strong>.</p>
<figure class="screenshot"><img src="blackboxing-files/blackboxing-setting.png" /></figure>
<p>This will open up a dialog where you can input file names of scripts that you would like to add to the blacklist. You can do this a couple of ways:</p>
<ul>
<li>enter the name of a file,</li>
<li>use regular expressions to target:
<ul>
<li>files that contain a specific name <code>/backbone\.js$</code>,</li>
<li>certain types of files like <code>\.min\.js$</code></li>
</ul>
</li>
<li>or enter in an entire folder that contains scripts you want to blackbox such as <code>bower_components</code>.</li>
</ul>
<figure class="screenshot"><img src="blackboxing-files/blackboxing-dialog.png" /></figure>
<p>You may want to temporarily unblackbox a rule for testing purposes. You can do this by changing the behavior to Disabled. If you wanted to remove a rule entirely you can click X to delete it.</p>
<h3 id="context-menu">Context menus</h3>
<p>To use the Settings panel for adding files to the blacklist, you can use the context menu when working in the Sources panel. When viewing a file you can right-click in the editor. And you can right-click on a file in the file navigator. From there choose <strong>Blackbox Script</strong>. This will add the file to the list in the Settings panel.</p>
<figure class="screenshot">
<img src="blackboxing-files/blackboxing-nav-menu.png" /> &nbsp;
<img src="blackboxing-files/blackboxing-text-menu.png" />
</figure>
<p>When you view a blackboxed script in the editor on the Sources panel, you will see a yellow bar indicating that it's blackboxed. Clicking on more expands the bar showing a bit more info about what it means, and how you can disable it.</p>
<figure class="screenshot"><img src="blackboxing-files/blackboxing-expanded.png" /></figure>
<p>When paused on a breakpoint, in the call stack you will see a message stating the number of frames which are blackboxed. You can show these frames if you want, but since they are calls made from a blackboxed script they are hidden unless you click <strong>show</strong>.</p>
<figure class="screenshot">
<img src="blackboxing-files/blackboxing-call-stack.png" /> &nbsp;
<img src="blackboxing-files/blackboxing-stack-expanded.png" />
</figure>
</div>
<div class="collapsible">
<h2 id="toc-conclusion">Conclusion</h2>
<p>Blackboxing scripts can help increase your productivity and help keep your focus on the code you care about. It is easy to enable using any workflow and just as easy to disable if the need to do so arises.</p>
<p>We want to make sure your debugging experience when working with JS frameworks is excellent. Please <a href="http://crbug.com">file a ticket</a> after trying blackboxing if you have ideas on how it can be improved or address your use cases better.</p>
</div>
{{/partials.standard_devtools_article}}