Skip to content

About

Parse and render AI answers from ChatGPT, Google AI Overview, Google AI Mode, Gemini and Bing AI Mode

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

@cloro-dev/response-parser

A TypeScript library that parses and renders AI answers from ChatGPT, Google AI Overview, Google AI Mode, Gemini, Bing AI Mode and Meta AI, as cloro returns them. cloro is the API for AI answers.

Framework-Agnostic: This library returns HTML strings that can be rendered in any framework (React, Vue, Svelte, vanilla JS, etc.).

Features

  • 🤖 Multi-Provider Support: ChatGPT, Google AI Overview, Google AI Mode, Gemini, Bing AI Mode and Meta AI. Stored Perplexity, Copilot and Grok responses still render
  • 🔍 Auto-Detection: Automatically detects the AI provider from response structure
  • 🎨 Built-in Styling: Provider-specific styling
  • 🔧 Framework-Agnostic: Pure HTML output for any framework
  • 🧹 Script removal: Removes <script> and <noscript> elements. This is not a full HTML sanitizer.
  • 📦 TypeScript: Full TypeScript support with comprehensive types
  • 🎯 Lightweight: No runtime dependencies for core parsing

Installation

npm install @cloro-dev/response-parser
# or
yarn add @cloro-dev/response-parser
# or
pnpm add @cloro-dev/response-parser

Quick Start

This library parses AI responses and returns HTML strings. You can render the HTML in any framework.

Security: The parser removes only <script> and <noscript> elements. It does not remove event handler attributes (for example onerror=) or javascript: URLs. If the HTML comes from a source that you do not trust, sanitize parsed.html with a full HTML sanitizer (for example DOMPurify) before you render it, or show it in an <iframe> with a sandbox attribute that does not include allow-scripts.

import { parseAiResponse, detectProvider } from "@cloro-dev/response-parser";

// Auto-detect provider and parse
const response = await fetchAIResponse();
const parsed = parseAiResponse(response);

console.log(parsed.provider); // 'CHATGPT' | 'GEMINI' | etc.
console.log(parsed.html); // HTML with <script> and <noscript> elements removed
console.log(parsed.text); // Plain text version

Usage Examples

React

import { parseAiResponse } from "@cloro-dev/response-parser";

function MyComponent() {
  const parsed = parseAiResponse(aiResponse, {
    removeLinks: true
  });

  return (
    <div dangerouslySetInnerHTML={{ __html: parsed.html }} />
  );
}

Vue

<script setup>
import { parseAiResponse } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(aiResponse, {
  removeLinks: true
});
</script>

<template>
  <div v-html="parsed.html"></div>
</template>

Svelte

<script>
import { parseAiResponse } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(aiResponse, {
  removeLinks: true
});
</script>

<div>{@html parsed.html}</div>

Vanilla JavaScript

import { parseAiResponse } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(aiResponse, {
  removeLinks: true
});

document.getElementById('output').innerHTML = parsed.html;

API Reference

parseAiResponse(response, options?)

Parse an AI response with auto-detected provider.

Options:

  • removeLinks: boolean - Make all hyperlinks in the HTML not clickable. The parser removes the href and keeps the link text and its style (default: false)
  • removeHeader: boolean - Remove navigation bar/header (default: false; true for AI Overview & AI Mode. ChatGPT, Perplexity, Gemini, Copilot, Grok, AI Overview, AI Mode & Meta AI)
  • removeFooter: boolean - Remove follow-up input box/footer (default: false; true for AI Overview & AI Mode. ChatGPT, Perplexity, Gemini, Copilot, Grok, AI Overview, AI Mode & Meta AI)
  • removeSidebar: boolean - Remove sidebar (default: false, ChatGPT, Gemini, Perplexity, Copilot, AI Mode & Meta AI)
  • removeSources: boolean - Remove sources/references panel (default: false, ChatGPT, Gemini, Perplexity, Copilot, Grok, Bing AI Mode & Meta AI)
  • invertColors: boolean - Invert the colors of the page. A light page becomes dark and a dark page becomes light. Images, videos and other media keep their colors (default: false, all providers)

Note: Cookie/privacy banners are automatically removed for ChatGPT, AI Mode, Copilot, Grok, and Perplexity — no option needed. Sign-in prompts are automatically removed for Gemini, Perplexity and Meta AI. For Meta AI, the parser also always hides toasts and open dialogs.

Returns: ParsedResponse | null

interface ParsedResponse {
  provider: AIProvider;
  html: string;
  text: string;
  sources?: Array<{
    title: string;
    url: string;
    snippet?: string;
  }>;
}

detectProvider(response)

Detect the AI provider from a response.

Returns: AIProvider | null

type AIProvider =
  | 'CHATGPT'
  | 'GEMINI'
  | 'PERPLEXITY'
  | 'COPILOT'
  | 'AIOVERVIEW'
  | 'AIMODE'
  | 'BING_AIMODE'
  | 'GROK'
  | 'META_AI';

PERPLEXITY, COPILOT and GROK are for stored responses only: cloro discontinued those endpoints. Use BING_AIMODE for Bing's AI answers.

Supported Providers

Provider Status Features
ChatGPT ✅ Sidebar, header, footer removal, auto cookie banner hiding
Gemini ✅ Sidebar, header, footer, sources removal
Perplexity ⚠️ Deprecated Sidebar, header, footer, sources removal, auto cookie banner hiding
Copilot ⚠️ Deprecated Sidebar, header, footer, sources removal, auto cookie banner hiding
AI Overview ✅ Header, footer removal, WIZ data extraction
AI Mode ✅ Sidebar, header, footer removal, auto cookie banner hiding
Bing AI Mode ✅ Renders the whole answer (from the answer frame's srcdoc); header (reasoning panel) and sources removal
Grok ⚠️ Deprecated Sources removal, auto cookie banner hiding
Meta AI ✅ Sidebar, header, footer, sources removal, auto login button, toast and dialog hiding

Common Use Cases

Remove Hyperlinks

import { parseAiResponse } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(response, {
  removeLinks: true, // Removes the href of all links, keeps the text
});

Clean View (Remove UI Elements)

const parsed = parseAiResponse(response, {
  removeHeader: true,  // Remove top navigation bar
  removeFooter: true,  // Remove follow-up input box
  removeLinks: true,   // Remove all hyperlinks
  removeSources: true, // Remove sources/references panel
});

Invert Colors

The engines return pages in a light or a dark theme. Set invertColors to show a page in the other theme.

const parsed = parseAiResponse(response, {
  invertColors: true, // Light page becomes dark, dark page becomes light
});

The parser adds a CSS filter to the <html> element. It does not detect the theme of the page. The option applies to parseAiResponse, parser.parse and parser.parseWithProvider. It does not apply when you call a provider class (for example new ChatGPTProvider().parse()) directly.

Manual Provider Specification

import { parseAiResponse, AIProvider } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(response, {
  provider: "CHATGPT",
});

Provider Detection Only

import { detectProvider } from "@cloro-dev/response-parser";

const provider = detectProvider(response);
console.log(`Detected: ${provider}`); // 'CHATGPT' | 'GEMINI' | etc.

Migration from v0.1.x

If you were using React components from v0.1.x, here's how to migrate:

Before (v0.1.x with React)

import { ResponseRenderer } from "@cloro-dev/response-parser/react";

<ResponseRenderer
  response={response}
  removeLinks={true}
  onProviderDetected={(provider) => console.log("Detected:", provider)}
/>

After (v0.2.0 framework-agnostic)

import { parseAiResponse } from "@cloro-dev/response-parser";

const parsed = parseAiResponse(response, {
  removeLinks: true
});

console.log("Detected:", parsed.provider);

<div dangerouslySetInnerHTML={{ __html: parsed.html }} />

The core parsing logic is identical - you just need to handle the HTML rendering yourself in your framework of choice.

What's Changed

v0.8.0

  • ✅ Added Meta AI provider (META_AI) for the Meta AI pages that the cloro API returns (/v1/monitor/meta-ai). Before, the parser detected these pages as Perplexity, and the Grok provider did not hide the parts of the page
  • ✅ Added Meta AI removeHeader hides the title bar above the conversation. removeFooter hides the prompt box ("Ask a follow up..."). removeSidebar hides the left rail. removeSources hides the citation chips in the text and the "Sources" button below the answer. The answer text stays, and the entity names in the text (for example "NASA") stay
  • ✅ Added Meta AI "Log in" and "Sign up" buttons, toasts and open dialogs are always hidden

v0.7.4

  • ✅ Fixed Some cleanup patterns were slow on crafted pages (CodeQL js/polynomial-redos). For example, 60 KB of <div class="ca_userquery_text" took 27 s with BING_AIMODE, and 234 KB of <div class=" took 37 s with COPILOT. All patterns now read the page a fixed number of times, and a 300 KB crafted page takes less than 0.1 s. The output for normal pages does not change
  • ✅ Fixed Script removal now also removes end tags with spaces or attributes (</script >). Before, such an end tag let a <script> element stay, or made the removal include the text up to the next </script>. A <script or </script that stays after the removal, for example from <scr<script></script>ipt>, becomes &lt;script. This is still not a full HTML sanitizer: see the Security note

v0.7.3

  • ✅ Fixed ChatGPT removeHeader, removeFooter and removeSidebar now work on the mobile web page. Before, the login card and an empty sidebar column stayed, and removeSidebar cut off the left part of the prompt box
  • ✅ Fixed ChatGPT pages captured in the dark theme showed dark text on a dark background. The parser now shows ChatGPT pages in their light theme
  • ✅ Fixed ChatGPT answer parts that set a dark color scheme on a light page showed white text on a white background
  • ✅ Fixed The ChatGPT login cards in the answer ("Log in for advice and recommendations…") are now always hidden
  • ✅ Fixed When the ChatGPT mobile web page is less than 800 px wide and removeSidebar is off, the open sidebar no longer covers the answer
  • ✅ Fixed A Bing AI Mode question with $1 in it (for example "under $150") lost those characters and got a second <body> tag
  • ✅ Fixed Gemini removeFooter no longer shows a menu that was open when the page was captured. Menus and tooltips are now always hidden
  • ✅ Fixed When the Gemini page is less than 560 px wide, the header links no longer cover the logo
  • ✅ Fixed Google News removeHeader now hides the line below the header
  • ✅ Changed removeLinks now removes the href of each link and keeps the <a> element, so the page keeps its layout and fonts. Before, it removed the <a> elements, which broke the Bing Search page and the Gemini header. ChatGPT is not changed

v0.7.0

  • ✅ Added invertColors option for all providers. It inverts the colors of the page, and images and videos keep their colors. metadata.colorsInverted is true when the option is applied
  • ✅ Fixed The ChatGPT mobile web page showed its answer text dark on a dark background when the viewer's browser is in dark mode. The parser now keeps pages that use Lightning CSS color variables in their light theme

v0.5.3

  • First release from the Publish workflow, with npm Trusted Publishing and provenance. No library changes

v0.5.2

  • ✅ Fixed The README said that the parser sanitizes HTML. It removes only <script> and <noscript> elements. A new Security note tells you to sanitize untrusted HTML before you render it
  • ✅ Fixed The package.json repository URL now points to cloro-dev/response-parser

v0.5.1

  • ✅ Fixed ChatGPT removeSources now hides the open sources dialog of the mobile page

v0.5.0

  • ✅ Fixed require("@cloro-dev/response-parser") failed with exports is not defined. The CommonJS build is now dist/index.cjs
  • ✅ Fixed Perplexity removeSources now hides the open "Sources" popover
  • ✅ Fixed Perplexity cookie banner (new markup) and sign-in prompts are now always hidden
  • ✅ Fixed Copilot removeHeader and removeSidebar no longer break the page layout. removeSidebar no longer hides the references panel
  • ✅ Fixed Copilot removeHeader now hides the date divider
  • ✅ Fixed ChatGPT removeSources now hides the sources flyout and the sources sheet on all pages
  • ✅ Fixed ChatGPT removeFooter and removeSidebar no longer change the page structure
  • ✅ Fixed Gemini sign-in prompt is now always hidden
  • ✅ Fixed AI Overview removeFooter now hides the Google footer
  • ✅ Fixed Provider detection no longer depends on pattern order for Gemini pages, and no longer reports a Google result page that links to Gemini as Gemini

v0.4.3

  • ✅ Added Perplexity removeSidebar support (left navigation removal)
  • ✅ Fixed Perplexity layout rendering in iframes (CSS overrides for single-column flow)
  • ✅ Fixed Perplexity removeFooter now hides the "Ask a follow-up" bar via CSS
  • ✅ Fixed ChatGPT removeFooter now hides the composer input form and collapses blank space
  • ✅ Fixed ChatGPT removeSidebar now hides leftover sidebar items via CSS
  • ✅ Fixed AI Mode removeHeader now hides the "New thread" compose button
  • ✅ Fixed Copilot removeHeader now hides the sticky header (share button)
  • ✅ Improved CSS overrides are now conditional — only injected when the corresponding remove* option is true (Perplexity, ChatGPT, Copilot)

v0.4.2

  • ✅ Added ChatGPT automatic cookie banner removal
  • ✅ Fixed Copilot sources removal regex to handle variable panel widths

v0.4.1

  • ✅ Added Copilot removeSources and removeSidebar support
  • ✅ Added Copilot automatic cookie banner removal
  • ✅ Added AI Mode removeSidebar support (history panel removal)
  • ✅ Fixed AI Mode sidebar/footer removal and detection
  • ✅ Added AI Mode automatic cookie consent banner hiding

v0.4.0

  • ✅ Added removeSources option for Gemini, Perplexity, and Grok
  • ✅ Added automatic cookie/privacy banner removal for Perplexity and Grok
  • ✅ Fixed Perplexity collapsed answer container (JS animation height workaround)

v0.3.0

  • ✅ Added Grok provider support
  • ✅ Simplified codebase and removed colour inversion

v0.2.0

  • ✅ Removed React components and hooks (now framework-agnostic)
  • ✅ Removed React peer dependency
  • ✅ Simplified API to return pure HTML strings
  • ✅ Keep core parsing logic (unchanged)

v0.1.4

  • ✅ Renamed removeNavbar → removeHeader (removes navigation bar/header)
  • ✅ Renamed removeFollowup → removeFooter (removes follow-up input box/footer)
  • ✅ Extended removeHeader support to AI Overview and AI Mode
  • ✅ Extended removeFooter support to all providers (ChatGPT, Perplexity, Gemini, Copilot, AI Overview, AI Mode)
  • ✅ Improved ChatGPT styling
  • ✅ Updated AI Mode and AI Overview parsers

v0.1.3

  • ✅ Always removes <script> and <noscript> elements from the HTML
  • ✅ Always includes provider-specific styles
  • ✅ Always uses provider's base URL for relative links
  • ❌ Removed theme option (styles are provider-specific)
  • ❌ Removed sanitize option (always enabled)
  • ❌ Removed includeStyles option (always enabled)
  • ❌ Removed baseUrl option (uses provider default)

Development

# Install dependencies
pnpm install

# Build
pnpm build

# Development mode
pnpm dev

# Type check
pnpm type-check

# Lint
pnpm lint

Release

The Publish workflow publishes the package to npm when a version tag is pushed. It uses npm Trusted Publishing, so you do not need to log in to npm.

  1. Add an entry under "What's Changed".

  2. Increase the version. This changes package.json and creates a git commit and a v tag:

    npm version patch   # 0.5.2 → 0.5.3
    npm version minor   # 0.5.2 → 0.6.0
    npm version major   # 0.5.2 → 1.0.0
  3. Push the commit and the tag. The workflow type-checks, lints, builds and publishes:

    git push --follow-tags

License

MIT © cloro

About

Parse and render AI answers from ChatGPT, Google AI Overview, Google AI Mode, Gemini and Bing AI Mode

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages