Skip to content

BrowserFrame.waitUntilComplete()

David Ortner edited this page Apr 10, 2025 · 5 revisions

Waits for all ongoing operations to complete. This includes operations such as loading resources and executing scripts.

Signature

async waitUntilComplete(): Promise<void>;

Returns

Promise<void>

Debugging

Set settings.debug.traceWaitUntilComplete to a time in ms to collect which tasks that are still open and their stack traces.

Read more about this under IOptionalBrowserSettings.

Timer Workarounds

This method may get stuck when using intervals or timers in a loop. Long running timers or fetch requests will slow it down, as it will wait for them to complete.

You can use the settings timer.maxTimeout, timer.maxIntervalTime, timer.maxIntervalIterations and timer.preventTimerLoops to prevent this from happening with timers.

Read more about this under IOptionalBrowserSettings.

Example

import { Browser } from 'happy-dom';

const browser = new Browser({
  settings: {
    timer: {
      maxTimeout: 200,
      maxIntervalTime: 10,
      maxIntervalIterations: 1,
      preventTimerLoops: true
    }
  }
});

const page = browser.newPage();

// Navigates page
await page.goto('https://github.com/capricorn86');

// Waits for the page to complete.
await page.mainFrame.waitUntilComplete();
Clone this wiki locally