BrowserProvider.getDownloadUrl() 方法
🌐 BrowserProvider.getDownloadUrl() method
获取所请求浏览器的下载网址。
🌐 Get the download URL for the requested browser.
buildId 可以是确切的版本(例如,“131.0.6778.109”)或别名(例如,“latest”,“stable”)。如果自定义提供器支持别名,则应在内部处理版本解析。
🌐 The buildId can be either an exact version (e.g., "131.0.6778.109") or an alias (e.g., "latest", "stable"). Custom providers should handle version resolution internally if they support aliases.
如果 buildId 无法解析为有效版本,则返回 null。URL 未经过验证——如果 URL 不存在,下载将会在之后失败。
🌐 Returns null if the buildId cannot be resolved to a valid version. The URL is not validated - download will fail later if URL doesn't exist.
对于简单的 URL 构建可以是同步的,如果需要版本解析/网络请求则可以是异步的。
🌐 Can be synchronous for simple URL construction or asynchronous if version resolution/network requests are needed.
语法
🌐 Signature
interface BrowserProvider {
getDownloadUrl(options: DownloadOptions): Promise<URL | null> | URL | null;
}
参数
🌐 Parameters
范围 🌐 Parameter | 类型 🌐 Type | 描述 🌐 Description |
|---|---|---|
options | 下载选项(buildId 可以是别名或确切版本) 🌐 Download options (buildId may be alias or exact version) |
返回:
Promise<URL | null> | URL | null
下载 URL,如果无法解析版本,则为 null
🌐 Download URL, or null if version cannot be resolved
示例
🌐 Example
// Synchronous example
getDownloadUrl(options) {
const platform = mapPlatform(options.platform);
return new URL(`https://releases.example.com/v${options.buildId}/${platform}.zip`);
}
// Asynchronous example with version mapping
async getDownloadUrl(options) {
const electronVersion = await resolveElectronVersion(options.buildId);
if (!electronVersion) return null;
const platform = mapPlatform(options.platform);
return new URL(`https://github.com/electron/electron/releases/download/v${electronVersion}/${platform}.zip`);
}