Skip to content

fix(http): guard top-level Deno global access for browser compatibility#6987

Merged
kt3k merged 1 commit intodenoland:mainfrom
Asguho:fix/guard-top-level-deno-access
Feb 16, 2026
Merged

fix(http): guard top-level Deno global access for browser compatibility#6987
kt3k merged 1 commit intodenoland:mainfrom
Asguho:fix/guard-top-level-deno-access

Conversation

@Asguho
Copy link
Contributor

@Asguho Asguho commented Feb 6, 2026

Problem:
When importing UserAgent or other utilities from @std/http in a browser environment (e.g., via Vite), the application crashes. This occurs because file_server.ts performs top-level execution of code accessing the Deno global namespace (specifically Deno.permissions and Deno.env) which does not exist in the browser.
Solution:
This PR adds a typeof Deno !== "undefined" check before attempting to access permission queries or environment variables. This ensures the module can be loaded in non-Deno environments without throwing a ReferenceError.

If there is anything else I can do to help this merge, please let me know.

@Asguho Asguho requested a review from kt3k as a code owner February 6, 2026 14:18
@CLAassistant
Copy link

CLAassistant commented Feb 6, 2026

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the http label Feb 6, 2026
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

❌ Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.19%. Comparing base (1cd85bf) to head (c66e55e).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
http/file_server.ts 42.85% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6987      +/-   ##
==========================================
- Coverage   94.20%   94.19%   -0.01%     
==========================================
  Files         613      613              
  Lines       47710    47715       +5     
  Branches     8299     8299              
==========================================
+ Hits        44945    44946       +1     
- Misses       2697     2701       +4     
  Partials       68       68              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

@kt3k kt3k merged commit 8fc6113 into denoland:main Feb 16, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants