Puppeteer Change Download Directory

0 views
Skip to first unread message

Elcira Acfalle

unread,
Jan 25, 2024, 4:46:29 AM1/25/24
to dabrapharbai

Starting in v19.0.0, Puppeteer stores browsers in /.cache/puppeteer toglobally cache browsers between installation. This can cause problems ifpuppeteer is packed during some build step and moved to a fresh location. Thefollowing configuration can solve this issue (reinstall puppeteer to takeeffect):

puppeteer change download directory


Download Filehttps://t.co/MmGuaEB4Jp



When you install Puppeteer, it automatically downloads a recent version ofChrome for Testing (170MB macOS, 282MB Linux, 280MB Windows) that is guaranteed toworkwith Puppeteer. The browser is downloaded to the $HOME/.cache/puppeteer folderby default (starting with Puppeteer v19.0.0).

puppeteer is a product for browser automation. When installed, it downloadsa version of Chrome, which it then drives using puppeteer-core. Being anend-user product, puppeteer automates several workflows using reasonabledefaults that can be customized.

puppeteer-core is a library to help drive anything that supports DevToolsprotocol. Being a library, puppeteer-core is fully driven through itsprogrammatic interface implying no defaults are assumed and puppeteer-corewill not download Chrome when installed.

You should use puppeteer-core if you areconnecting to a remote browseror managing browsers yourself.If you are managing browsers yourself, you will need to callpuppeteer.launch withan explicitexecutablePath(or channel if it'sinstalled in a standard location).

So after hours of battling what settings to use I finally got my function to work but now if I change even a single setting, like removing a space, the code starts producing an error after a new build.

My function utilizes puppeteer-core (9.1.1), chrome-aws-lamba (9.1.0), discord.js (12.5.3 had to downgrade to get it to work with node 12). I run esbuild with node_bundler in the netlify.toml to keep it under the 50mb limit. I use NODE_VERSION=12 and AWS_LAMBDA_JS_RUNTIME=nodejs12.x along with the 2 other discord envs in the netlify UI.

Thanks for your patience here. I believe that you are blocked due to your dependencies being outdated. For example, puppeteer is now running on 18.2.1. Here is some documentation outlining puppeteer versions.

Additionally, you will no longer be able to use or depend on node 12. We have announced this change here: Netlify CLI: Dropping support for Node.js version 12. I have shared this feedback with the Docs team so that they are aware you encountered difficulties with this.

In the meanwhile I ended up to temporarily fix this by updating my endpoints to use browserless ( ). Just change your code to connect puppeteer into browserless.io endpoint where puppeteer is running instead of trying to use puppeteer in Netlify.

I was able to find a solution and stay on Netlify. I used the package GitHub - Sparticuz/chromium: Chromium (x86-64) for Serverless Platforms instead of chrome-aws-lambda. This allows me to use the latest version of puppeteer-core and Node 16. Zero issues running this on Netlify so far.

When I was testing everything before I came to my solution I was using esbuild in my netlify.toml and that allowed me to use puppeteer and keep my function under 50mb. That may not be necessary now but specifying that in the netlify.toml did make a difference when it was building the function.
Link to doc Modern, faster Netlify Functions: New bundler and JavaScript features

You may have seen this part above but just in case:
Puppeteer ships with a specific version of chromium.
For example, as of today, the latest version of puppeteer is 18.0.5 . The latest version of chromium stated on puppeteer 's support page is 106.0.5249.0 . So you need to install @sparticuz/chromium@106 .
Source: GitHub - Sparticuz/chromium: Chromium (x86-64) for Serverless Platforms

Today I saw Zevo's Puppeteer Breast Control in the marketplace, I already owned the required purchases so I bought this. I had never really heard of or used Puppeteer before, so I watched the video on the product page. They were clicking on various tabs and getting a live area where they were dragging around and it appeared, making changes on the fly.

all that happens when i start to move the arrows on the puppeteer pane the character morphs back into the base figure,, no matter how many times i tried.. i wish i could get a refund on this, this product is crap...i wont even touch any of your product in the future.. a manual of somesort but nothing.

Here is an example minimal Synthetics Canary script. This script passes as a successful run, and returns a string. To see what a failing canary looks like, change let fail = false; to let fail = true;.

If you have more than a single .js file or you have a dependency that your script depends on, you can bundle them all into a single ZIP file that contains the folder structure nodejs/node_modules/myCanaryFilename.js file and other folders and files. If you are using syn-nodejs-puppeteer-3.4 or later, you can optionally put your canary files in another folder and creating your folder structure like this: nodejs/node_modules/myFolder/myCanaryFilename.js file and other folders and files.

Create and export a handler function. The handler is the entry point function for the script. If you are using a runtime earlier than syn-nodejs-puppeteer-3.4, the handler function must be named handler. If you are using syn-nodejs-puppeteer-3.4 or later, the function can have any name, but it must be the same name that is used in the script. Also, if you are using syn-nodejs-puppeteer-3.4 or later, you can store your scripts under any folder and specify that folder as part of the handler name.

In the AWS Console, manually empty the bucket that was created by the CDK. Look for puppeteer.BucketName in the Outputs section. You can also find the bucket name in the Resources tab of the CloudFormation stack. Then, run the following command after the bucket has been emptied.

The override happens in chrome/app/chrome_main_delegate.cc. Platforms not building with the file may not have implemented the override. Overriding the user data directory via the command line is not supported on iOS.

Chrome Remote Desktop (CRD) used to set $CHROME_USER_DATA_DIR or $CHROME_CONFIG_HOME on the virtual session on a Linux host, since a single Chrome instance cannot show windows on multiple X displays, and two running Chrome instances cannot share the same user data directory. However, with the obsolescence of dbus-x11, most modern Linux distros have lost the ability to simultaneously run multiple graphical sessions for the same user without running into difficult-to-trace dbus cross talk issues, and Chrome can only be run on a single X display per user in reality. Therefore, CRD no longer sets these environment variables for new installations after CRD host M105.

It has multiple options/parameters for use, such as the ability to enable full-page screenshot and to set saving directory, picture encoding, screenshot type, and more. For example, Puppeteer sets the initial page size to 800600 pixels, but you can change it with page.setViewport.

Building websites with the content as a service model, the website appearance continually changes. Puppeteer screenshot can help you create a timeline of visual changes. Alternately, you can easily archive magazines, newspapers, or legal documents.

The solution here is to either move this Chromium download folder to a location that does get persisted (via PUPPETEER_CACHE_DIR environment variable or a puppeteer.config.cjs config file) or persist it yourself via a Netlify build plugin.

Attaches a file to element located by label, name, CSS or XPathPath to file is relative current codecept directory (where codecept.conf.ts or codecept.conf.js is located).File will be uploaded to remote system (if tests are running remotely).

Then I check the existence of chrome.exe in the C:\Windows\TEMP\jsreport\compile\jsreport-2.11.0-SJu_2xpjD\chrome directory, and I found that all files in the directory were disappeared, except for directories, that were empty.
It seems like some task delete all files in C:\Windows\TEMP\jsreport\compile\jsreport-2.11.0-SJu_2xpjD\chrome.
I looked for this error in jsreport forum and I found this topic " -2-7-2-all-locked-up/4", which suggest to change the default temp directory.
Well, I tried to change default temp directory, but only directories "autocleanup" and "core" were moved to new location; instead, "cli" and "compile", that contains chrome directory, remain in the previous temp directory c:\windows\temp\jsreport.
Any suggestion?

Ok, in this way seems that "\compile\jsreport-3.7.1-405f5Qt-s\chrome" directory is properly moved into tempDirectory specified into AppEnvironment variable.
All I can do now is monitoring the pdf report generation feature on our application, hoping that no unknown process can delete chrome content anymore.
Thanks!

9738318194
Reply all
Reply to author
Forward
0 new messages