Puppeteer is experiencing a hanging issue on Raspberry Pi Zero due to a timeout being exceeded

I am encountering difficulties with running puppeteer on my Raspberry Pi Zero, following the steps outlined in this tutorial.

Here is what I have attempted so far:

$ sudo apt-get install chromium-browser chromium-codecs-ffmpeg --yes

$ npm init -Y
$ npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6f1f1a1f1f0a1b0a0a1d420c001d0a2f5e415e5e415f">[email protected]</a>

I also tried installing without specifying the core version (1.11.0) but encountered the same issues.

This is my index.js file:

const puppeteer = require('puppeteer-core');

(async () => {
    try {
        const browser = await puppeteer.launch({ executablePath: 'chromium-browser', headless: true, product: 'chrome' });
        const page = await browser.newPage();
        page.setDefaultNavigationTimeout(25 * 1000);
        await page.goto('https://www.google.com/');
        await page.screenshot({ path: 'screenshot.png' });

        await browser.close();
        console.log('Screenshot taken');
    } catch (e) {
        console.log(e.message);
    }
})();

When I run it, I encounter a timeout error:

$ node index.js
Navigation Timeout Exceeded: 25000ms exceeded

It simply hangs and doesn't exit.

Any assistance would be greatly appreciated. Thank you.

Answer №1

If you're encountering slow performance on your Raspberry Pi, here are some tips that might help improve the speed:

Ensure that your RPi has reliable internet connectivity with a timeout limit of 25 seconds by using

page.setDefaultNavigationTimeout(25 * 1000);
. You can test latency with the ping google.com command.

Considering the specs of an RPi Zero (1GHz processor, 512MB RAM), both hardware and OS play a role in performance. Operations like opening a headless browser, taking a snapshot, and saving it to a file all require time. Timing these operations individually can give insight into where time is spent.

Tests conducted on different machines showed varying speeds - around 4 seconds on a Core i5 machine with 8 GB RAM and ~9 seconds in a video tutorial.

A simple solution could be increasing the timeout value. Additionally, hosting a static webpage on a local Apache Server and testing locally without internet can reduce latency. Adjusting the timeout may be necessary in this scenario. Python's SimpleHTTPServer can also be used instead of Apache.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Guide on how to beautify HTML and generate output files in the identical directory as the current one

Hey there! I'm currently working as a junior front-end developer and have recently delved into using gulp. One of the challenges I face is dealing with HTML files received from senior developers that aren't well-formatted, containing excessive wh ...

Uncovering the xpath of an element within an iframe using QTP

When attempting to set a value in the <input type="file" name="file007"> element using QTP, I encountered an issue. The element is located within an iframe, making it inaccessible through xpath on the page. <iframe id="file_007" src="javascript:& ...

Navigating through a sequence of URLs in Node.js, one by one

I am new to node js and experimenting with creating a web scraping script. I've received permission from the site admin to scrape their products as long as I make less than 15 requests per minute. Initially, my script was requesting all URLs at once, ...

Modify variables in the child function to be utilized in the parent function

I need to create a scenario where a variable defined in a parent function is modified within a child function and then returned back to the parent as an updated variable. Here is the code I have attempted: let value = 20; console.log(value); // Output: ...

Retrieve a JSON object from a Knockout observable array using the object's ID

I'm struggling to find examples of ko.observablearrays that deal with complex JSON objects instead of simple strings. I have an observable array containing a large JSON object with several properties, and I need to retrieve a specific object based on ...

I find myself unable to write any code using my Visual Studio Code

I'm facing an issue where I can't write any code on my Visual Studio Code. Despite following all the recommendations on the official website, I haven't been able to resolve the problem. More information here Here are the changes I have tri ...

Moving punctuation from the beginning or middle of a string to the end: A guide

My Pig Latin converter works well with single or multi-word strings, but it struggles with punctuation marks. For example, when I input translatePigLatin("Pig Latin.");, the output is 'Igpay Atin.lay' instead of 'Igpay Atinlay.'. How c ...

Guide to converting JSON data into object structures

Question - How do I convert JSON data into objects? You can find the JSON data here Details - After successfully connecting to the API and retrieving the JSON data, I am looking to map two arrays data.hourly.time[] and data.hourly.temperature_2m[] into a ...

Understanding the res.render method in JavaScript can be a bit tricky at first

In my spare time, I have been immersing myself in coding lessons and have encountered some puzzling aspects of the code: Firstly, there is a confusion surrounding the action attribute in HTML Secondly, this particular piece of code is causing me some b ...

Synchronously read a file in Node.js and return its contents as a string instead of a buffer

I need assistance with reading a file in Node.js as a string rather than a buffer. I am developing a program in Node.js and encountering an issue when attempting to read a file synchronously. The problem is that the file is returned as a buffer, not a stri ...

Learn the steps to successfully select a drop-down option by clicking on a button

Below is the HTML code for my select options: <select id="font"> <option value="School">School</option> <option value="'Ubuntu Mono'">SansitaOne</option> <option value="Tangerine">Tange ...

A guide on implementing typescript modules within a Node.js environment

It may sound trivial, but unfortunately I am struggling to utilize a Typescript module called device-detector-js in my Node.js project. I have searched the web for solutions on "How to use typescript modules in Node.js", but all I find is tutorials on "Bu ...

Navigating to the specific item that a directive is linked to

I am looking to develop a directive that can be applied to elements to adjust their maximum height to be equal to the height of the window minus the distance from the top of the element to the top of the window. I have attempted it in the following manner ...

Unable to retrieve the selected name in the controller

Forgive me for this, but I am still learning angularjs. I am facing an issue with a select control that is populated using the following code: <select ng-model="limit" data-ng-options="listLimit.name for listLimit in listLimits" data-ng-change="limitC ...

Adjusting the React Material UI TextField behavior upon a change in value while maintaining the

I have an MUI TextField component that I would like to trigger a function when it changes, while still allowing it to function as usual (without being a controlled input). <TextField onChange={(e)=>{ doSomething(e.target.value) //perhaps call ...

Is there a performance boost when using queue() and filter() together in jQuery?

I'm currently refactoring some Jquery code and I've heard that chaining can improve performance. Question: Does this also apply to chains involving queue() and filter()? For instance, here is the un-chained version: var self = this, co = ...

Error in Compiling HTML Elements Collection<<Element>

Currently, I am developing an eCommerce application that features a popup window for users when they click on "Add to Cart." This popup allows users to select product variations and quantities before adding the item to their cart. The popup consists of a s ...

Prevent variable declaration using try-catch blocks

I am currently working on a code that aims to retrieve a path value from an XML file. If the path is not found, I want to set it to blank. Interestingly, I encounter errors when I use try/catch blocks, stating that the "path" cannot be found. However, whe ...

Creating a row of aligned card components in React

Recently, I began learning React and successfully created a card component using Material UI. However, this time around, I'm attempting to create it using axios and map() methods. I expected the cards to be displayed in the same row horizontally, not ...

Why isn't the jQuery click() function functioning on my modified HTML?

I am trying to create a unique version of the go-moku game using different programming languages and databases. My aim is to enhance the game's functionality by incorporating jQuery, PHP, and a MySQL database. var moveCount = -1; setInterval(function ...