wppconnect-server: WAPI is not defined

Description

error: 2024-05-21T12:03:50.660Z WAPI is not defined - Error: WAPI is not defined

Environment

  • Wppconnect-server version(s): 2.4.4
  • Browser: Chromium 119.0.6045.159 Alpine Linux
  • OS: Ubuntu 22 / Docker container
  • Node version: v20.13.1
  • WhatsApp version: 2.24.9.78
  • MultiDevice (BETA): yes
  • config.json:
import { ServerOptions } from './types/ServerOptions';

export default {
  secretKey: 'THISISMYSECURETOKEN',
  host: 'http://localhost',
  port: '21465',
  deviceName: 'Desktop',
  poweredBy: 'WPPConnect-Server',
  startAllSession: true,
  tokenStoreType: 'file',
  maxListeners: 1000,
  customUserDataDir: './userDataDir/',
  webhook: {
    url: 'http://event_hook***',
    autoDownload: true,
    uploadS3: false,
    readMessage: false,
    allUnreadOnStart: false,
    listenAcks: true,
    onPresenceChanged: false,
    onParticipantsChanged: false,
    onReactionMessage: true,
    onPollResponse: false,
    onRevokedMessage: true,
    onLabelUpdated: false,
    onSelfMessage: true,
    ignore: ['status@broadcast'],
  },
  websocket: {
    autoDownload: false,
    uploadS3: false,
  },
  chatwoot: {
    sendQrCode: true,
    sendStatus: true,
  },
  archive: {
    enable: false,
    waitTime: 10,
    daysToArchive: 45,
  },
  log: {
    level: 'silly', // Before open a issue, change level to silly and retry a action
    logger: ['console', 'file'],
  },
  createOptions: {
    browserArgs: [
      '--disable-web-security',
      '--no-sandbox',
      '--disable-web-security',
      '--aggressive-cache-discard',
      '--disable-cache',
      '--disable-application-cache',
      '--disable-offline-load-stale-cache',
      '--disk-cache-size=0',
      '--disable-background-networking',
      '--disable-default-apps',
      '--disable-extensions',
      '--disable-sync',
      '--disable-translate',
      '--hide-scrollbars',
      '--metrics-recording-only',
      '--mute-audio',
      '--no-first-run',
      '--safebrowsing-disable-auto-update',
      '--ignore-certificate-errors',
      '--ignore-ssl-errors',
      '--ignore-certificate-errors-spki-list',
      '--disable-features=LeakyPeeker',
    ],
    /**
     * Example of configuring the linkPreview generator
     * If you set this to 'null', it will use global servers; however, you have the option to define your own server
     * Clone the repository https://github.com/wppconnect-team/wa-js-api-server and host it on your server with ssl
     *
     * Configure the attribute as follows:
     * linkPreviewApiServers: [ 'https://www.yourserver.com/wa-js-api-server' ]
     */
    linkPreviewApiServers: null,
  },
  mapper: {
    enable: false,
    prefix: 'tagone-',
  },
  db: {
    mongodbDatabase: 'tokens',
    mongodbCollection: '',
    mongodbUser: '',
    mongodbPassword: '',
    mongodbHost: '',
    mongoIsRemote: true,
    mongoURLRemote: '',
    mongodbPort: 27017,
    redisHost: 'localhost',
    redisPort: 6379,
    redisPassword: '',
    redisDb: 0,
    redisPrefix: 'docker',
  },
  aws_s3: {
    region: 'sa-east-1' as any,
    access_key_id: null,
    secret_key: null,
    defaultBucketName: null,
    endpoint: null,
    forcePathStyle: null,
  },
} as unknown as ServerOptions;

Steps to Reproduce

  1. Run the wppconnect-server on VM (GCP)
  2. Start the session
  3. Scan the QR code
  4. QR code is successfully scanned
  5. Connection is initializing, but wppconnect-server logs that WAPI is not found (see the logs) and mobile device does not pairs.

Log Output

info:     [<session_name>:browser] Using browser folder './userDataDir/<session_name>'
info:     [<session_name>:browser] Initializing browser...
http:     [<session_name>:browser] checking headless...
http:     [<session_name>:browser] headless option is active, browser hidden
info:     [<session_name>:client] Initializing...
verbose:  [<session_name>:client] Setting WhatsApp WEB version to 2.2411.x
verbose:  [<session_name>:client] Loading WhatsApp WEB
verbose:  [<session_name>:page] Page loaded
verbose:  [<session_name>:client] Injecting wapi.js
verbose:  [<session_name>:client] WhatsApp WEB loaded
http:     [<session_name>:client] Waiting page load
info:     [<session_name>:session] Session Unpaired
verbose:  [<session_name>:client] wapi.js injected
debug:    [<session_name>:client] Exposing onMessage function
info:     [<session_name>:client] WhatsApp WEB version: 2.2411.2
info:     [<session_name>:client] WA-JS version: 3.2.6
debug:    [<session_name>:client] Exposing onAnyMessage function
debug:    [<session_name>:client] Exposing onAck function
debug:    [<session_name>:client] Exposing onNotificationMessage function
debug:    [<session_name>:client] Exposing onParticipantsChanged function
debug:    [<session_name>:client] Exposing onStateChange function
http:     [<session_name>:client] Checking is logged...
debug:    [<session_name>:client] Exposing onStreamChange function
info:     [<session_name>:client] Auto close configured to 60s
http:     [<session_name>:client] Waiting for QRCode Scan...
info: 2024-05-21T12:03:37.541Z notLogged


