open-wa / wa-automate-nodejs

πŸ’¬ πŸ€– The most reliable tool for chatbots with advanced features. Be sure to 🌟 this repository for updates!
https://docs.openwa.dev/
Other
3.08k stars 592 forks source link

TypeError: mc.processFiles is not a function #2718

Closed gnadelwartz closed 2 years ago

gnadelwartz commented 2 years ago

Are you using the latest version of the library?

What type of session are you experiencing this issue on?

Multi-device and I have set multiDevice to true in my config OR am using the --multi-device flag

What type of host account are you experiencing this issue on?

Personal account (normal)

Mode

My own code

Current Behavior

wa-automate is working as normal, but after first state change and re-pairung/the connection on next Message the follwing error happens:

Error: Evaluation failed: TypeError: mc.processFiles is not a function                                                                                                                            
    at window.WAPI.procFiles (__puppeteer_evaluation_script__:1541:14)                                                                                                                            
    at __puppeteer_evaluation_script__:1439:34                                                                                                                                                    
    at W (https://web.whatsapp.com/bootstrap_qr.791b58dd80835bbaefa8.js:31:99446)                                                                                                                 
    at MutationObserver.B (https://web.whatsapp.com/bootstrap_qr.791b58dd80835bbaefa8.js:31:96023)                                                                                                
    at ExecutionContext._evaluateInternal (/usr/local/telegram/dealwaecho/node_modules/puppeteer/src/common/ExecutionContext.ts:273:13)                                                           
    at processTicksAndRejections (node:internal/process/task_queues:96:5)                                                                                                                         
    at ExecutionContext.evaluate (/usr/local/telegram/dealwaecho/node_modules/puppeteer/src/common/ExecutionContext.ts:140:12)                                                                    

This happend on Version 4.35.13 without updating, but also on newest version. It happen with installed Chromium and newest puppeteer, also.

Expected Behavior

no type error ;-)

Steps To Reproduce

run script and wait for reconnect on state change (plus send picture?)

create() code OR full CLI command + CONFIG

const launchConfig = {
        legacy: true,
        useChrome: false,
        cacheEnabled: false,
        throwErrorOnTosBlock: true,
        disableSpins: true,
        skipUpdateCheck: true,
        //useStealth: true,
        //autoRefresh: true,
        //logConsoleErrors: true,
        //logConsole: true,
        //safeMode: true,
        headless: true,
        multiDevice: true
};

async function start(client) {
   // watch dirs for sending to WA
  chokidar.watch('/..../wabot',
                { ignoreInitial: true }
            // new file
            ).on('add', (file) => {
               [...]
               my_log('******** Forward detected: ' + file + ':' +CHAT +':' + IMAGEURL);
              client.sendImage(CHAT, IMAGEURL.replace(/.*\//, '').replace(/[?&].*/, ''), caption);
              [...]
            });
  // START execute on every new message
  client.onAnyMessage(async message => {
      // here we go ....          
      my_log('=========== new message =================');
      [... save message to file ...]
  });
}

wa.create(launchConfig).then(client => start(client));

DEBUG INFO

{
  "WA_VERSION": "2.2218.7",
  "WA_AUTOMATE_VERSION": "4.36.5",
  "BROWSER_VERSION": "HeadlessChrome/102.0.5002.0",
  "START_TS": 1653221687164,
  "RAM_INFO": "Total: 6.22 GB | Free: 0.48 GB",
  "PPTR_VERSION": "13.7.0",
  "LATEST_VERSION": true,
  "CLI": false,
  "LAUNCH_TIME_MS": 26902,
  "ACC_TYPE": "PERSONAL",
  "chats": 15,
  "messages": 22,
  "contacts": 598,
  "isMd": true,
  "INSTANCE_ID": "ae76499f-b59b-43a6-8ad1-56fa3ea5dd32"
}

Environment

- OS: Linux 5.3
- Node: 16.13.2
- npm: 8.1.2

Screenshots/Logs

22.5.2022, 15:00:02 statechanged OPENING
- session_STARTUP
- Injecting scripts
- Base inject: 139ms
- Injecting scripts
- Launch inject: 179ms
- Base inject: 42ms
22.5.2022, 15:00:03 statechanged PAIRING
22.5.2022, 15:00:03 statechanged CONNECTED
- Injecting scripts
- Injecting scripts
- Base inject: 28ms
- Launch inject: 265ms
- Base inject: 251ms
- Launch inject: 225ms
- Launch inject: 190ms
- Injecting scripts
- Base inject: 44ms
- WAPI inject: 518ms
- Checking session integrity
- Session integrity check passed
- Launch inject: 795ms
22.5.2022, 15:00:50 ******** Forward detected: 1eb5b64804c1c0dc13d0a006bdc4f7d6c3cadde5.lnk:report_haushalt.sh:4915905861477-1626848692@g.us
22.5.2022, 15:00:50 send text:  πŸ›’ KOSMOS 602598 ReBotz - Duke der Skating-Bot, Mini-Roboter zum Bauen, Spielenund Sammeln fΓΌr eine Robo-Gang, Roboter-Spielzeug, Experimentier-Set fΓΌrKinder ab 8 - 12 Jahre | 6,79 € πŸ’Ά | 4.7 *

22.5.2022, 15:00:50 send picture: https://m.media-amazon.com/images/I/51mkCqUF59L._SL500_.jpg
22.5.2022, 15:00:51 done ...
Error: Evaluation failed: TypeError: mc.processFiles is not a function
    at window.WAPI.procFiles (__puppeteer_evaluation_script__:1541:14)
    at __puppeteer_evaluation_script__:1439:34
    at W (https://web.whatsapp.com/bootstrap_qr.791b58dd80835bbaefa8.js:31:99446)
    at MutationObserver.B (https://web.whatsapp.com/bootstrap_qr.791b58dd80835bbaefa8.js:31:96023)
    at ExecutionContext._evaluateInternal (/usr/local/telegram/dealwaecho/node_modules/puppeteer/src/common/ExecutionContext.ts:273:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at ExecutionContext.evaluate (/usr/local/telegram/dealwaecho/node_modules/puppeteer/src/common/ExecutionContext.ts:140:12)

Anything else?

No response

smashah commented 2 years ago

The fact that you can easily read the error means that the patches code has not been injected. Please always share your logs from the start of launch until the error. A lot of context is missing due to truncated logs.

Also, use advanced logging https://github.com/open-wa/wa-automate-nodejs/discussions/2673

gnadelwartz commented 2 years ago

I've added logging options to my code and will share output here ...

gnadelwartz commented 2 years ago

thats what I get with debug enabled. now seems it a diffent error message. Good new is that I can catch the error without with try and think have already found the source of it.

May be the original problem was temporary or is already fixed in patches ...

[[33m┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓^[[39m
^[[33m┃^[[39m                                                                                                   ^[[33m┃^[[39m
^[[33m┃^[[39m   @open-wa/wa-automate                                                                            ^[[33m┃^[[39m
^[[33m┃^[[39m    πŸ’¬ πŸ€– The most reliable NodeJS whatsapp library for chatbots with advanced features.           ^[[33m┃^[[39m
^[[33m┃^[[39m   Version: 4.36.5                                                                                 ^[[33m┃^[[39m
^[[33m┃^[[39m   Check out the latest changes: https://github.com/open-wa/wa-automate-nodejs#latest-changes      ^[[33m┃^[[39m
^[[33m┃^[[39m                                                                                                   ^[[33m┃^[[39m
^[[33m┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛^[[39m
- Starting
- Version: 4.36.5
- Initializing WA
- It is recommended to set useChrome: true or use the --use-chrome flag if you are experiencing issues with Multi device support
- Launching Browser
- MD Enabled, turning off incognito mode.
- Data dir: ./_IGNORE_session
- Browser launched: 579ms
- Setting Up Page
- Loading session data
- Found session data file: /usr/local/telegram/dealwaecho/session.data.json
- multi-device enabled. Session data skipped...
- Existing session data injected
- Pre page launch setup complete: 12ms
- Navigating to WA
- Page loaded in 4872ms: 200
- Page loaded
- Debug info: {
  "WA_VERSION": "2.2218.8",
  "PAGE_UA": "WhatsApp/2.2147.16 Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36",
  "WA_AUTOMATE_VERSION": "4.36.5",
  "BROWSER_VERSION": "HeadlessChrome/102.0.5002.0",
  "OS": "Linux 5.3",
  "START_TS": 1653372545157,
  "RAM_INFO": "Total: 6.22 GB | Free: 0.79 GB",
  "PPTR_VERSION": "13.7.0"
}
- Use this easy pre-filled link to report an issue: https://github.com/open-wa/wa-automate-nodejs/issues/new?template=bug_report.yaml&d_info=%7B%0A%20%20%22WA_VERSION%22:%20%222.2218.8%22,%0A%20%20%22WA_AUTOMATE_VERSION%22:%20%224.36.5%22,%0A%20%20%22BROWSER_VERSION%22:%20%22HeadlessChrome/102.0.5002.0%22,%0A%20%20%22START_TS%22:%201653372545157,%0A%20%20%22RAM_INFO%22:%20%22Total:%206.22%20GB%20%7C%20Free:%200.79%20GB%22,%0A%20%20%22PPTR_VERSION%22:%20%2213.7.0%22,%0A%20%20%22LATEST_VERSION%22:%20true,%0A%20%20%22CLI%22:%20false%0A%7D&enviro=-%20OS:%20Linux%205.3%0A-%20Node:%2016.13.2%0A-%20npm:%208.1.2&labels=MD
- Time to injection: 1193ms
- Injecting api
- Injecting scripts
- Base inject: 24ms
- WAPI inject: 19ms
- Checking session integrity
- Session integrity check passed
- Launch inject: 1176ms
- WAPI injected
- Authenticating
- Authenticated
- Waiting for ripe session...
- Injecting scripts
- Session ready for injection
- Reinjecting api
- Injecting scripts
- Base inject: 305ms
- Base inject: 92ms
- WAPI inject: 484ms
- Checking session integrity
- WAPI inject: 414ms
- Checking session integrity
- Session integrity check passed
- Session integrity check passed
- Launch inject: 728ms
- Launch inject: 1174ms
- WAPI Reinjected
- Checking if session is valid
- Downloading patches from https://cdn.openwa.dev/patches.json
- Client is ready
- Downloaded patches in 0.207s
- Installing patches
- Patches Installed: e3e64
- Client loaded for normal account [MD] with 599 contacts, 15 chats & 15 messages in 26.83s
- Finalizing web session...
- Finalizing client...
^[[31mβ”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”^[[39m
^[[31mβ”‚^[[39m                                                       ^[[31mβ”‚^[[39m
^[[31mβ”‚^[[39m   Use the link below to easily report issues:πŸ‘‡πŸ‘‡πŸ‘‡   ^[[31mβ”‚^[[39m
^[[31mβ”‚^[[39m                                                       ^[[31mβ”‚^[[39m
^[[31mβ””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜^[[39m
- https://github.com/open-wa/wa-automate-nodejs/issues/new?template=bug_report.yaml&d_info=%7B%0A%20%20%22WA_VERSION%22:%20%222.2218.8%22,%0A%20%20%22WA_AUTOMATE_VERSION%22:%20%224.36.5%22,%0A%20%20%22BROWSER_VERSION%22:%20%22HeadlessChrome/102.0.5002.0%22,%0A%20%20%22START_TS%22:%201653372545157,%0A%20%20%22RAM_INFO%22:%20%22Total:%206.22%20GB%20%7C%20Free:%200.79%20GB%22,%0A%20%20%22PPTR_VERSION%22:%20%2213.7.0%22,%0A%20%20%22LATEST_VERSION%22:%20true,%0A%20%20%22CLI%22:%20false,%0A%20%20%22PATCH_HASH%22:%20%22e3e64%22,%0A%20%20%22LAUNCH_TIME_MS%22:%2026830,%0A%20%20%22ACC_TYPE%22:%20%22PERSONAL%22,%0A%20%20%22chats%22:%2015,%0A%20%20%22messages%22:%2015,%0A%20%20%22contacts%22:%20599,%0A%20%20%22isMd%22:%20true,%0A%20%20%22INSTANCE_ID%22:%20%22b60507a6-a23b-49bb-a3e3-c2d5fa93e462%22%0A%7D&enviro=-%20OS:%20Linux%205.3%0A-%20Node:%2016.13.2%0A-%20npm:%208.1.2&labels=MD,PHA
- πŸš€ @OPEN-WA ready for account: 1477

[ ... 2h later! ...]

/usr/local/telegram/dealwaecho/dealwaecho.ts:41
                //'--proxy-server=socks5://localhost:1080', // in case you want a default proxy
                      ^
TypeError: Cannot read properties of undefined (reading 'includes')
    at /usr/local/telegram/dealwaecho/dealwaecho.ts:324:14
    at step (/usr/local/telegram/dealwaecho/dealwaecho.ts:41:23)
    at Object.next (/usr/local/telegram/dealwaecho/dealwaecho.ts:22:53)
    at /usr/local/telegram/dealwaecho/dealwaecho.ts:16:71
    at new Promise (<anonymous>)
    at __awaiter (/usr/local/telegram/dealwaecho/dealwaecho.ts:12:12)
    at /usr/local/telegram/dealwaecho/dealwaecho.ts:262:36
    at Client.<anonymous> (/usr/local/telegram/dealwaecho/node_modules/@open-wa/wa-automate/dist/api/Client.js:697:92)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/telegram/dealwaecho/node_modules/@open-wa/wa-automate/dist/api/Client.js:24:58)
gnadelwartz commented 2 years ago

OK, can confirm "TypeError: mc.processFiles" after reeconnect is gone. Issue will be closed

gnadelwartz commented 2 years ago

a followup question: the second error appears in a chat where I get messages of type chipertext whre message.content is undefined and message.body is empty. seems to be a new feature to have also encrypted message in group chats.

Type: ciphertext Caption: undefined Content: undefined Body:

how to can I get message text in this case?

smashah commented 2 years ago

@gnadelwartz read this:

https://github.com/open-wa/wa-automate-nodejs/issues/2616

gnadelwartz commented 2 years ago

@smashah thank you for pointing out, but this was not the problem. Im my case I had now some starnge behavoir - 3 alone in this issue - and therefore I decided to delete session data and re-join with QR.

An all these stange errors are gone. In multidevice it seems a good idea not only to restart the scrikpt regulary, but also to delete session data once a while...

Cheers Kay