2022-10-13 09:01:31 +00:00
<!doctype html>
< html lang = "en" dir = "ltr" class = "docs-wrapper docs-doc-page docs-version-current plugin-docs plugin-id-default docs-doc-id-guides/debugging" >
< head >
< meta charset = "UTF-8" >
2022-12-16 13:59:40 +00:00
< meta name = "generator" content = "Docusaurus v2.2.0" >
2023-01-11 15:09:01 +00:00
< title data-rh = "true" > Debugging | Puppeteer< / title > < meta data-rh = "true" name = "viewport" content = "width=device-width,initial-scale=1" > < meta data-rh = "true" name = "twitter:card" content = "summary_large_image" > < meta data-rh = "true" property = "og:url" content = "https://pptr.dev/next/guides/debugging" > < meta data-rh = "true" name = "docsearch:language" content = "en" > < meta data-rh = "true" name = "docsearch:counter" content = "3" > < meta data-rh = "true" property = "og:title" content = "Debugging | Puppeteer" > < meta data-rh = "true" name = "description" content = "Debugging with Puppeteer can be an arduous task. There is no single method for" > < meta data-rh = "true" property = "og:description" content = "Debugging with Puppeteer can be an arduous task. There is no single method for" > < link data-rh = "true" rel = "icon" href = "/img/favicon.ico" > < link data-rh = "true" rel = "canonical" href = "https://pptr.dev/next/guides/debugging" > < link data-rh = "true" rel = "alternate" href = "https://pptr.dev/next/guides/debugging" hreflang = "en" > < link data-rh = "true" rel = "alternate" href = "https://pptr.dev/next/guides/debugging" hreflang = "x-default" > < link data-rh = "true" rel = "preconnect" href = "https://DVKY664LG7-dsn.algolia.net" crossorigin = "anonymous" > < link rel = "search" type = "application/opensearchdescription+xml" title = "Puppeteer" href = "/opensearch.xml" >
< script src = "/fix-location.js" > < / script > < link rel = "stylesheet" href = "/assets/css/styles.79ad2638.css" >
2023-02-15 10:38:59 +00:00
< link rel = "preload" href = "/assets/js/runtime~main.410700f8.js" as = "script" >
2023-02-14 21:42:45 +00:00
< link rel = "preload" href = "/assets/js/main.583110df.js" as = "script" >
2022-10-13 09:01:31 +00:00
< / head >
< body class = "navigation-with-keyboard" >
< script > ! function ( ) { function t ( t ) { document . documentElement . setAttribute ( "data-theme" , t ) } var e = function ( ) { var t = null ; try { t = localStorage . getItem ( "theme" ) } catch ( t ) { } return t } ( ) ; t ( null !== e ? e : "light" ) } ( ) < / script > < div id = "__docusaurus" >
2023-02-13 10:26:19 +00:00
< div role = "region" aria-label = "Skip to main content" > < a class = "skipToContent_fXgn" href = "#docusaurus_skipToContent_fallback" > Skip to main content< / a > < / div > < nav class = "navbar navbar--fixed-top" > < div class = "navbar__inner" > < div class = "navbar__items" > < button aria-label = "Toggle navigation bar" aria-expanded = "false" class = "navbar__toggle clean-btn" type = "button" > < svg width = "30" height = "30" viewBox = "0 0 30 30" aria-hidden = "true" > < path stroke = "currentColor" stroke-linecap = "round" stroke-miterlimit = "10" stroke-width = "2" d = "M4 7h22M4 15h22M4 23h22" > < / path > < / svg > < / button > < a class = "navbar__brand" href = "/" > < div class = "navbar__logo" > < img src = "https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png" alt = "Puppeteer Logo" class = "themedImage_ToTc themedImage--light_HNdA" > < img src = "https://user-images.githubusercontent.com/10379601/29446482-04f7036a-841f-11e7-9872-91d1fc2ea683.png" alt = "Puppeteer Logo" class = "themedImage_ToTc themedImage--dark_i4oU" > < / div > < b class = "navbar__title text--truncate" > Puppeteer< / b > < / a > < a aria-current = "page" class = "navbar__item navbar__link navbar__link--active" href = "/next/" > Docs< / a > < a class = "navbar__item navbar__link" href = "/next/api/puppeteer.puppeteernode" > API< / a > < / div > < div class = "navbar__items navbar__items--right" > < div class = "navbar__item dropdown dropdown--hoverable dropdown--right" > < a class = "navbar__link" aria-haspopup = "true" aria-expanded = "false" role = "button" href = "/next/" > Next< / a > < ul class = "dropdown__menu" > < li > < a aria-current = "page" class = "dropdown__link dropdown__link--active" href = "/next/guides/debugging" > Next< / a > < / li > < li > < a class = "dropdown__link" href = "/guides/debugging" > 19.7.0< / a > < / li > < li > < hr class = "dropdown-separator" > < / li > < li class = "dropdown-archived-versions" > < b > Archived versions< / b > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.6.3/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.6.3< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "iconExternalLink_nPIU" > < path fill = "currentColor" d = "M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" > < / path > < / svg > < / a > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.6.2/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.6.2< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "iconExternalLink_nPIU" > < path fill = "currentColor" d = "M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" > < / path > < / svg > < / a > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.6.1/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.6.1< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "iconExternalLink_nPIU" > < path fill = "currentColor" d = "M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" > < / path > < / svg > < / a > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.6.0/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.6.0< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "iconExternalLink_nPIU" > < path fill = "currentColor" d = "M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" > < / path > < / svg > < / a > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.5.2/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.5.2< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "iconExternalLink_nPIU" > < path fill = "currentColor" d = "M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z" > < / path > < / svg > < / a > < / li > < li > < a href = "https://github.com/puppeteer/puppeteer/blob/v19.5.1/docs/api/index.md" target = "_blank" rel = "noopener noreferrer" class = "dropdown__link" > 19.5.1< svg width = "12" height = "12" aria-hidden = "true" viewBox = "0 0 24 24" class = "icon
2022-10-19 08:43:26 +00:00
debugging all possible issues since Puppeteer touches many distinct components
of a browser such as network requests and Web APIs. On a high note, Puppeteer
provides < em > several< / em > methods for debugging which hopefully does cover all possible
issues.< / p > < h2 class = "anchor anchorWithStickyNavbar_LWe7" id = "background" > Background< a class = "hash-link" href = "#background" title = "Direct link to heading" > < / a > < / h2 > < p > In general, there are two possible sources of an issue: Code running on Node.js
(which we call < em > server code< / em > ), and
2022-10-24 07:23:07 +00:00
< a href = "/next/guides/[`Page.evaluate()`](../api/puppeteer.page.evaluate)" > code running in the browser< / a >
2022-10-19 08:43:26 +00:00
(which we call < em > client code< / em > ). There is also a third possible source being the
browser itself (which we call < em > internal code< / em > ), but if you suspect this is the
source < strong > after attempting the methods below< / strong > , we suggest
< a href = "https://github.com/puppeteer/puppeteer/issues" target = "_blank" rel = "noopener noreferrer" > searching existing issues< / a >
before
< a href = "https://github.com/puppeteer/puppeteer/issues/new/choose" target = "_blank" rel = "noopener noreferrer" > filing an issue< / a > .< / p > < h2 class = "anchor anchorWithStickyNavbar_LWe7" id = "debugging-methods-for-all-situations" > Debugging methods for all situations< a class = "hash-link" href = "#debugging-methods-for-all-situations" title = "Direct link to heading" > < / a > < / h2 > < p > These methods can be used to debug any situation. These should be used as a
2022-10-24 07:23:07 +00:00
quick sanity check before diving into more complex methods.< / p > < h3 class = "anchor anchorWithStickyNavbar_LWe7" id = "turn-off-headless" > Turn off < a href = "/next/api/puppeteer.browserlaunchargumentoptions.headless" > < code > headless< / code > < / a > < a class = "hash-link" href = "#turn-off-headless" title = "Direct link to heading" > < / a > < / h3 > < p > Sometimes it' s useful to see what the browser is displaying. Instead of
2022-10-19 08:43:26 +00:00
launching in
2022-10-28 07:23:25 +00:00
< a href = "/next/api/puppeteer.browserlaunchargumentoptions.headless" > < code > headless< / code > < / a > mode,
launch a full version of the browser with
< a href = "/next/api/puppeteer.browserlaunchargumentoptions.headless" > < code > headless< / code > < / a > set to
< code > false< / code > :< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token keyword" style = "color:#00009f" > const< / span > < span class = "token plain" > browser < / span > < span class = "token operator" style = "color:#393A34" > =< / span > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > puppeteer< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > launch< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > {< / span > < span class = "token plain" > headless< / span > < span class = "token operator" style = "color:#393A34" > :< / span > < span class = "token plain" > < / span > < span class = "token boolean" style = "color:#36acaa" > false< / span > < span class = "token punctuation" style = "color:#393A34" > }< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < h3 class = "anchor anchorWithStickyNavbar_LWe7" id = "puppeteer-slow-mo" > Puppeteer " slow-mo" < a class = "hash-link" href = "#puppeteer-slow-mo" title = "Direct link to heading" > < / a > < / h3 > < p > The < a href = "/next/api/puppeteer.browserconnectoptions.slowmo" > < code > slowMo< / code > < / a > option slows down
Puppeteer operations by a specified amount of milliseconds. It' s another way to
help see what' s going on.< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token keyword" style = "color:#00009f" > const< / span > < span class = "token plain" > browser < / span > < span class = "token operator" style = "color:#393A34" > =< / span > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > puppeteer< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > launch< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > {< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > headless< / span > < span class = "token operator" style = "color:#393A34" > :< / span > < span class = "token plain" > < / span > < span class = "token boolean" style = "color:#36acaa" > false< / span > < span class = "token punctuation" style = "color:#393A34" > ,< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > slowMo< / span > < span class = "token operator" style = "color:#393A34" > :< / span > < span class = "token plain" > < / span > < span class = "token number" style = "color:#36acaa" > 250< / span > < span class = "token punctuation" style = "color:#393A34" > ,< / span > < span class = "token plain" > < / span > < span class = "token comment" style = "color:#999988;font-style:italic" > // slow down by 250ms< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > < / span > < span class = "token punctuation" style = "color:#393A34" > }< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < h2 class = "anchor anchorWithStickyNavbar_LWe7" id = "debugging-methods-for-client-code" > Debugging methods for client code< a class = "hash-link" href = "#debugging-methods-for-client-code" title = "Direct link to heading" > < / a > < / h2 > < h3 class = "anchor anchorWithStickyNavbar_LWe7" id = "capture-console-output" > Capture < code > console.*< / code > output< a class = "hash-link" href = "#capture-console-output" title = "Direct link to heading" > < / a > < / h3 > < p > Since client code runs in the browser, doing < code > console.*< / code > in client code will not
directly log to Node.js. However, you can < a href = "/next/api/puppeteer.page.on" > listen< / a > for
the < a href = "/next/api/puppeteer.pageeventobject.console" > < code > console< / code > < / a > event which returns a
payload with the logged text.< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > page< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > on< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token string" style = "color:#e3116c" > ' console' < / span > < span class = "token punctuation" style = "color:#393A34" > ,< / span > < span class = "token plain" > msg < / span > < span class = "token operator" style = "color:#393A34" > => < / span > < span class = "token plain" > < / span > < span class = "token builtin" > console< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > log< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token string" style = "color:#e3116c" > ' PAGE LOG:' < / span > < span class = "token punctuation" style = "color:#393A34" > ,< / span > < span class = "token plain" > msg< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > text< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" style = "display:inline-block" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > page< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > evaluate< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token plain" > < / span > < span class = "token operator" style = "color:#393A34" > => < / span > < span class = "token plain" > < / span > < span class = "token builtin" > console< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > log< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token template-string template-punctuation string" style = "color:#e3116c" > `< / span > < span class = "token template-string string" style = "color:#e3116c" > url is < / span > < span class = "token template-string interpolation interpolation-punctuation punctuation" style = "color:#393A34" > ${< / span > < span class = "token template-string interpolation" > location< / span > < span class = "token template-string interpolation punctuation" style = "color:#393A34" > .< / span > < span class = "token template-string interpolation" > href< / span > < span class = "token template-string interpolation interpolation-punctuation punctuation" style = "color:#393A34" > }< / span > < span class = "token template-string template-punctuation string" style = "color:#e3116c" > `< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5
< code > true< / code > when launching Puppeteer:< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token keyword" style = "color:#00009f" > const< / span > < span class = "token plain" > browser < / span > < span class = "token operator" style = "color:#393A34" > =< / span > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > puppeteer< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > launch< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > {< / span > < span class = "token plain" > devtools< / span > < span class = "token operator" style = "color:#393A34" > :< / span > < span class = "token plain" > < / span > < span class = "token boolean" style = "color:#36acaa" > true< / span > < span class = "token punctuation" style = "color:#393A34" > }< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < / li > < li > < p > Add < code > debugger< / code > inside any client code you want debugged. For example,< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > page< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > evaluate< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token plain" > < / span > < span class = "token operator" style = "color:#393A34" > => < / span > < span class = "token plain" > < / span > < span class = "token punctuation" style = "color:#393A34" > {< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > debugger< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > < / span > < span class = "token punctuation" style = "color:#393A34" > }< / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < p > The Browser will now stop in the location the < code > debugger
2022-10-19 08:43:26 +00:00
debug mode.< / p > < / li > < / ol > < h2 class = "anchor anchorWithStickyNavbar_LWe7" id = "debugging-methods-for-server-code" > Debugging methods for server code< a class = "hash-link" href = "#debugging-methods-for-server-code" title = "Direct link to heading" > < / a > < / h2 > < h3 class = "anchor anchorWithStickyNavbar_LWe7" id = "use-the-debugger-in-nodejs-chromechromium-only" > Use the debugger in Node.js (Chrome/Chromium-only)< a class = "hash-link" href = "#use-the-debugger-in-nodejs-chromechromium-only" title = "Direct link to heading" > < / a > < / h3 > < p > Since server code intermingles with client code, this method of debugging is
closely tied with the browser. For example, you can step over
< code > await page.click()< / code > in the server script and see the click happen in the
browser.< / p > < p > Note that you won' t be able to run < code > await page.click()< / code > in DevTools console due
to this
< a href = "https://bugs.chromium.org/p/chromium/issues/detail?id=833928" target = "_blank" rel = "noopener noreferrer" > Chromium bug< / a > , so
2022-10-28 07:23:25 +00:00
if you want to try something out, you have to add it to your test file.< / p > < ol > < li > < p > Set < a href = "/next/api/puppeteer.browserlaunchargumentoptions.headless" > < code > headless< / code > < / a > to
< code > false< / code > .< / p > < / li > < li > < p > Add < code > debugger< / code > to any server code you want debugged. For example,< / p > < div class = "language-ts codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-ts codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token keyword" style = "color:#00009f" > debugger< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < span class = "token plain" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > < / span > < span class = "token keyword" style = "color:#00009f" > await< / span > < span class = "token plain" > page< / span > < span class = "token punctuation" style = "color:#393A34" > .< / span > < span class = "token function" style = "color:#d73a49" > click< / span > < span class = "token punctuation" style = "color:#393A34" > (< / span > < span class = "token string" style = "color:#e3116c" > ' a[target=_blank]' < / span > < span class = "token punctuation" style = "color:#393A34" > )< / span > < span class = "token punctuation" style = "color:#393A34" > ;< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < / li > < li > < p > Run your server code with < code > --inspect-brk< / code > . For example,< / p > < div class = "language-sh codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-sh codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > node --inspect-brk path/to/script.js< / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < / li > < li > < p > In the opened Chrome/Chromium browser, open < code > chrome://inspect/#devices< / code > and
2022-10-19 08:43:26 +00:00
click < code > inspect< / code > .< / p > < / li > < li > < p > In the newly opened test browser, press < code > F8< / code > to resume test execution.< / p > < / li > < li > < p > Now your < code > debugger< / code > statement will be hit and you can debug in the test
2022-10-28 09:20:45 +00:00
browser.< / p > < / li > < / ol > < h3 class = "anchor anchorWithStickyNavbar_LWe7" id = "log-devtools-protocol-traffic" > Log DevTools protocol traffic< a class = "hash-link" href = "#log-devtools-protocol-traffic" title = "Direct link to heading" > < / a > < / h3 > < p > If all else fails, it' s possible there may be an issue between Puppeteer and the
2022-10-19 08:43:26 +00:00
DevTools protocol. You can debug this by setting the < code > DEBUG< / code > environment
variable before running your script. This will log internal traffic via
2023-01-26 06:48:58 +00:00
< a href = "https://github.com/visionmedia/debug" target = "_blank" rel = "noopener noreferrer" > < code > debug< / code > < / a > under the < code > puppeteer< / code > namespace.< / p > < div class = "language-sh codeBlockContainer_Ckt0 theme-code-block" style = "--prism-color:#393A34;--prism-background-color:#f6f8fa" > < div class = "codeBlockContent_biex" > < pre tabindex = "0" class = "prism-code language-sh codeBlock_bY9V thin-scrollbar" > < code class = "codeBlockLines_e6Vv" > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > # Basic verbose logging< / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > env DEBUG=" puppeteer:*" node script.js< / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" style = "display:inline-block" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > # Prevent truncating of long messages< / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > env DEBUG=" puppeteer:*" env DEBUG_MAX_STRING_LENGTH=null node script.js< / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" style = "display:inline-block" > < / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > # Protocol traffic can be rather noisy. This example filters out all Network domain messages< / span > < br > < / span > < span class = "token-line" style = "color:#393A34" > < span class = "token plain" > env DEBUG=" puppeteer:*" env DEBUG_COLORS=true node script.js 2> & 1 | grep -v ' " Network' < / span > < br > < / span > < / code > < / pre > < div class = "buttonGroup__atx" > < button type = "button" aria-label = "Copy code to clipboard" title = "Copy" class = "clean-btn" > < span class = "copyButtonIcons_eSgA" aria-hidden = "true" > < svg class = "copyButtonIcon_y97N" viewBox = "0 0 24 24" > < path d = "M19,21H8V7H19M19,5H8A2,2 0 0,0 6,7V21A2,2 0 0,0 8,23H19A2,2 0 0,0 21,21V7A2,2 0 0,0 19,5M16,1H4A2,2 0 0,0 2,3V17H4V3H16V1Z" > < / path > < / svg > < svg class = "copyButtonSuccessIcon_LjdS" viewBox = "0 0 24 24" > < path d = "M21,7L9,19L3.5,13.5L4.91,12.09L9,16.17L19.59,5.59L21,7Z" > < / path > < / svg > < / span > < / button > < / div > < / div > < / div > < / div > < / article > < nav class = "pagination-nav docusaurus-mt-lg" aria-label = "Docs pages navigation" > < a class = "pagination-nav__link pagination-nav__link--prev" href = "/next/guides/chrome-extensions" > < div class = "pagination-nav__sublabel" > Previous< / div > < div class = "pagination-nav__label" > Chrome Extensions< / div > < / a > < a class = "pagination-nav__link pagination-nav__link--next" href = "/next/chromium-support" > < div class = "pagination-nav__sublabel" > Next< / div > < div class = "pagination-nav__label" > Chromium Support< / div > < / a > < / nav > < / div > < / div > < div class = "col col--3" > < div class = "tableOfContents_bqdL thin-scrollbar theme-doc-toc-desktop" > < ul class = "table-of-contents table-of-contents__left-border" > < li > < a href = "#background" class = "table-of-contents__link toc-highlight" > Background< / a > < / li > < li > < a href = "#debugging-methods-for-all-situations" class = "table-of-contents__link toc-highlight" > Debugging methods for all situations< / a > < ul > < li > < a href = "#turn-off-headless" class = "table-of-contents__link toc-highlight" > Turn off < code > headless< / code > < / a > < / li > < li > < a href = "#puppeteer-slow-mo" class = "table-of-contents__link toc-highlight" > Puppeteer " slow-mo" < / a > < / li > < / ul > < / li > < li > < a href = "#debugging-methods-for-client-code" class = "table-of-contents__link toc-highlight" > Debugging methods for client code< / a > < ul > < li > < a href = "#capture-console-output" class = "table-of-contents__link toc-highlight" > Capture < code > console.*< / code > output< / a > < / li > < li > < a href = "#use-the-debugger-in-the-browser" class = "table-of-contents__link toc-highlight" > Use the debugger in the browser< / a > < / li > < / ul > < / li > < li > < a href = "#debugging-methods-for-server-code" class = "table-of-contents__link toc-highlight" > Debugging methods for server code< / a > < ul > < li > < a href = "#use-the-debugger-in-nodejs-chromechromium-only" class = "table-of-contents__link toc-highlight" > Use the debugger in Node.js (Chrome/Chromium-only)< / a > < / li > < li > < a href = "#log-devtools-protocol-traffic" cl
2023-02-15 10:38:59 +00:00
< script src = "/assets/js/runtime~main.410700f8.js" > < / script >
2023-02-14 21:42:45 +00:00
< script src = "/assets/js/main.583110df.js" > < / script >
2022-10-13 09:01:31 +00:00
< / body >
< / html >