logancyang_obsidian-copilot/src
Logan Yang 7587b4fa4d
fix(mobile): import Buffer from the buffer polyfill so it works in WebView (#2443)
Mobile Obsidian runs on Capacitor + WebView (no Node.js runtime), so the
bare `Buffer` global is undefined. On iOS WebKit this surfaces as the
runtime error "Can't find variable: Buffer" the moment the image
processing path fires. Desktop is unaffected because Electron exposes
Node globals.

Two PRs in 3.3.0 introduced direct `Buffer.from(...)` calls in
image-handling paths assuming "Buffer is global":

- #2403 rewrote src/utils/base64.ts from btoa/atob to bare Buffer.from
- #2401 did the same in src/utils.ts safeFetch arrayBuffer branch and
  src/LLMProviders/BedrockChatModel.ts decodeBase64ToUint8Array

Result: any image attachment on mobile fails with "failed to send
image, please try again". Confirmed via user log:

  ERROR Error sending message: Can't find variable: Buffer

The fix is an explicit `import { Buffer } from "buffer"` in each
affected file. The `buffer` npm package (already in dependencies) is a
browser-compatible polyfill that esbuild bundles into main.js, so the
same Buffer code path works on desktop (where it's effectively the
Electron-provided Buffer) and on mobile (where it's the polyfill).

Two lint rules complicate this:
- Obsidian's official scorecard flags btoa/atob as deprecated and
  asks for Buffer.from. That rules out reverting to btoa/atob.
- The repo's own `import/no-nodejs-modules` rule blocks `import from
  "buffer"`. Suppressed inline at each import site with justification,
  because `buffer` here is the npm polyfill (in package.json
  dependencies), not Node's built-in being used at runtime.

Files touched:
- src/utils/base64.ts (arrayBufferToBase64 / base64ToArrayBuffer)
  This is the call site the image processor hits and the path
  encryptionService.ts uses for WEBCRYPTO_PREFIX (mobile encryption),
  so mobile encryption is also fixed transitively.
- src/utils.ts (safeFetch arrayBuffer fallback)
- src/LLMProviders/BedrockChatModel.ts (decodeBase64ToUint8Array)

Regression test:
- src/utils/base64.test.ts deletes globalThis.Buffer before exercising
  the helpers to confirm the imported polyfill binding is what gets
  used (not a bare global reference). Catches any future regression
  where someone replaces the import with a bare global usage.

Out of scope:
- src/encryptionService.ts has Buffer.from references but they sit
  inside desktop-only branches (`getSafeStorage().isEncryptionAvailable()`
  / DESKTOP_PREFIX) that mobile never enters. Touching them from a
  mobile hotfix would expand blast radius unnecessarily.
- src/LLMProviders/BedrockChatModel.ts:835 is already guarded with
  `typeof Buffer !== "undefined"` so mobile skips it; left alone.

Bundle size unchanged at 3.3 MB (buffer polyfill is small).

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 23:05:29 -07:00
..
__tests__ chore(types): tighten types and replace TFile/TFolder casts (W1/9) (#2403) 2026-05-12 16:18:22 -07:00
cache chore(eslint): enable @typescript-eslint/no-unsafe-return and fix violations (#2436) 2026-05-13 22:04:59 -07:00
commands chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
components chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
context chore(eslint): enable @typescript-eslint/no-unsafe-return and fix violations (#2436) 2026-05-13 22:04:59 -07:00
contexts fix(popout): document ownership and selection listener fixes (W4/9) (#2406) 2026-05-12 21:28:04 -07:00
core chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
editor chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
hooks chore(eslint): enable no-unsafe-member-access; fix 124 violations (#2438) 2026-05-13 22:35:38 -07:00
imageProcessing Improve custom command (#1942) 2025-10-20 17:52:50 -07:00
integration_tests chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
lib chore(eslint): enable @typescript-eslint/unbound-method (#2439) 2026-05-13 22:09:34 -07:00
LLMProviders fix(mobile): import Buffer from the buffer polyfill so it works in WebView (#2443) 2026-05-13 23:05:29 -07:00
memory chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
mentions feat: add Firecrawl and Supadata self-host support for web search and YouTube (#2196) 2026-02-19 20:44:39 -08:00
miyo chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
projects chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
search chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
services chore(lint): enable 4 type-aware quick-win rules and fix violations (#2424) 2026-05-13 21:57:33 -07:00
settings chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
state chore(lint): enable obsidianmd/rule-custom-message and fix violations (#2416) 2026-05-13 01:39:35 -07:00
styles fix(agent): improve inline citations, query dedup, and answer source priority (#2300) 2026-03-14 23:41:31 -07:00
system-prompts chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
tests chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
tools chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
types Address quick ask (#2146) 2026-02-03 20:04:10 -08:00
utils fix(mobile): import Buffer from the buffer polyfill so it works in WebView (#2443) 2026-05-13 23:05:29 -07:00
aiParams.ts chore(lint): enable obsidianmd/rule-custom-message and fix violations (#2416) 2026-05-13 01:39:35 -07:00
chainFactory.ts chore(eslint): enable @typescript-eslint/no-unsafe-return and fix violations (#2436) 2026-05-13 22:04:59 -07:00
chainType.ts chore(lint): enable obsidianmd/rule-custom-message and fix violations (#2416) 2026-05-13 01:39:35 -07:00
chainUtils.ts fix: defense-in-depth overrides to prevent tiktoken CDN timeout in Plus mode (#2283) 2026-03-13 21:48:13 -07:00
chatUtils.toolMarkers.test.ts chore(eslint): enable @typescript-eslint/no-unsafe-argument and fix violations (#2440) 2026-05-13 21:40:26 -07:00
chatUtils.ts Implement modular context compaction architecture (#2159) 2026-02-06 21:52:33 -08:00
composerUtils.ts Squash preview (#1502) 2025-05-30 20:06:25 -07:00
constants.ts chore(lint): enable obsidianmd/rule-custom-message and fix violations (#2416) 2026-05-13 01:39:35 -07:00
context.ts Listen to active note changes (#1015) 2025-01-06 23:23:56 -08:00
contextProcessor.dataview.test.ts chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
contextProcessor.embeds.test.ts chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
contextProcessor.selectedText.test.ts Address quick ask (#2146) 2026-02-03 20:04:10 -08:00
contextProcessor.ts chore(eslint): enable @typescript-eslint/no-unsafe-argument and fix violations (#2440) 2026-05-13 21:40:26 -07:00
encryptionService.test.ts chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
encryptionService.ts chore(eslint): enable @typescript-eslint/no-unsafe-return and fix violations (#2436) 2026-05-13 22:04:59 -07:00
error.ts feat: add confirmation dialog before clearing Miyo index (#2211) 2026-03-03 11:11:13 +09:00
errorFormat.ts chore(eslint): enable no-unsafe-member-access; fix 124 violations (#2438) 2026-05-13 22:35:38 -07:00
langchainStream.test.ts chore(eslint): enable @typescript-eslint/no-unsafe-argument and fix violations (#2440) 2026-05-13 21:40:26 -07:00
langchainStream.ts feat: Improve error handling architecture across chain runners. (#1931) 2025-10-23 17:00:23 -07:00
logFileManager.ts chore(types): tighten types and replace TFile/TFolder casts (W1/9) (#2403) 2026-05-12 16:18:22 -07:00
logger.ts chore(eslint): enable @typescript-eslint/no-unsafe-argument and fix violations (#2440) 2026-05-13 21:40:26 -07:00
main.ts chore(eslint): enable no-unsafe-member-access; fix 124 violations (#2438) 2026-05-13 22:35:38 -07:00
noteUtils.ts Throttle number of links returned (#998) 2025-01-02 18:18:56 -08:00
plusUtils.ts chore(lint): enable obsidianmd/rule-custom-message and fix violations (#2416) 2026-05-13 01:39:35 -07:00
rateLimiter.ts chore(popout): window-global API swaps — timers, globalThis, base64 (W3/9) (#2401) 2026-05-12 22:24:17 -07:00
types.ts Add Editor "Quick Ask" Floating Panel + Persistent Selection Highlights (#2139) 2026-02-03 17:37:33 -08:00
utils.cleanMessageForCopy.test.ts Composer V2: Replace replaceInFile with editFile as the primary targeted-edit tool (#2305) 2026-03-17 18:51:39 +09:00
utils.test.ts chore(eslint): enable no-unsafe-assignment for tests (#2434) 2026-05-13 22:56:46 -07:00
utils.ts fix(mobile): import Buffer from the buffer polyfill so it works in WebView (#2443) 2026-05-13 23:05:29 -07:00