debug:    [<session_name>:client] Exposing onIncomingCall function
debug:    [<session_name>:client] Exposing onInterfaceChange function
debug:    [<session_name>:client] Exposing onPresenceChanged function
debug:    [<session_name>:client] Exposing onLiveLocation function
debug:    [<session_name>:client] Exposing onAddedToGroup function
debug:    [<session_name>:client] Exposing onRevokedMessage function
debug:    [<session_name>:client] Exposing onReactionMessage function
debug:    [<session_name>:client] Exposing onPollResponse function
debug:    [<session_name>:client] Exposing onUpdateLabel function
debug:    [<session_name>:client] Exposing onOrderStatusUpdate function
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
info:     [<session_name>:client] Waiting for QRCode Scan (Attempt 1)...:
<QR_CODE>
http:     [<session_name>:client] Auto close remain: 50s
http:     [<session_name>:client] Checking QRCode status...
http:     [<session_name>:client] Login with success
info: 2024-05-21T12:03:49.391Z qrReadSuccess


info:     [<session_name>:client] Auto close configured to 180s
http:     [<session_name>:client] Checking phone is connected...
verbose:  [<session_name>:page] Page loaded
verbose:  [<session_name>:client] Injecting wapi.js
debug:    [<session_name>:client] Registering onStateChange event
error: 2024-05-21T12:03:50.660Z WAPI is not defined - Error: WAPI is not defined
    at /usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:107:31
    at step (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:49:23)
    at Object.next (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:30:53)
    at fulfilled (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:21:58)
JS Stack: ReferenceError: WAPI is not defined
    at pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:56:47
    at pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:56:77
    at new Promise (<anonymous>)
    at anonymous (pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:54:14)
Function: function () { return WAPI.isConnected(); }
debug:    [<session_name>:client] Registering onStateChange event
debug:    [<session_name>:client] Registering onMessage event
debug:    [<session_name>:client] Registering onAnyMessage event
debug:    [<session_name>:client] Registering onIncomingCall event
debug:    [<session_name>:client] Registering onAck event
error: 2024-05-21T12:03:51.216Z WAPI is not defined - Error: WAPI is not defined
    at /usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:107:31
    at step (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:49:23)
    at Object.next (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:30:53)
    at fulfilled (/usr/src/wpp-server/node_modules/@wppconnect-team/wppconnect/dist/api/helpers/evaluate-and-return.js:21:58)
JS Stack: ReferenceError: WAPI is not defined
    at pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:56:47
    at pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:56:77
    at new Promise (<anonymous>)
    at anonymous (pptr:evaluate;%2Fusr%2Fsrc%2Fwpp-server%2Fnode_modules%2F%40wppconnect-team%2Fwppconnect%2Fdist%2Fapi%2Fhelpers%2Fevaluate-and-return.js%3A99%3A56:54:14)
Function: function () { return WAPI.isConnected(); }
verbose:  [<session_name>:client] wapi.js injected
info:     [<session_name>:client] WhatsApp WEB version: 2.2411.2
info:     [<session_name>:client] WA-JS version: 3.2.6
debug:    [<session_name>:client] Emitting onStateChange event (2 registered)
info: 2024-05-21T12:03:52.109Z State Change UNLAUNCHED: <session_name>
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
http:     [<session_name>:client] Waiting page load
http:     [<session_name>:client] Checking is logged...
info:     [<session_name>:client] Auto close configured to 60s
http:     [<session_name>:client] Waiting for QRCode Scan...
info: 2024-05-21T12:03:55.272Z notLogged


debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
debug:    [<session_name>:client] Emitting onStateChange event (2 registered)
info: 2024-05-21T12:03:55.469Z State Change OPENING: <session_name>
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
debug:    [<session_name>:client] Emitting onStateChange event (2 registered)
info: 2024-05-21T12:03:55.846Z State Change PAIRING: <session_name>
debug:    [<session_name>:client] Emitting onInterfaceChange event (1 registered)
http:     [<session_name>:client] Current state: QR (CONNECTING)
debug:    [<session_name>:client] Emitting onStateChange event (2 registered)
info: 2024-05-21T12:03:55.987Z State Change UNPAIRED: <session_name>
info:     [<session_name>:client] Waiting for QRCode Scan (Attempt 1)...:
<QR_CODE>
http:     [<session_name>:client] Auto close remain: 50s
http:     [<session_name>:client] Auto close remain: 40s
http:     [<session_name>:client] Auto close remain: 30s
http:     [<session_name>:client] Auto close remain: 20s
http:     [<session_name>:client] Auto close remain: 10s

Your Code

If relevant, paste all of your challenge code in here

Additional context / Screenshot

Add any other context about the problem here. If applicable, add screenshots to help explain.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 18

Most upvoted comments

Ok. I can’t reproduce the error. I’m checking

Please, do:

Clear folder userdatadir Clear folder tokens Create a new token to session named test (and not <session_name>) Connect and read qrcode Wait 5 minutes with server running Stop and start again

Post here the result.

Hello, thanks for the reply!

Actually the <session_name> is just a placeholder, I’ve replaced it for the privacy reasons. The real name was like 2 chars followed by 4 digits, like xx1234.

We have tried to clean up the userdatadir & tokens dirs multiple time, but the result is the same, it reports that the wapi js is undefined and this is not the only device foe us - we have several which have the same problem.

In any case, we’ll re-tey again based on your instructions & put the logs here.