Puppeteer: Navigating frame was detached
Last verified
Error: Navigating frame was detachedWhat it means
A navigation that Puppeteer was waiting on, from page.goto(), frame.goto() or page.waitForNavigation(), could not complete because the frame being navigated was removed. Puppeteer stops waiting and rejects with this message instead of a timeout.
On the main frame this typically means the page was closed or the renderer crashed during the navigation. Heavy pages in memory-limited containers, reusing a page that another part of the script closed, or a site that closes its own window during login all lead here. On iframes it means the iframe element was removed while it was loading.
What is not wrong: the URL. The same navigation in a fresh page usually succeeds, which is why this error tends to look intermittent and is often misread as a network problem.
What it looks like
async function gotoWithRetry(browser, url) {
let page = await browser.newPage();
try {
await page.goto(url, { waitUntil: 'domcontentloaded' });
} catch (err) {
if (!/frame was detached/i.test(err.message)) throw err;
if (!page.isClosed()) await page.close();
page = await browser.newPage();
await page.goto(url, { waitUntil: 'domcontentloaded' });
}
return page;
}Why it happens
- The browser or renderer crashed during navigation, often from memory pressure or a small /dev/shm.
- The page was closed by other code while goto was pending.
- An iframe being navigated was removed by its parent page.
- The site closed its own window (popup or OAuth flow) mid-navigation.
How to fix it
- Listen for page.on('error') (renderer crash) and browser.on('disconnected') to confirm a crash.
- In Docker, add --shm-size=1gb or args: ['--disable-dev-shm-usage'], and give the container more memory.
- Make sure no other task can close the page while it navigates; one page per task.
- On this error, open a new page and retry the navigation once.
How to stop it recurring
Give Chrome enough shared memory and RAM, limit concurrent pages, and recycle the browser periodically in long crawls. Keep page ownership clear so only one task navigates or closes a given page, and log crash and disconnect events so intermittent failures can be correlated with memory usage.
Official documentation: pptr.dev/api/puppeteer.page.goto. See all Puppeteer error messages.
Related errors
- Attempted to use detached FrameError: Attempted to use detached Frame 'A1B2C3D4E5F6A7B8C9D0E1F2A3B4C5D6'.
- Protocol error (Target.setDiscoverTargets): Target closedProtocolError: Protocol error (Target.setDiscoverTargets): Target closed
- Session closed. Most likely the page has been closed.Error: Protocol error (Runtime.callFunctionOn): Session closed. Most likely…
Definitions
- PuppeteerPuppeteer is Google's open-source Node.js library for controlling Chrome and Firefox. It drives Chrome over th
- Chrome DevTools Protocol (CDP)The Chrome DevTools Protocol (CDP) is the JSON-over-WebSocket interface Chrome exposes for inspecting and cont
- CSS SelectorA CSS selector is a pattern used to identify and target specific HTML elements on a web page, widely used in b
- Headless ChromeHeadless Chrome is Google Chrome running without a visible window. It renders pages and runs JavaScript like n
- IframeAn iframe (inline frame) is an HTML element that embeds a separate web page within a parent page, creating an
- Web ElementA web element is any individual component rendered on a web page — buttons, links, input fields, images, text
Quick answers
What does "Navigating frame was detached" mean in Puppeteer?
A navigation that Puppeteer was waiting on, from page.goto() , frame.goto() or page.waitForNavigation() , could not complete because the frame being navigated was removed. Puppeteer stops waiting and rejects with this message instead of a timeout. On the main frame this typically means the page was closed or the renderer crashed during the navigation.
How do I fix "Navigating frame was detached"?
1. Listen for page.on('error') (renderer crash) and browser.on('disconnected') to confirm a crash. 2. In Docker, add --shm-size=1gb or args: ['--disable-dev-shm-usage'], and give the container more memory. 3. Make sure no other task can close the page while it navigates; one page per task. 4. On this error, open a new page and retry the navigation once.
Run browser automation you can watch and take over
Autonoly runs each job in a real cloud Chromium browser driven by Playwright. Timeouts and detached elements still happen; the difference is that you can watch the run live, see the step that failed, and take control of the browser to finish it.
Also see Live browser control.