ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# class:browserfetcher ### class: BrowserFetcher v0.9.0 BrowserFetcher 可以用来下载和管理不同版本的 Chromium。 BrowserFetcher 操作一个修订版本字符串,修订版本字符串指定了一个 Chromium 的确定版本,例如 `"533271"`。修订版本字符串可以从 [omahaproxy.appspot.com](http://omahaproxy.appspot.com/) 获取。 看下面这个例子,他将告诉你如何使用 BrowserFetcher 下载一个指定版本的 Chromium: ``` const browserFetcher = puppeteer.createBrowserFetcher();const revisionInfo = await browserFetcher.download('533271');const browser = await puppeteer.launch({executablePath: revisionInfo.executablePath}) ``` > **注意** BrowserFetcher 不适用于与共享下载目录的其他实例同时运行。 #### Methods - [browserFetcher.canDownload(revision)](#?product=Puppeteer&version=v1.11.0&show=api-browserfetchercandownloadrevision)v0.9.0 - [browserFetcher.download(revision\[, progressCallback\])](#?product=Puppeteer&version=v1.11.0&show=api-browserfetcherdownloadrevision-progresscallback)v0.9.0 - [browserFetcher.localRevisions()](#?product=Puppeteer&version=v1.11.0&show=api-browserfetcherlocalrevisions)v0.9.0 - [browserFetcher.platform()](#?product=Puppeteer&version=v1.11.0&show=api-browserfetcherplatform)v0.9.0 - [browserFetcher.remove(revision)](#?product=Puppeteer&version=v1.11.0&show=api-browserfetcherremoverevision)v0.9.0 - [browserFetcher.revisionInfo(revision)](#?product=Puppeteer&version=v1.11.0&show=api-browserfetcherrevisioninforevision)v0.9.0 ### Methods #### browserFetcher.canDownload(revision)v0.9.0 - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 修订版本号, 检查其可用性 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")>> 返回 `true` 如果该修订版本可以从主机下载 该方法将会发起一个 HEAD 请求来检查该修订版本是否有效。 #### browserFetcher.download(revision\[, progressCallback\])v0.9.0 - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 下载的修订版本。 - `progressCallback` <[function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function "Function")([number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"), [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number"))> 一个函数, 调用时将会传入两个参数: - `downloadedBytes` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 多少字节已经被下载 - `totalBytes` <[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Number_type "Number")> 下载全部的字节数(译者注: 也就是需要下载的文件大小) - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")>> Resolves with revision information when the revision is downloaded and extracted - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 该修订版本被创建时的信息 - `folderPath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 解压该修订版本的路径 - `executablePath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 该修订版本的可执行文件的路径 - `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL 该修订版本的下载路径 - `local` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> 该修订版本是否是在本地的磁盘上是可用的 该方法将会发起一个 GET 请求来从主机下载该修订版本。 #### browserFetcher.localRevisions()v0.9.0 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")<[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array "Array")<[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")>>> 一个列表, 包含所有的在本地磁盘可用的修订版本 #### browserFetcher.platform()v0.9.0 - returns: <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 返回 `mac`, `linux`, `win32` 或 `win64` 之一。 #### browserFetcher.remove(revision)v0.9.0 - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 想要移除的修订版本,如果指定的修订版本还没有被下载,该方法将抛出一个错误 - returns: <[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise "Promise")> Resolves when the revision has been removed. #### browserFetcher.revisionInfo(revision)v0.9.0 - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 想要获取信息的修订版本 - returns: <[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object "Object")> - `revision` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 该修订版本被创建时的信息 - `folderPath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 解压该修订版本的路径 - `executablePath` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> 该修订版本的可执行文件的路径 - `url` <[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type "String")> URL 该修订版本的下载路径 - `local` <[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type "Boolean")> 该修订版本是否是在本地的磁盘上是可用的 ![](images/pptr.png) puppeteer.js中文网|class:browserfetcher puppeteer.js中文文档, puppeteer chrome, puppeteer firefox, puppeteer api 中文文档 puppeteer.js中文网包含了Puppeteer中文文档,最新资讯,应用案例等。Puppeteer 是一个 Node 库,它提供了一个高级 API 来通过 DevTools 协议控制 Chromium 或 Chrome。