fix: use puppeteer node for installation script (#9489)

Fixed: https://github.com/puppeteer/puppeteer/issues/9470
This commit is contained in:
jrandolf 2023-01-11 16:15:53 +01:00 committed by GitHub
parent 29b948197d
commit 9bf90d9f4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 17 deletions

View File

@ -8,8 +8,10 @@ sidebar_label: createBrowserFetcher
```typescript ```typescript
createBrowserFetcher: ( createBrowserFetcher: (
options: Partial< options?:
import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcherOptions | Partial<
> import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcherOptions
>
| undefined
) => import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcher; ) => import('puppeteer-core/internal/puppeteer-core.js').BrowserFetcher;
``` ```

View File

@ -8,15 +8,17 @@ sidebar_label: PuppeteerNode.createBrowserFetcher
```typescript ```typescript
class PuppeteerNode { class PuppeteerNode {
createBrowserFetcher(options: Partial<BrowserFetcherOptions>): BrowserFetcher; createBrowserFetcher(
options?: Partial<BrowserFetcherOptions>
): BrowserFetcher;
} }
``` ```
## Parameters ## Parameters
| Parameter | Type | Description | | Parameter | Type | Description |
| --------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------- | | --------- | ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
| options | Partial&lt;[BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md)&gt; | Set of configurable options to specify the settings of the BrowserFetcher. | | options | Partial&lt;[BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md)&gt; | <i>(Optional)</i> Set of configurable options to specify the settings of the BrowserFetcher. |
**Returns:** **Returns:**

View File

@ -289,7 +289,7 @@ export class PuppeteerNode extends Puppeteer {
* @returns A new BrowserFetcher instance. * @returns A new BrowserFetcher instance.
*/ */
createBrowserFetcher( createBrowserFetcher(
options: Partial<BrowserFetcherOptions> options: Partial<BrowserFetcherOptions> = {}
): BrowserFetcher { ): BrowserFetcher {
const downloadPath = this.defaultDownloadPath; const downloadPath = this.defaultDownloadPath;
if (downloadPath) { if (downloadPath) {
@ -304,6 +304,9 @@ export class PuppeteerNode extends Puppeteer {
if (this.configuration.downloadHost) { if (this.configuration.downloadHost) {
options.host = this.configuration.downloadHost; options.host = this.configuration.downloadHost;
} }
if (this.configuration.defaultProduct) {
options.product = this.configuration.defaultProduct;
}
return new BrowserFetcher(options as BrowserFetcherOptions); return new BrowserFetcher(options as BrowserFetcherOptions);
} }
} }

View File

@ -16,10 +16,9 @@
import https, {RequestOptions} from 'https'; import https, {RequestOptions} from 'https';
import createHttpsProxyAgent, {HttpsProxyAgentOptions} from 'https-proxy-agent'; import createHttpsProxyAgent, {HttpsProxyAgentOptions} from 'https-proxy-agent';
import {join} from 'path';
import ProgressBar from 'progress'; import ProgressBar from 'progress';
import {getProxyForUrl} from 'proxy-from-env'; import {getProxyForUrl} from 'proxy-from-env';
import {BrowserFetcher} from 'puppeteer-core'; import {PuppeteerNode} from 'puppeteer-core/internal/node/PuppeteerNode.js';
import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js'; import {PUPPETEER_REVISIONS} from 'puppeteer-core/internal/revisions.js';
import URL from 'url'; import URL from 'url';
import {getConfiguration} from '../getConfiguration.js'; import {getConfiguration} from '../getConfiguration.js';
@ -42,14 +41,10 @@ export async function downloadBrowser(): Promise<void> {
return; return;
} }
const puppeteer = new PuppeteerNode({configuration, isPuppeteerCore: false});
const product = configuration.defaultProduct!; const product = configuration.defaultProduct!;
const browserFetcher = new BrowserFetcher({ const browserFetcher = puppeteer.createBrowserFetcher();
product,
host: configuration.downloadHost,
path:
configuration.downloadPath ??
join(configuration.cacheDirectory!, product),
});
let revision = configuration.browserRevision; let revision = configuration.browserRevision;