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 — feat: Pass through data URLs directly and gracefully handle unknown U… by yxshee · Pull Request #12592 · anomalyco/opencode

Conversation

@yxshee

@yxshee yxshee commented Feb 7, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Summary

Fixes #12547

Error: TypeError: The URL must be of scheme file (ERR_INVALID_URL_SCHEME)

Root Cause

In prompt.ts, the switch statement at line 946 handles URL protocols:

  • case "data:" only processes text/plain mime types, then breaks
  • For clipboard images (image/png), the condition fails and falls through to case "file:"
  • fileURLToPath() is called on a data: URL → crash

Changes

packages/opencode/src/session/prompt.ts

  • Added proper handling for non-text data: URLs (images, PDFs) - returns them as-is for the model
  • Added default case to prevent silent fall-through for unknown protocols

Why This Happens on Windows

Windows clipboard paste encodes images as data:image/png;base64,... URLs via FileReader.readAsDataURL(). The server-side switch statement wasn't handling this case properly.

Testing

  • Paste image from clipboard on Windows 11 - no crash, image attaches correctly
  • File drop still works
  • File picker still works
  • Paste text still works

Checklist

  • Minimal fix addressing root cause
  • No try-catch band-aids
  • Follows existing code patterns

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

LoserFox reacted with thumbs up emoji LoserFox reacted with rocket emoji
All reactions
  • 👍 1 reaction
  • 🚀 1 reaction
Yash
feat: Pass through data URLs directly and gracefully handle unknown U…
6507e80
…RL protocols in prompt part processing.
Copilot AI review requested due to automatic review settings February 7, 2026 09:30
@github-actions github-actions Bot added contributor needs:issue labels Feb 7, 2026
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot started reviewing on behalf of yxshee February 7, 2026 09:30
View session
@github-actions

github-actions Bot commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Duplicate Found

PR #12549: fix(desktop): windows clipboard images come thru as data not file
#12549

This PR is directly related to the current PR #12592. Both address the same issue: handling clipboard images on Windows that come through as data: URLs instead of file URLs. PR #12549 appears to be a prior fix for the same problem, so you should check if it's already merged or if it needs to be superseded/combined with PR #12592.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot removed the needs:issue label Feb 7, 2026
Copilot AI reviewed Feb 7, 2026
View reviewed changes

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a crash when handling clipboard-pasted images (e.g., Windows 11 data:image/png;base64,...) by preventing data: URLs from falling through to file: handling and by adding a safe fallback for previously-unhandled URL protocols in SessionPrompt.

Changes:

  • Pass through non-text/plain data: URL file parts (e.g., images/PDFs) without attempting fileURLToPath().
  • Add a default branch in the URL protocol switch to avoid unhandled protocols causing failures/dropped parts.
  • Add warning log for unknown protocols (with URL prefix logging).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/opencode/src/session/prompt.ts Outdated
]
default:
// Handle unknown protocols gracefully to prevent crashes
log.warn("unsupported URL protocol", { protocol: url.protocol, url: part.url.slice(0, 100) })

Copilot AI Feb 7, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default-case log includes a prefix of the full URL (part.url.slice(0, 100)), which can leak sensitive user data (e.g., signed URLs/tokens in query strings). Consider logging only the protocol plus a redacted/sanitized identifier (e.g., hostname for http(s), or just url.protocol/mime/length), and avoid logging the URL itself at warn level.

Suggested change
log.warn("unsupported URL protocol", { protocol: url.protocol, url: part.url.slice(0, 100) })
log.warn("unsupported URL protocol", {
protocol: url.protocol,
mime: part.mime,
filename: part.filename,
})

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
Comment thread packages/opencode/src/session/prompt.ts
Comment on lines +1169 to +1172
default:
// Handle unknown protocols gracefully to prevent crashes
log.warn("unsupported URL protocol", { protocol: url.protocol, url: part.url.slice(0, 100) })
return [

Copilot AI Feb 7, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default branch labels any non-data:/file: URL as "unsupported" and emits a warn. The codebase can create http: URLs for image parts (see packages/opencode/src/acp/agent.ts where part.uri.startsWith("http:") becomes a file part), and those may be valid to pass through to providers. Consider adding explicit case "http:":/"https:": to pass through without warning, or change the log message/level to reflect "unhandled" rather than "unsupported" to avoid noisy/misleading logs.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
Comment thread packages/opencode/src/session/prompt.ts Outdated
Comment on lines +974 to +983
// For non-text data URLs (images, PDFs from clipboard), pass through as-is
log.info("data url", { mime: part.mime })
return [
{
...part,
id: part.id ?? Identifier.ascending("part"),
messageID: info.id,
sessionID: input.sessionID,
},
]

Copilot AI Feb 7, 2026

Copy link

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change introduces new behavior for non-text data: URLs and unknown protocols. There are existing SessionPrompt tests under packages/opencode/test/session/; please add coverage for (1) data:image/png;base64,... parts to ensure they no longer crash/are preserved, and (2) a non-file:/data: URL (e.g., http:) to ensure it’s handled consistently (and not dropped).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot uses AI. Check for mistakes.
@yxshee yxshee mentioned this pull request Feb 7, 2026
Crash on Windows when pasting images from clipboard (ERR_INVALID_URL_SCHEME) #12547
Closed
Yash added 2 commits February 7, 2026 18:51
Yash
fix: handle non-text data URLs to prevent Windows clipboard paste crash
ccfd30f
When pasting images from clipboard on Windows 11, the app crashed with:
TypeError: The URL must be of scheme file (ERR_INVALID_URL_SCHEME)
Root cause: The data: case only handled text/plain and broke, causing
non-text data URLs to fall through to file: case which called
fileURLToPath() on a data: URL.
Fix:
- Return non-text data URLs directly instead of breaking
- Add default case to prevent fall-through for unknown protocols
Yash
refactor: Resolve merge conflict and clarify unsupported URL protocol…
684dbd4
… warning message.
@github-actions github-actions Bot mentioned this pull request Feb 8, 2026
fix(desktop): add native clipboard image paste and fix text paste #12682
Merged
@LoserFox LoserFox mentioned this pull request Feb 11, 2026
fix(tui): make Windows image paste reliable #13161
Closed
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot closed this Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Crash on Windows when pasting images from clipboard (ERR_INVALID_URL_SCHEME)

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@yxshee
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.