How to use the createBrowserFetcher function from puppeteer
Find comprehensive JavaScript puppeteer.createBrowserFetcher code examples handpicked from public code repositorys.
The puppeteer.createBrowserFetcher method creates a new instance of a browser fetcher that can download and manage different versions of Chromium or other supported browsers.
GitHub: browserless/chrome
72 73 74 75 76 77 78 79 80 81 82 83
const PUPPETEER_BINARY_LOCATION = (() => { if (PLATFORM === LINUX_ARM64) { return playwright.chromium.executablePath(); } const browserFetcher = puppeteer.createBrowserFetcher({ product: 'chrome' }); return browserFetcher.revisionInfo(PUPPETEER_CHROMIUM_REVISION) .executablePath; })();
GitHub: PolyBoen/CodeForGpt
812 813 814 815 816 817 818 819 820 821
browserName === "chrome" ? revisions.chromium : revisions.firefox; // Remove other revisions than the one we want to use. Updating Puppeteer can // cause a new revision to be used, and not removing older revisions causes // the disk to fill up. const browserFetcher = puppeteer.createBrowserFetcher({ product: browserName, }); const localRevisions = await browserFetcher.localRevisions(); if (localRevisions.length > 1) {
+ 16 other calls in file
How does puppeteer.createBrowserFetcher work?
puppeteer.createBrowserFetcher is a method that creates an instance of a browser fetcher which is responsible for downloading and managing different versions of Chromium or other supported browsers that Puppeteer can use. When you call this method, it returns a new instance of BrowserFetcher class. Once you have a BrowserFetcher instance, you can call its methods to download and install a specific version of Chromium or other supported browsers. If the requested version is not available locally, the fetcher will download the corresponding revision of the browser from the internet and store it in a local cache. The createBrowserFetcher method accepts an optional configuration object as its argument. This object can contain the following properties: path: A string specifying the path to the directory where the fetcher should store downloaded browsers. If not specified, a default directory will be used. host: A string specifying the URL of the host where the fetcher should download browsers from. If not specified, a default URL will be used. platform: A string specifying the platform of the host where the fetcher should download browsers from. If not specified, the current platform will be used. Once you have a BrowserFetcher instance, you can call its methods to manage browser installations. For example, you can call the canDownload method to check if a specific browser revision is available for download, and the download method to download a specific browser revision. Overall, puppeteer.createBrowserFetcher provides a simple and convenient way to manage different versions of Chromium or other supported browsers that Puppeteer can use.
17 18 19 20 21 22 23 24 25 26 27 28
const assert = require('assert'); const puppeteer = require('puppeteer'); const https = require('https'); const SUPPORTER_PLATFORMS = ['linux', 'mac', 'win32', 'win64']; const fetchers = SUPPORTER_PLATFORMS.map(platform => puppeteer.createBrowserFetcher({platform})); const colors = { reset: '\x1b[0m', red: '\x1b[31m',
41 42 43 44 45 46 47 48 49 50 51 52
await page.goto(url); })(); async function downloadChrome(revision) { const fetcher = puppeteer.createBrowserFetcher(); let progressBar = null; let lastDownloadedBytes = 0; return await fetcher.download(revision, (downloadedBytes, totalBytes) => { if (!progressBar) {
Ai Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
const puppeteer = require("puppeteer"); const browserFetcher = puppeteer.createBrowserFetcher(); const revision = "912860"; browserFetcher .download(revision) .then(() => { const browserPath = browserFetcher.revisionInfo(revision).executablePath; console.log(`Chromium downloaded to ${browserPath}`); }) .catch((error) => { console.error(`Failed to download Chromium: ${error}`); });
In this example, createBrowserFetcher is used to create a new instance of BrowserFetcher. download is then called on the instance to download the Chromium browser executable for a specific revision. Once the download is complete, executablePath can be obtained by calling revisionInfo on the BrowserFetcher instance.
6978 6979 6980 6981 6982 6983 6984 6985 6986 6987
// ignoreDefaultArgs: ['--disable-extensions'], // headless: true, // args: ['--no-sandbox', "--disabled-setupid-sandbox"] // }); const browserFetcher = puppeteer.createBrowserFetcher(); let revisionInfo = await browserFetcher.download('1095492'); const browser = await puppeteer.launch({ executablePath: revisionInfo.executablePath,
32 33 34 35 36 37 38 39 40 41 42
/*PROCEDIMENTOS*/ const { read_waiting_file } = require("./src/procedures/p_read_waiting_file"); //fucnao com auto-execucao (async () => { await vanillaPuppeteer.createBrowserFetcher().download(vanillaPuppeteer.PUPPETEER_REVISIONS.chromium) //instancia o puppeteer const puppeteer = addExtra(vanillaPuppeteer); puppeteer.use(Stealth()); //instancia o navegador
puppeteer.launch is the most popular function in puppeteer (5121 examples)