CloakHQ/CloakBrowser · error · StealthEvaluationError

Isolated-world DOM evaluation failed for '{selector}'

Error message

Isolated-world DOM evaluation failed for '{selector}'

What it means

The isolated-world DOM evaluation itself failed (StealthStatus.EvaluationFailed, or an Ok status with a null snapshot), so the actionability check could not read element state. This is an infrastructure failure of the stealth CDP evaluation, not a verdict about the element. When it happens on the first attempt inside the window it may be recorded and retried until timeout.

Source

Thrown at dotnet/src/CloakBrowser/Human/Actionability.cs:168

        while (true)
        {
            double remainingMs = Math.Max(0, deadline - NowMs());
            if (remainingMs <= 0)
            {
                if (lastError != null)
                    throw lastError;
                throw new ActionabilityError(selector, "timeout", "timeout expired before first check");
            }

            try
            {
                var (status, snapshot) = await StealthDom.ActionableAsync(
                    stealth, selector).ConfigureAwait(false);
                if (status == StealthStatus.Unsupported)
                    throw new UnsupportedHumanizeSelectorError(selector);
                if (status == StealthStatus.EvaluationFailed)
                    throw new StealthEvaluationError(selector);
                if (status == StealthStatus.NotFound)
                    throw new ElementNotAttachedError(selector);
                if (status != StealthStatus.Ok || snapshot == null)
                    throw new StealthEvaluationError(selector);

                var value = snapshot.Value;
                if (checks.Contains("visible") && !value.Visible)
                    throw new ElementNotVisibleError(selector);
                if (checks.Contains("enabled") && !value.Enabled)
                    throw new ElementNotEnabledError(selector);
                if (checks.Contains("editable") && !value.Editable)
                    throw new ElementNotEditableError(selector);
                return;
            }
            catch (Exception error) when (error is ActionabilityError or StealthEvaluationError)
            {
                lastError = error;
                if (NowMs() >= deadline)

View on GitHub (pinned to d6bad5de26)

Solutions

  1. Retry the call — transient context destruction (navigation races) commonly resolves on retry.
  2. Re-acquire the IsolatedWorld after navigation or frame changes before humanizing.
  3. Ensure the page has finished navigating (wait for load/network idle) before checks.
  4. If persistent, update the library to match your Chromium version (protocol/evaluator drift).

Example fix

// before
await Actionability.EnsureActionableWorldAsync(page, selector, stealth);

// after
await page.WaitForLoadStateAsync(LifecycleEvent.NetworkIdle);
stealth = await page.AcquireIsolatedWorldAsync(); // refresh context after nav
await Actionability.EnsureActionableWorldAsync(page, selector, stealth);
Defensive patterns

Strategy: retry

Validate before calling

if (stealth is { IsClosed: false } w && await w.IsContextAliveAsync())
    await Actionability.EnsureActionableAsync(page, selector, w);

Try / catch

catch (StealthEvaluationError)
{
    await page.WaitForLoadStateAsync(LifecycleEvent.Load);
    stealth = await page.AcquireIsolatedWorldAsync(); // fresh context after nav
    await Actionability.EnsureActionableAsync(page, selector, stealth);
}

Prevention

When it happens

Trigger: Calling EnsureActionableAsync when StealthDom.ActionableAsync throws or returns a failed status — CDP Runtime.evaluate errors, the isolated world's execution context destroyed by navigation or frame swap, JS exception inside the injected evaluator, or snapshot deserialization returning null.

Common situations: Page navigation or SPA soft-navigation destroying the execution context mid-check; frame attachment races; the injected script crashing on unusual DOM shapes; DevTools protocol version mismatches after a Chromium upgrade; world handle invalidated by page reload.

Related errors


AI-assisted analysis of CloakHQ/CloakBrowser@d6bad5de26 (2026-08-28). Data as JSON: /api/errors/d9643fd5b1ac38e4. Report an issue: GitHub.