whatsapp-web.js icon indicating copy to clipboard operation
whatsapp-web.js copied to clipboard

Error: Evaluation failed: N and Error: Evaluation failed: d

Open viniciusgdr opened this issue 2 years ago • 14 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

Describe the bug

Uploading Videos: Error: Evaluation failed: N

Uploading Audios: Error: Evaluation failed: d

at ExecutionContext._evaluateInternal (C:\Users\xxxx\node_modules\whatsapp-web.js\node_modules\puppeteer\src\common\ExecutionContext.ts:273:13) at runMicrotasks ()

I'm trying to send media in formats: videos, audios and I face the problems described above.)

Expected behavior

Waiting for the media to be sent, but the application crashes

Steps to Reproduce the Bug or Issue

  1. Start a Connection
  2. Send a Video or Image

Relevant Code

let media = await MessageMedia.fromUrl('urlvideo', { unsafeMime: true }) await msg.reply(media)

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

SO: Windows 11 Phone OS: Android whatsapp-web.js github branch buttons-fix WA Web Version: 2.2236.10 Node.jS Version: v16.15.0

Additional context

No response

viniciusgdr avatar Oct 04 '22 01:10 viniciusgdr

unstale

viniciusgdr avatar Oct 08 '22 20:10 viniciusgdr

same here

wenked avatar Oct 13 '22 12:10 wenked

I get the same error, maybe there is a solution?

pratamaid avatar Oct 15 '22 06:10 pratamaid

same here

jalescardoso avatar Oct 20 '22 14:10 jalescardoso

unstale

viniciusgdr avatar Oct 25 '22 01:10 viniciusgdr

Same error for me too.

tapan-thapa avatar Oct 25 '22 06:10 tapan-thapa

unstale

viniciusgdr avatar Oct 29 '22 16:10 viniciusgdr

unstale

viniciusgdr avatar Nov 02 '22 18:11 viniciusgdr

unstale

viniciusgdr avatar Nov 09 '22 10:11 viniciusgdr

@viniciusgdr I fixed the issue by checking if the message is video and then uploading it as a document.

let options: WAWebJS.MessageSendOptions = {
      caption: hasBody,
      sendAudioAsVoice: true
    };
    if (media.mimetype.includes("video")) {
      options = {
        caption: hasBody,
        sendAudioAsVoice: true,
        sendMediaAsDocument: true
      };
    }
    const sentMessage = await wbot.sendMessage(
      `${ticket.contact.number}@${ticket.isGroup ? "g" : "c"}.us`,
      newMedia,
      options
    );````

allexxis avatar Apr 24 '23 23:04 allexxis

yep same thing

i can only send as sendMediaDocument = true

and its look ugly

any fix to send as video ?

hmne avatar May 13 '23 14:05 hmne

WhatsApp is capricious about video. Go to the official site and check whether your video is suitable or not

tofers avatar May 13 '23 15:05 tofers

I solve it without looking ugly by not using pupeteer defaults : You need to set this env variable PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true And install chrome into your server/pc manually. This is my example using docker

RUN apt-get update \
    && apt-get install -y wget gnupg \
    && wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' \
    && apt-get update \
    && apt-get install -y google-chrome-stable fonts-ipafont-gothic fonts-wqy-zenhei fonts-thai-tlwg fonts-kacst fonts-freefont-ttf libxss1 \
      --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENV CHROME_BIN=google-chrome-stable

Then on whatsappjs

const wbot: Session = new Client({
        session: sessionCfg,
        authStrategy: new LocalAuth({ clientId: `bd_${whatsapp.id}` }),
        puppeteer: {
          executablePath: process.env.CHROME_BIN || undefined,
          browserWSEndpoint: process.env.CHROME_WS || undefined,
          args: args.split(" ")
        }
      });

This works beacuse chrome is able to send video format as requested by whatsapp and chromium will not.

allexxis avatar May 14 '23 16:05 allexxis

this did not work withe my project

const client = new Client({ puppeteer: { executablePath: process.env.CHROME_BIN || undefined, browserWSEndpoint: process.env.CHROME_WS || undefined, args: ["--no-sandbox"] }, authStrategy: new LocalAuth({ clientId: bd_${undefined}`, dataPath: constants.sessionPath}) });

`

hmne avatar May 18 '23 17:05 hmne

Same error for me too.

GeorgesdaSilva avatar Jul 21 '23 15:07 GeorgesdaSilva

What size you media is, and what kind?

shirser121 avatar Aug 04 '23 14:08 shirser121

You fix this by using chrome instead of pupeteer default chromium

allexxis avatar Aug 04 '23 15:08 allexxis

i am still facing this issue:

Error during sending message: Error: Evaluation failed: N 1|index | at ExecutionContext._evaluateInternal (//node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)

s4suryapal avatar Feb 22 '24 13:02 s4suryapal

i am still facing this issue:

Error during sending message: Error: Evaluation failed: N 1|index | at ExecutionContext._evaluateInternal (//node_modules/puppeteer/lib/cjs/puppeteer/common/ExecutionContext.js:221:19)

I managed to solve this, besides passing the chrome path to puppeter:

new Client({
    authStrategy: new LocalAuth(),
    webVersionCache: {
        type: "remote",
        remotePath: 'https://raw.githubusercontent.com/wppconnect-team/wa-version/main/html/2.2332.15.html',
    },
    puppeteer: {
        executablePath: '/usr/bin/google-chrome-stable',
        args: ['--no-sandbox', '--disable-setuid-sandbox'],
        headless: true
    }
})

But also converting the video to mp4 with ffmpeg (Sometimes even though the video was already in .mp4 it gave the error, so when using ffmpeg it works):

const { exec } = require("child_process")

exec(`ffmpeg -i ${filePath} -preset superfast -crf 30 -c:v libx264 ${newPath}`, (err, stdout, stderr) => {
                if(err){
                    console.log(`convert video error: ${err}`)
                    return resolve(null)

                }else{
                    console.log(`convert video success`)
                    return resolve(newPath)

                }
            })

And then I send the video like this: message.reply(MessageMedia.fromFilePath(newPath))

Bestfastfire avatar Feb 22 '24 13:02 Bestfastfire

I am already using that :

const store = new MongoStore({ mongoose: mongoose });
        let browser_path = '/usr/bin/google-chrome-stable'; // for Linux
        if (process.env.NODE_ENV !== 'production') {
            browser_path = '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; // for Mac OS
        }
        const client = new Client({
            authStrategy: new LocalAuth({
                store: store,
                backupSyncIntervalMs: 300000
            }),
            puppeteer: {
                executablePath: browser_path,
                headless: true,
                args: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-extensions']
            },
            restartOnAuthFail: true
        });

s4suryapal avatar Feb 22 '24 13:02 s4suryapal

I'm encountering an issue while attempting to send a video file using whatsapp-web.js with a CDN URL such as []("https://download.ig-10-data.xyz/ig/1709204866/a5e9ee198d0c2b9f241f65c88ccb596be76a6e120e31114e5a354773a75a77b7?file=aHR0cHM6Ly9zY29udGVudC5jZG5pbnN0YWdyYW0uY29tL3YvdDY2LjMwMTAwLTE2LzEwMDAwMDAwXzkyNTQxNjA1NTgxNjA2N18zNzE0MjE2ODYxOTEyNzc1NTE0X24ubXA0P19uY19odD1zY29udGVudC1mcmEzLTIuY2RuaW5zdGFncmFtLmNvbSZfbmNfY2F0PTExMSZfbmNfb2hjPTdja3FnQ0hQX29nQVgtUVcwSHkmZWRtPUFQX1YxMEVCQUFBQSZjY2I9Ny01Jm9oPTAwX0FmQzNKbzduZ3ItN1ZwQmdQazU4LVJEQ28zTU9WQndIRTRLZFg3SlBOdWlkZ1Emb2U9NjVFMjBEOTYmX25jX3NpZD0yOTk5YjgmbmFtZT1TYXZlSUcuQXBwXzMyNzg1ODkzMDAyNDAwNTUwMTIubXA0". When using this URL, I receive an error message: "Error during sending video: Error: Evaluation failed: N".)

Additional Context:

The issue does not occur when sending small video files using other URLs, such as "https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.mp4". I have attempted various approaches to resolve the issue, including using buffer-based methods as mentioned in the whatsapp-web.js documentation, but the problem persists specifically with CDN URLs. Any insights or suggestions on how to resolve this issue would be greatly appreciated. Thank you!

s4suryapal avatar Feb 29 '24 10:02 s4suryapal

@pedroslopez @PurpShell please help

s4suryapal avatar Feb 29 '24 10:02 s4suryapal

Just send the video in .mov format

const media = new MessageMedia('video/mov', b64data, title);

jr-gomes avatar Jun 06 '24 20:06 jr-gomes