/** * Canonical legacy CSS-path walker. * * This is the Chromium-DevTools-derived `cssPath` algorithm that was the only * selector source autocapture used before the strategy engine existed. It still * matters in two situations: * * 1. The kill switch: when `ResolvedSelectorConfig.enabled === false`, the * engine routes here so a customer who flips the engine off mid-session * keeps emitting the same selectors their downstream zones and cohorts * were built against. * 2. The safety net: when the strategy chain or its internal walker throws * anything unexpected, the engine catches and falls back here. The * autocapture click handler must always produce *some* selector — a * runtime exception in selector generation is a worse outcome than a * slightly less stable selector. * * Until this file existed, the algorithm was duplicated in two places kept * "in sync by comment": * * - `packages/plugin-autocapture-browser/src/libs/element-path.ts` * - `javascript/packages/session-replay-ui/src/utils/element-path.ts` * * Both will eventually re-export from here so divergence becomes impossible. * * Behavior is byte-identical to those two copies — selectors emitted by this * function for a given element MUST match what the SDK has been emitting in * production. Do not "fix" the selector format without an explicit version * bump and a coordinated dashboard rollout. * * **Why this lives in the package, not as an optional consumer concern:** * * Every consumer that uses `engine.generate(el)` benefits from the kill * switch and the safety net automatically. Without this, each new consumer * (Chrome extension visual tagger, future tagging surfaces) has to * reimplement the same router and the same legacy walker. We learned that * the hard way — by writing the same `if (config.enabled && engine) ... * else cssPath()` block in two repositories with two copies of cssPath. * * Code is adapted from The Chromium Authors. * Source: https://github.com/ChromeDevTools/devtools-frontend/blob/main/front_end/panels/elements/DOMPath.ts#L14 * License: BSD-style license * * Copyright 2014 The Chromium Authors * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above * copyright notice, this list of conditions and the following * disclaimer in the documentation and/or other materials provided * with the distribution. * * Neither the name of Google Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import { ElementSelectorLogger } from './types'; /** * Produce a CSS selector string for `node` using the legacy positional walker. * * Returns the empty string for non-element nodes — same shape every existing * caller depends on. Never throws for well-formed Element inputs. * * @param node Element to identify. * @param optimized When `true`, short-circuits at the nearest unique-ish step * (id or `` / `` / ``). Default `false`, * which matches what autocapture has always passed. */ export declare const legacyCssPath: (node: Element, optimized?: boolean) => string; /** * Invoke `legacyCssPath` without letting a throw escape to the caller. * * Shared by `engine.generate` (kill switch + strategy-chain safety net) and * `generateSelector` (null-engine branch) so the swallow-warn-fallback * guarantee lives in one place. */ export declare function safeLegacyCssPath(el: Element, logger?: ElementSelectorLogger): string; //# sourceMappingURL=legacy-css-path.d.ts.map