index.rst (17454B)
1 ================ 2 Console messages 3 ================ 4 5 Most of the Web Console is occupied by the message display pane: 6 7 .. image:: console-messages-fx79.png 8 :alt: Screenshot of the web console, highlighting the messages area 9 :class: center 10 11 Each message is displayed as a separate row: 12 13 .. image:: console-msg-annotated.png 14 :alt: Screenshot of a single console message, with its parts annotated 15 :class: center 16 17 .. |image1| image:: info-icon.png 18 :alt: An "i" inside a circle 19 20 .. |image2| image:: warning-icon.png 21 :alt: A "!" inside a yellow triangle 22 23 .. |image3| image:: error-icon.png 24 :alt: A "!" inside a solid red circle 25 26 .. |image4| image:: blocked-icon.png 27 :alt: A red circle with a slash across it 28 29 30 .. list-table:: 31 :widths: 25 75 32 :header-rows: 0 33 34 * - **Time** 35 - The time the message was recorded. This is not shown by default: you can opt to see timestamps by selecting **Show Timestamps** in the console settings menu (gear icon in the console toolbar). 36 37 * - **Icon** 38 - Not all console messages contain icons. The following icons may be used: 39 40 - |image1| Informational message 41 - |image2| Warning 42 - |image3| Error 43 - |image4| Blocked; for network messages 44 45 In addition, a disclosure triangle indicates that further information is available; clicking it displays or collapses that information. 46 47 * - **Message** 48 - The message itself. 49 50 * - **Number of occurrences** 51 - If a line that generates a warning or error is executed more than once, it is only logged once and this counter appears to indicate how many times it was encountered. 52 53 * - **Filename and line number** 54 - For JavaScript, CSS and console API messages, the message can be traced to a specific line of code. The console then provides a link to the filename and line number that generated the message. 55 56 57 By default, the console is cleared each time you navigate to a new page or reload the current page. To override this behavior, enable **Persist Logs** in the console settings menu (gear icon). 58 59 The context menu options listed below are available on all message categories. Additional context menu options are described in the subsection for the message category they apply to. 60 61 62 - **Copy Message** copies the selected message to the clipboard. 63 - **Select All** selects all messages available in the message display pane. 64 - **Export Visible Messages To** 65 66 - **Clipboard** copies all messages available in the display pane to the clipboard. 67 - **File** opens a file dialog box so you can save an export of all messages available in the display pane. 68 69 70 Message categories 71 ****************** 72 73 .. _web_console_console_messages: 74 75 Network 76 ------- 77 78 .. note:: 79 Network log messages are not shown by default. Use the :ref:`filtering <web_console_ui_tour_filtering_by_category>` feature to show them. 80 81 82 Network requests are logged with a line that looks like this: 83 84 .. image:: response-msg-annotated.png 85 :alt: Screenshot of a network response message, with its parts annotated 86 :class: center 87 88 89 .. list-table:: 90 :widths: 25 75 91 :header-rows: 0 92 93 * - **Time** 94 - The time the message was recorded. 95 96 * - **Method** 97 - The specific HTTP request method. 98 99 If the request was made as an `XMLHttpRequest <https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest>`_, there's an additional "XHR" tag indicating this. 100 101 If more information is available, a disclosure triangle lets you display it, in an embedded panel that is identical to the :doc:`Network Monitor request details <../../network_monitor/request_details/index>`. 102 103 * - **URI** 104 - The target URI. 105 106 * - **Summary** 107 - The HTTP version, response code, and time taken to complete. Clicking the response code takes you to the reference page for that code. 108 109 .. raw:: html 110 111 <iframe width="560" height="315" src="https://www.youtube.com/embed/cFlcWzJ9j4I" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> 112 <br/> 113 <br/> 114 115 The context menu for network messages includes a few extra items in addition the globally-available ones: 116 117 .. image:: response-msg-context-menu.png 118 :alt: Screenshot showing the context menu for network response messages 119 :class: border 120 121 122 Copy link location 123 Acts as you would expect, copying the URL into the clipboard 124 Open in Network Panel 125 Switches context to the Network tab, selects the request and shows you the details 126 Resend Request 127 Sends the network request again. 128 Open URL in New Tab 129 Opens the URL in a new browser tab. If the resource is an image, the image will be opened in a new tab. If the resource is a stylesheet, you will see the CSS rules, etc. 130 131 132 JS 133 -- 134 135 JavaScript errors contain a "Learn more" linkthat takes you to the `JavaScript error reference <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors>`_ containing additional advice for fixing issues. 136 137 138 Source maps 139 ~~~~~~~~~~~ 140 141 The Web Console understands `source maps <https://blog.teamtreehouse.com/introduction-source-maps>`_. This means that if your JavaScript sources are compressed, you can supply a source map for them. Then any messages or errors your source generates will show up in the Web Console with a link back to the original source, not the compressed version. 142 143 Async stack frames 144 ~~~~~~~~~~~~~~~~~~ 145 146 Stack traces show stack frames for `async functions <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function>`_ separately from those for synchronous functions. When you run code containing an async function, its traces (`console.trace <https://developer.mozilla.org/en-US/docs/Web/API/console/trace>`_ or `thrown error <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error>`_) are shown with an *Async:* prefix. 147 148 .. image:: async-trace.png 149 :alt: Console log showing a trace containing async code 150 :class: center 151 152 153 CSS 154 --- 155 156 .. note:: 157 CSS warnings and reflow messages are not shown by default, for performance reasons (see `bug 1452143 <https://bugzilla.mozilla.org/show_bug.cgi?id=1452143>`_. Use the :ref:`filtering <web_console_ui_tour_filtering_by_category>` feature to show them. 158 159 160 Some CSS messages contain a disclosure triangle at the left of the message. Click it to view more information about the error, as well as which DOM nodes are affected by the error. 161 162 .. image:: css_warnings.png 163 :class: center 164 165 166 Security 167 -------- 168 169 The security messages shown in the Web Console help developers find potential or actual vulnerabilities in their sites. Additionally, many of these messages help educate developers because they end with a “Learn More” link that takes you to a page with background information and advice for mitigating the issue. 170 171 The complete list of security messages is as follows: 172 173 .. list-table:: 174 :widths: 50 50 175 :header-rows: 1 176 177 * - Messages 178 - Details 179 180 * - Blocked loading mixed active content 181 - The page contained mixed active content: that is, the main page was served over HTTPS, but asked the browser to load "active content", such as scripts, over HTTP. The browser blocked this active content. See `Mixed Content <https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content>`_ for more details. 182 183 * - Blocked loading mixed display content 184 - The page contained mixed display content: that is, the main page was served over HTTPS, but asked the browser to load "display content", such as images, over HTTP. The browser blocked this display content. See `Mixed Content <https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content>`_ for more details. 185 186 * - Loading mixed (insecure) active content on a secure page 187 - The page contained mixed active content: that is, the main page was served over HTTPS, but asked the browser to load "active content", such as scripts, over HTTP. The browser loaded this active content. See `Mixed Content <https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content>`_ for more details. 188 189 * - Loading mixed (insecure) display content on a secure page 190 - The page contained mixed display content: that is, the main page was served over HTTPS, but asked the browser to load "display content", such as images, over HTTP. The browser loaded this display content. `Mixed Content <https://developer.mozilla.org/en-US/docs/Web/Security/Mixed_content>`_ for more details. 191 192 * - This site specified both an X-Content-Security-Policy/Report-Only header and a Content-Security-Policy/Report-Only header. The X-Content-Security-Policy/Report-Only header(s) will be ignored. 193 - See `Content Security Policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP>`_ for more details. 194 195 * - The X-Content-Security-Policy and X-Content-Security-Report-Only headers will be deprecated in the future. Please use the Content-Security-Policy and Content-Security-Report-Only headers with CSP spec compliant syntax instead. 196 - See `Content Security Policy <https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP>`_ for more details. 197 198 * - Password fields present on an insecure (http://) page. This is a security risk that allows user login credentials to be stolen. 199 - Pages containing login forms must be served over HTTPS, not HTTP. 200 201 * - Password fields present in a form with an insecure (http://) form action. This is a security risk that allows user login credentials to be stolen. 202 - Forms containing password fields must submit them over HTTPS, not HTTP. 203 204 * - Password fields present on an insecure (http://) iframe. This is a security risk that allows user login credentials to be stolen. 205 - iframes containing login forms must be served over HTTPS, not HTTP. 206 207 * - The site specified an invalid Strict-Transport-Security header. 208 - See `HTTP Strict Transport Security <https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Strict-Transport-Security>`_ for more details. 209 210 * - This site makes use of a SHA-1 Certificate; it's recommended you use certificates with signature algorithms that use hash functions stronger than SHA-1. 211 212 - The site uses a certificate whose signature uses the SHA-1 hash algorithm. 213 214 SHA-1 is still widely used in certificates, but it is starting to show its age. Web sites and Certification Authorities are encouraged to switch to stronger hash algorithms in future. See the `Weak Signature Algorithm <https://developer.mozilla.org/en-US/docs/Web/Security/Weak_Signature_Algorithm>`_ article for more details. 215 216 Note that the SHA-1 certificate may not be your site's own certificate, but may be the certificate belonging to a Certification Authority that was used to sign your site's certificate. 217 218 219 `Bug 863874 <https://bugzilla.mozilla.org/show_bug.cgi?id=863874>`_ is the meta-bug for logging relevant security messages to the Web Console. If you have more ideas for useful features like the ones discussed here, or are interested in contributing, check out the metabug and its dependencies. 220 221 222 Logging 223 ------- 224 225 .. note:: 226 Messages logged from `Shared Workers <https://developer.mozilla.org/en-US/docs/Web/API/SharedWorker>`_, `Service Workers <https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API>`_, add-ons, and **Chrome Workers** are not shown by default. Use the :ref:`filtering <web_console_ui_tour_filtering_by_category>` feature to show them. 227 228 229 The Logging category includes messages logged using the `Console API <https://developer.mozilla.org/en-US/docs/Web/API/console>`_. 230 231 The Web console supports the following `Console API <https://developer.mozilla.org/en-US/docs/Web/API/console>`_ messages: 232 233 234 - `assert() <https://developer.mozilla.org/en-US/docs/Web/API/console/assert>`_ 235 - `clear() <https://developer.mozilla.org/en-US/docs/Web/API/console/clear>`_ 236 - `count() <https://developer.mozilla.org/en-US/docs/Web/API/console/count>`_ 237 - `dir() <https://developer.mozilla.org/en-US/docs/Web/API/console/dir>`_ 238 - `dirxml() <https://developer.mozilla.org/en-US/docs/Web/API/console/dirxml>`_ 239 - `error() <https://developer.mozilla.org/en-US/docs/Web/API/console/error>`_ 240 - ``exception()`` 241 - `group() <https://developer.mozilla.org/en-US/docs/Web/API/console/group>`_ 242 - `groupEnd() <https://developer.mozilla.org/en-US/docs/Web/API/console/groupEnd>`_ 243 - ``info()`` 244 - `log() <https://developer.mozilla.org/en-US/docs/Web/API/console/log>`_ 245 - `table() <https://developer.mozilla.org/en-US/docs/Web/API/console/table>`_ 246 - `time() <https://developer.mozilla.org/en-US/docs/Web/API/console/time>`_ 247 - `timeEnd() <https://developer.mozilla.org/en-US/docs/Web/API/console/timeEnd>`_ 248 - `trace() <https://developer.mozilla.org/en-US/docs/Web/API/console/trace>`_ 249 - `warn() <https://developer.mozilla.org/en-US/docs/Web/API/console/warn>`_ 250 251 252 The console prints a stack trace for all error messages, like this: 253 254 .. code-block:: javascript 255 256 function foo() { 257 console.error("it explodes"); 258 } 259 260 function bar() { 261 foo(); 262 } 263 264 function doStuff() { 265 bar(); 266 } 267 268 doStuff(); 269 270 .. image:: error-stack.png 271 :class: center 272 273 274 .. _web_console_server: 275 276 Server 277 ------ 278 279 With the `Chrome Logger extension <https://addons.mozilla.org/en-US/firefox/addon/chromelogger/>`_, Web Console can display messages sent from the server. This enables you to use the Web Console to debug server-side code. 280 281 282 It uses the `Chrome Logger <https://craig.is/writing/chrome-logger>`_ protocol. Briefly, the way it works is: 283 284 285 - Your server-side code — Python, PHP, Node.js, etc. — includes a library that provides a console API. 286 - Your server-side code uses this API to log messages. 287 - The server-side library creates JSON objects from the messages and encodes them for transmission. 288 - The messages are transmitted to the client as a response header named ``X-ChromeLogger-Data``. 289 - The Web Console decodes these headers and displays them. 290 291 292 To find a suitable library for your server code, see the `Chrome Logger documentation <https://craig.is/writing/chrome-logger>`_. 293 294 295 .. _web_console_console_messages_interpreter_io: 296 297 Interpreter input/output 298 ------------------------ 299 300 Commands sent to the browser using the :doc:`Web Console's JavaScript interpreter <../the_command_line_interpreter/index>`, and the corresponding responses, are logged in the console messages. 301 302 For responses that contain objects or variables, the following context menu options are available: 303 304 305 Reveal in Inspector 306 Shows the selected DOM node in the Inspector pane. 307 Store as Global Variable 308 Creates a global variable (with a name like ``temp0``, ``temp1``, etc.) whose value is the selected object. The name of the variable appears as an input to the interpreter, and its value appears as a response. 309 Copy Object 310 Copies the selected object to the clipboard. 311 312 313 314 Filtering and searching 315 *********************** 316 317 .. _web_console_ui_tour_filtering_by_category: 318 319 Filtering by category 320 --------------------- 321 322 You can use the toolbar along the top to constrain the results displayed. 323 324 .. image:: console-toolbar.png 325 :alt: Screenshot showing the web console, with the toolbar highlighted 326 :class: center 327 328 To see only messages of particular categories, click the button labeled with that category (**Errors**, **CSS**, and so on). 329 330 For Errors and Warnings, when you turn off display of the category, a number appears next to the button text to indicate how many messages of that type are available. For example, "Warnings (25)". 331 332 Network requests with response codes in the 400-499 (client error) or 500-599 (server error) ranges are considered errors. Their display is controlled by the **Errors** button, not the **Requests** button. 333 334 335 .. _web_console_ui_tour_filtering_by_text: 336 337 Filtering by text 338 ----------------- 339 340 To see only messages that contain a specific string, type in the text box labeled "Filter output". For example, if you entered the string img into the text box, you would have a list something like this: 341 342 .. image:: console_clear_filter.png 343 :class: border 344 345 346 A small "x" icon appears at the right end of the text box when you have entered a string on which to filter the output. Click the "x" icon to clear the filter and show the entire list again. 347 348 You can negate a text search by prefixing it with the ``-`` character. For example, ``-img`` shows only items that *do not* contain the string ``img``. 349 350 351 .. _web_console_ui_tour_filtering_by_regular_expressions: 352 353 Filtering with Regular Expressions 354 ---------------------------------- 355 356 You can also use a valid regular expression to filter the console output. For example, the following video shows the results when filtering on two simple regular expressions: ``/(cool|rad)/`` and ``/(cool)/``. 357 358 .. raw:: html 359 360 <iframe width="560" height="315" src="https://www.youtube.com/embed/E6bGOe2fvW0" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> 361 <br/> 362 <br/> 363 364 You can negate a regular expression search by prefixing it with the ``-`` character. For example, ``-/(cool|rad)/`` shows only items that *do not* match the expression ``/(cool|rad)/``. 365 366 Clearing the log 367 ---------------- 368 369 Finally, you can use the trashcan icon on the left to clear the contents of the console. When you clear the console, the console cache is also cleared. This prevents errors that have already been logged from reappearing when you reopen the console.