alexanderatallah / window.ai

Use your own AI models on the web
https://windowai.io
MIT License
834 stars 78 forks source link

window.ai fails if document title contains any non ISO-8859-1 code point character #83

Closed FurryR closed 1 month ago

FurryR commented 1 month ago

This bug is done by a mistake. Bro really needs an AI code approval ๐Ÿ’€

Expected behavior

window.ai.generateText works fine.

Actual behavior

window.ai.generateText fails when document.title contains any non ISO-8859-1 code point character.

Where?

https://github.com/alexanderatallah/window.ai/blob/fa05ec564d47a93c0ae46e9386368fd3ae76486c/apps/extension/src/core/llm/model.ts#L355 didn't use encodeURIComponent.

Related: https://github.com/alexanderatallah/window.ai/blob/fa05ec564d47a93c0ae46e9386368fd3ae76486c/apps/extension/src/core/model-router.ts#L51

Step to produce

  1. Open windowai.io.
  2. document.title = 'ไฝ ๅฅฝใ“ใ‚“ใซใกใฏ๐Ÿฆ–๐Ÿฆ–'
  3. await window.ai.generateText(
    { messages: [{role: "user", content: "I guess you are dead arent you"}] }
    )
  4. ๐ŸŽ‰ Your website exploded!

Possible Workaround

Before any request, set document.title to a ISO-8859-1 (aka Latin-1) only string.

Exception message

Uncaught Unknown error: TypeError: Failed to construct 'Headers': String contains non ISO-8859-1 code point.