{"record":{"id":"e9a385fa82e326cc","repo":"linshenkx/prompt-optimizer","slug":"this-html-file-does-not-contain-prompt-optimizer-f","errorCode":null,"errorMessage":"This HTML file does not contain Prompt Optimizer favorite share data","messagePattern":"This HTML file does not contain Prompt Optimizer favorite share data","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/utils/favorite-share-export.ts","lineNumber":1453,"sourceCode":"    !isRecord(parsed) ||\n    parsed.schemaVersion !== FAVORITE_SHARE_SCHEMA_VERSION ||\n    parsed.format !== 'favorite-share' ||\n    typeof parsed.packageBase64 !== 'string'\n  ) {\n    throw new Error('Invalid favorite share payload')\n  }\n  return parsed as FavoriteSharePayload\n}\n\nexport const readFavoriteSharePackage = (\n  input: ArrayBuffer | Uint8Array | string,\n): Uint8Array => {\n  if (typeof input === 'string') {\n    const parser = new DOMParser()\n    const document = parser.parseFromString(input, 'text/html')\n    const script = document.getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)\n    if (!script?.textContent) {\n      throw new Error('This HTML file does not contain Prompt Optimizer favorite share data')\n    }\n    return base64ToBytes(parseSharePayload(script.textContent).packageBase64)\n  }\n\n  const bytes = input instanceof Uint8Array ? input : new Uint8Array(input)\n  const chunk = readPngTextChunk(bytes, FAVORITE_SHARE_PNG_TEXT_KEYWORD)\n  if (!chunk) {\n    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.')\n  }\n  return base64ToBytes(parseSharePayload(chunk).packageBase64)\n}\n\nexport const looksLikeFavoriteShareHtml = (\n  fileName: string | undefined,\n  text: string,\n): boolean => {\n  const normalizedName = String(fileName || '').toLowerCase()\n  return (","sourceCodeStart":1435,"sourceCodeEnd":1471,"githubUrl":"https://github.com/linshenkx/prompt-optimizer/blob/3e677b1d9f7e0493c142c175560531e7ae786dce/packages/ui/src/utils/favorite-share-export.ts#L1435-L1471","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-export or re-download the original share HTML file and import that unchanged","Pre-check the file with looksLikeFavoriteShareHtml(fileName) / a content sniff before calling the reader","Transfer the file as a real attachment (not inline HTML preview) so scripts aren't stripped","If you control generation, embed the payload in a non-script element (e.g. data attribute or comment) as a fallback"],"exampleFix":"// before\nconst pkg = readFavoriteSharePackage(htmlString)\n\n// after\nif (!looksLikeFavoriteShareHtml(fileName) || !htmlString.includes(FAVORITE_SHARE_HTML_SCRIPT_ID)) {\n  throw new UserError('Not a Prompt Optimizer share HTML file')\n}\nconst pkg = readFavoriteSharePackage(htmlString)","handlingStrategy":"validation","validationCode":"const htmlOk =\n  typeof input === 'string' &&\n  input.includes(`id=\"${FAVORITE_SHARE_HTML_SCRIPT_ID}\"`)\nif (!htmlOk) throw new UserError('Not a Prompt Optimizer share HTML file')","typeGuard":"const containsShareScript = (html: string): boolean =>\n  new DOMParser().parseFromString(html, 'text/html')\n    .getElementById(FAVORITE_SHARE_HTML_SCRIPT_ID)?.textContent != null","tryCatchPattern":"try { readFavoriteSharePackage(html) } catch (e) { if (e.message.includes('does not contain Prompt Optimizer favorite share data')) promptForOriginalFile(); else throw e }","preventionTips":["Use looksLikeFavoriteShareHtml(fileName) as a first-pass filter","Transfer share HTML as attachments, not inline previews","Keep an untouched copy of the exported file"],"tags":["html","import","dom-parsing","sanitization"],"backgroundTag":"missing-payload-in-file","analyzedSha":"3e677b1d9f7e0493c142c175560531e7ae786dce","analyzedAt":"2026-08-27T21:29:16.709Z","schemaVersion":2},"datasetVersion":"2026-08-28T00:17:15.603Z"}