GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Bug: webfetch with format="text" crashes on HTML content in Electron desktop app (HTMLRewriter is not defined) · Issue #26187 · anomalyco/opencode

Bug: webfetch with format="text" crashes on HTML content in Electron desktop app (HTMLRewriter is not defined) #26187

New issue
Copy link
New issue
Copy link
Closed
Closed
Bug: webfetch with format="text" crashes on HTML content in Electron desktop app (HTMLRewriter is not defined)#26187
Copy link
Assignees
Hona

Description

@Innerpeace1990
Innerpeace1990
opened on May 7, 2026
Issue body actions

Description

The webfetch tool crashes with HTMLRewriter is not defined when called with format: "text" on HTML content in the Electron desktop app (OpenCode.exe).

Root Cause

The extractTextFromHTML() function in packages/opencode/src/tool/webfetch.ts calls new HTMLRewriter() as an un-imported global:

https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/tool/webfetch.ts

HTMLRewriter is a built-in global in Bun and Cloudflare Workers (workerd), but it does not exist in Node.js or Electron.

Runtime HTMLRewriter available?
Bun (CLI/TUI mode) Yes, built-in global
Cloudflare Workers Yes, built-in global
Node.js No
Electron (desktop app) No

The OpenCode desktop app (OpenCode.exe) runs on Electron, so HTMLRewriter is undefined at runtime.

OpenCode Version

  • Desktop app version: 1.14.39 (also confirmed in app.asar as 1.1.0)
  • Platform: Windows (Electron)

Steps to Reproduce

  1. Open OpenCode desktop app (Electron version)
  2. Use the webfetch tool with format: "text" on any HTML page:
    • e.g., webfetch with url https://github.com and format "text"
  3. Observe the error: HTMLRewriter is not defined

Workaround

Use format: "markdown" (the default) instead of format: "text". The markdown path uses TurndownService (pure JavaScript) and works correctly in all runtimes.

Suggested Fix

The simplest fix would be to replace HTMLRewriter with a runtime-agnostic approach. Three options:

Option 1 — Use TurndownService for text extraction too (simplest):

The format: "markdown" path already uses TurndownService to convert HTML to markdown. For format: "text", the markdown output could be further stripped of formatting characters.

Option 2 — Use a simple regex-based approach:

Replace extractTextFromHTML with a regex-based tag stripper that removes <script>, <style>, <noscript> blocks and then strips remaining HTML tags. This would work in all JavaScript runtimes without dependencies.

Option 3 — Add a conditional polyfill:

Detect whether HTMLRewriter is available at runtime, and fall back to a regex-based approach when it is not. This preserves the Bun/Workers fast path while adding Electron compatibility.

Additional Context

  • No existing issues appear to cover this specific bug (searched for "HTMLRewriter" and "webfetch" in issues)
  • PR fix: resolve memory leaks and zombie processes from missing cleanup handlers #13186 previously patched an O(n²) text += pattern in the same function but did not address the missing HTMLRewriter global
  • The bug does not affect format: "markdown" (default) or format: "html"
  • The bug does not affect non-HTML content (JSON, plain text, API responses)

Operating System

Windows 11

Terminal

OpenCode Desktop (Electron)

Reacted by hiraghi

Activity

  1. github-actions
    assigned
    rekram1-node
    on May 7, 2026
  2. alfep commented on May 20, 2026

    @alfep
    alfep
    on May 20, 2026
    More actions

    Additional Reproduction — OpenCode Desktop v1.14.48

    Confirming this bug is still present in v1.14.48 (desktop app).

    Environment

    • OpenCode version: Desktop v1.14.48
    • OS: Windows 11
    • Terminal: PowerShell 7
    • Model: deepseek-v4-flash-free

    Steps Reproduced

    1. Open OpenCode desktop app
    2. Use webfetch with format: "text" on https://example.com
    3. Error: HTMLRewriter is not defined

    Additional Observations

    • format: "markdown" works on some sites (e.g., google.com)
    • format: "text" fails on all HTML pages
    • JSON/API responses work fine regardless of format
    • CLI mode (Bun runtime) works — confirms this is Electron-specific

    Suggested Fix

    Option 1 from the OP seems most practical — reuse the existing TurndownService path for format: "text" by stripping markdown formatting characters. Zero new dependencies, works everywhere.

    This issue (#26187) supersedes my earlier report #27305. Closing that one now.

  3. PaleNeutron commented on May 28, 2026

    @PaleNeutron
    PaleNeutron
    on May 28, 2026
    More actions

    same problem here, waiting for fix

  4. rekram1-node
    assigned
    Hona
    and unassigned
    rekram1-node
    on May 28, 2026
  5. Brendonovich commented on Jun 1, 2026

    @Brendonovich
    Brendonovich
    on Jun 1, 2026
    Member
    More actions

    This was addressed in versions from a few weeks ago by #26309

  6. Brendonovich
    closed this as completedon Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @Hona
    Hona

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.