# Troubleshooting

> What to do when the program cannot find Chrome, waits for ever, or leaves Chrome running.

The page: https://chromedp.dev/guides/troubleshooting/

## The program cannot find Chrome

chromedp looks for Chrome in the places that [Install](/start/install/#a-browser)
lists. If Chrome is somewhere else, give its path with `chromedp.ExecPath`. See
[Options of the browser](/concepts/contexts/#options-of-the-browser).

## An action waits for ever

A query waits until the page has the element, and it waits until the
context ends. Check the selector in the developer tools of Chrome, and set a
[timeout](/concepts/contexts/#timeouts) on the context, so that the program
stops with an error. To see what the program and the browser say to each
other, add `chromedp.WithDebugf(log.Printf)` to `chromedp.NewContext`.

## Chrome keeps running after the program

Call the cancel function of `chromedp.NewContext` with `defer`. A program
that ends with `log.Fatal` or `os.Exit` skips its deferred calls, so return
the error from a function, and call `log.Fatal` only in `main`, after the
deferred calls of that function have run.

## The page looks different in the program

Chrome runs headless by default, with a viewport of its own size. Set the
size with `chromedp.EmulateViewport`, or watch the browser with
`chromedp.WithVisibleWindow()` or the environment variable
`CHROMEDP_VISIBLEWINDOW=1`.

## A selector finds nothing in an iframe

A query looks in the document of the page, and an iframe has a document of
its own. Get the node of the iframe first, then query inside it with
`chromedp.FromNode`. See [Selectors and waiting](/concepts/selectors/).

## Ask a question

Ask in the
[discussions of chromedp](https://github.com/chromedp/chromedp/discussions).
Give a short program that shows the problem.
