{"record":{"id":"9f1b95548c7b3181","repo":"nolimits4web/swiper","slug":"text","errorCode":null,"errorMessage":"text","messagePattern":"text","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/shared/utils.ts","lineNumber":149,"sourceCode":"        : []),\n    );\n  }\n  return false;\n}\n\nexport function elementIsChildOf(el: Element, parent: Element): boolean {\n  let isChild = parent.contains(el);\n  if (!isChild && parent instanceof HTMLSlotElement) {\n    const children = [...parent.assignedElements()];\n    isChild = children.includes(el);\n    if (!isChild) isChild = elementIsChildOfSlot(el, parent);\n  }\n  return isChild;\n}\n\nexport function showWarning(text: string): void {\n  try {\n    console.warn(text);\n  } catch {\n    // err\n  }\n}\n\nexport function createElement<K extends keyof HTMLElementTagNameMap>(\n  tag: K,\n  classes?: string | string[],\n): HTMLElementTagNameMap[K];\nexport function createElement(tag: string, classes?: string | string[]): HTMLElement;\nexport function createElement(tag: string, classes: string | string[] = []): HTMLElement {\n  const el = document.createElement(tag);\n  el.classList.add(...(Array.isArray(classes) ? classes : classesToTokens(classes)));\n  return el;\n}\n\n// Viewport-relative on purpose: every caller either compares against viewport quantities\n// or adds window.scrollX/Y itself, so folding the scroll offset in here double-counts.","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/nolimits4web/swiper/blob/6138c2a6857d17fe097149dd3b975b2387d0b2dc/src/shared/utils.ts#L131-L167","documentation":"showWarning (src/shared/utils.ts:147-153) is Swiper's single warning funnel: every loop/grid advisory string is passed to console.warn(text) at line 149. The body is wrapped in try { ... } catch { /* err */ }, so if console is missing or console.warn throws, the warning is silently swallowed with no re-throw and no fallback channel. This makes the function an observability choke point: the other four warnings in this batch (and all Swiper runtime advisories) surface only if console.warn is actually callable in the host environment.","triggerScenarios":"console.warn(text) is invoked with any Swiper advisory (e.g. a loop warning). The catch block executes only when the host cannot warn: console is undefined (some SSR/node setups without a console polyfill), console.warn has been deleted or reassigned to a throwing stub, a sandboxed iframe restricts the console, or CSP/lockdown config makes console.warn throw. In a normal browser the call succeeds and the string is printed as a console warning.","commonSituations":"Server-side rendering where globalThis.console is absent or shimmed; unit tests that stub console.warn to throw on noise; iframe sandboxes (allow-scripts without a full console); CI pipelines that fail on any console.warn where the silent catch then hides which advisory fired; overridden/monkey-patched consoles in analytics-heavy apps.","solutions":["Do not delete, null, or reassign console.warn to a throwing function in any environment where Swiper runs; if you must silence noise, filter by message prefix instead of throwing.","If running in SSR/Node, ensure globalThis.console is a real console (e.g. keep Node's default) or polyfill console.warn before constructing the Swiper instance.","To capture Swiper warnings deterministically, wrap console.warn before new Swiper(...) and forward matching messages, since the internal try/catch will otherwise swallow failures.","Treat Swiper warnings as config defects: fix the upstream loop/grid config (see errors 1-4) so showWarning is never called, rather than relying on console visibility."],"exampleFix":"// before -- Swiper warnings go to console.warn and may be swallowed by showWarning's try/catch\nconst swiper = new Swiper(el, { loop: true });\n// after -- intercept console.warn before init to capture every Swiper advisory\nconst captured: string[] = [];\nconst origWarn = console.warn.bind(console);\nconsole.warn = (m: unknown) => {\n  if (typeof m === 'string' && m.startsWith('Swiper')) captured.push(m);\n  origWarn(m);\n};\nconst swiper = new Swiper(el, { loop: true });","handlingStrategy":"validation","validationCode":"// Run once, before any Swiper instance is created, to ensure warnings can surface\nfunction ensureSwiperConsole(): void {\n  const g = globalThis as { console?: Partial<Console> };\n  if (typeof g.console?.warn !== 'function') {\n    g.console = {\n      ...(g.console ?? {}),\n      warn: (m?: unknown) => process.stderr.write(String(m ?? '') + '\\n'),\n    } as Console;\n  }\n}\nensureSwiperConsole();","typeGuard":"function hasWarnableConsole(c: unknown): c is Console & { warn: (m?: unknown) => void } {\n  return typeof c === 'object' && c !== null && typeof (c as Console).warn === 'function';\n}","tryCatchPattern":"// showWarning swallows internally, so intercept BEFORE it runs\nconst swiperWarnings: string[] = [];\nconst origWarn = console.warn.bind(console);\nconsole.warn = (m?: unknown) => {\n  if (typeof m === 'string' && m.startsWith('Swiper')) swiperWarnings.push(m);\n  origWarn(m);\n};\ntry {\n  const swiper = new Swiper(el, params);\n} finally {\n  console.warn = origWarn; // restore\n}","preventionTips":["Never delete/null console.warn or stub it to throw in environments where Swiper runs; filter by message prefix instead.","In SSR or test setups, assert typeof globalThis.console?.warn === 'function' before constructing Swiper.","Capture warnings via a console.warn hook rather than relying on showWarning's internal try/catch, which is silent.","Treat any Swiper warning as a config defect and fix the triggering condition so showWarning is never called."],"tags":["console","observability","ssr","warnings","showwarning"],"backgroundTag":null,"analyzedSha":"6138c2a6857d17fe097149dd3b975b2387d0b2dc","analyzedAt":"2026-08-12T21:16:10.868Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}