
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@webcontainer/env
Advanced tools
⚠️ Important ⚠️
We strongly recommend that you update to version
1.1.0or greater as we recently introduced a breaking change in WebContainer, making older versions of@webcontainer/apigenerate invalidHostURL.hrefandHostURL.hostnamewhen those methods are called inside a WebContainer.
Set of environment utilities for WebContainers.
$ npm install @webcontainer/env
isWebContainer(): boolean (method)Returns a boolean indicating whether the program runs in a WebContainer.
HostURL (class)The HostURL class represents a host specific URL. It can be used to parse a regular URL, such as
http://localhost:1234, into a HostURL. Only if the program is executed in a WebContainer,
the hostname is resolved to a WebContainer hostname, e.g. http://blitz--1234.local.webcontainer.io.
This can be useful to create platform-dependent OAuth callback URLs.
HostURL.port(): string (getter)HostURL.hash(): string (getter)HostURL.host(): string (getter)HostURL.hostname(): string (getter)HostURL.href(): string (getter)HostURL.origin(): string (getter)HostURL.username(): string (getter)HostURL.password(): string (getter)HostURL.pathname(): string (getter)HostURL.protocol(): string (getter)HostURL.search(): string (getter)HostURL.searchParams(): URLSearchParams (getter)HostURL.parse(url: string | URL): HostURL (static method)Parses a url into a HostURL. On local this is a no-op but when running in a WebContainer it resolves localhost
to a WebContainer hostname.
Example
import { HostURL, isWebContainer } from '@webcontainer/env';
const hostURL = HostURL.parse('http://localhost:1234');
/**
* Note that this branching would not be necessary as the host URL gets parsed
* and resolved automatically through `HostURL.parse()` (see above). So `href`
* will return a different value depending on the environment. This is illustrated
* with the following `if` statement.
*/
if (isWebContainer()) {
console.log(hostURL.href); // http://blitz--1234.local.webcontainer.io
} else {
console.log(hostURL.href); // http://localhost:1234
}
HostURL.update(change: Partial<UpdateableURLProperties>): HostURL (method)Updates the HostURL.
Object containing the URL changes. Note that some properties are immutable (read-only), e.g. origin or searchParams. When updating the port it automatically updates the host.
Type: Partial<UpdateableURLProperties>
interface UpdateableURLProperties {
hash: string;
host: string;
hostname: string;
href: string;
password: string;
pathname: string;
port: string;
protocol: string;
search: string;
username: string;
}
HostURL.toString(): string (method)Stringifies the HostURL. It is effectively a read-only version of HostURL.href.
HostURL.toJSON(): string (method)Returns a string containing a serialized version of the HostURL.
FAQs
Set of environment utilities for WebContainers
The npm package @webcontainer/env receives a total of 828,070 weekly downloads. As such, @webcontainer/env popularity was classified as popular.
We found that @webcontainer/env demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.