linshenkx/prompt-optimizer · error · Error

This HTML file does not contain Prompt Optimizer favorite sh

Error message

This HTML file does not contain Prompt Optimizer favorite share data

What it means

readFavoriteSharePackage parses an HTML string with DOMParser, looks for a <script> element with the favorite-share script ID, and throws this when that element is missing or empty. It means the file was parsed as HTML but does not contain an embedded share payload — typically because the HTML was saved/modified in a way that stripped the script tag.

Source

Thrown at packages/ui/src/utils/favorite-share-export.ts:1453

    !isRecord(parsed) ||
    parsed.schemaVersion !== FAVORITE_SHARE_SCHEMA_VERSION ||
    parsed.format !== 'favorite-share' ||
    typeof parsed.packageBase64 !== 'string'
  ) {
    throw new Error('Invalid favorite share payload')
  }
  return parsed as FavoriteSharePayload
}

export const readFavoriteSharePackage = (
  input: ArrayBuffer | Uint8Array | string,
): Uint8Array => {
  if (typeof input === 'string') {
    const parser = new DOMParser()
    const document = parser.parseFromString(input, 'text/html')
    const script = document.getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)
    if (!script?.textContent) {
      throw new Error('This HTML file does not contain Prompt Optimizer favorite share data')
    }
    return base64ToBytes(parseSharePayload(script.textContent).packageBase64)
  }

  const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)
  const chunk = readPngTextChunk(bytes, FAVORITE_SHARE_PNG_TEXT_KEYWORD)
  if (!chunk) {
    throw new Error('This PNG file does not contain Prompt Optimizer favorite share data. Use the original exported PNG file; screenshots or compressed images cannot be imported.')
  }
  return base64ToBytes(parseSharePayload(chunk).packageBase64)
}

export const looksLikeFavoriteShareHtml = (
  fileName: string | undefined,
  text: string,
): boolean => {
  const normalizedName = String(fileName || '').toLowerCase()
  return (

View on GitHub (pinned to 3e677b1d9f)

Solutions

  1. Re-export or re-download the original share HTML file and import that unchanged
  2. Pre-check the file with looksLikeFavoriteShareHtml(fileName) / a content sniff before calling the reader
  3. Transfer the file as a real attachment (not inline HTML preview) so scripts aren't stripped
  4. If you control generation, embed the payload in a non-script element (e.g. data attribute or comment) as a fallback

Example fix

// before
const pkg = readFavoriteSharePackage(htmlString)

// after
if (!looksLikeFavoriteShareHtml(fileName) || !htmlString.includes(FAVORITE_SHARE_HTML_SCRIPT_ID)) {
  throw new UserError('Not a Prompt Optimizer share HTML file')
}
const pkg = readFavoriteSharePackage(htmlString)
Defensive patterns

Strategy: validation

Validate before calling

const htmlOk =
  typeof input === 'string' &&
  input.includes(`id="${FAVORITE_SHARE_HTML_SCRIPT_ID}"`)
if (!htmlOk) throw new UserError('Not a Prompt Optimizer share HTML file')

Type guard

const containsShareScript = (html: string): boolean =>
  new DOMParser().parseFromString(html, 'text/html')
    .getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)?.textContent != null

Try / catch

try { readFavoriteSharePackage(html) } catch (e) { if (e.message.includes('does not contain Prompt Optimizer favorite share data')) promptForOriginalFile(); else throw e }

Prevention

When it happens

Trigger: Calling readFavoriteSharePackage with an HTML string where getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID) returns null or has empty textContent: a regular HTML page, an exported share HTML that was edited/sanitized (script tags stripped by a mail client, CMS, or 'save page' tool), or the wrong file passed to the HTML import path.

Common situations: Users share the exported HTML through email/chat tools that sanitize scripts; uploading a different HTML file; opening the export in a rich-text editor that rewrites markup; script-stripping proxies or sanitizers (DOMPurify, AMP) removing the payload.

Related errors


AI-assisted analysis of linshenkx/prompt-optimizer@3e677b1d9f (2026-08-27). Data as JSON: /api/errors/e9a385fa82e326cc. Report an issue: GitHub.