wppconnect-team / wa-js

WPPConnect/WA-JS is an open-source project with the aim of exporting functions from WhatsApp Web
https://wppconnect.io/wa-js/
Apache License 2.0
418 stars 135 forks source link

TypeError: Cannot read properties of undefined (reading 'm') #2305

Closed ljj314zz closed 4 weeks ago

ljj314zz commented 1 month ago

WA-JS Version

any version

WhatsApp Version

any

Browser Version

any

Operation System

win11

Steps to reproduce

when use in electron,After the script is injected, WPP.version can get the version number, WPP.isinjected is false, and this error will be displayed if other commands are allowed

ErrorevaluateJs: TypeError: Cannot read properties of undefined (reading 'm') I have tried different wajs versions

  app.on("web-contents-created", (_, webContents) => {
    const scriptPath =
      "wppconnect.js";

    const scriptContent = fs.readFileSync(scriptPath, "utf8");

    webContents.on("did-finish-load", () => {
      webContents.executeJavaScript(scriptContent);
    });
}

What is expected?

can get the correct results

What is actually happening?

WPP.chat.list() and any other have no result

Any additional comments?

No response

ljj314zz commented 1 month ago

The line with error is here: t.webpackRequire.m

 function p(e, r=!1) {
                let n = Object.keys(t.webpackRequire.m);
                r && (n = n.reverse());
                const o = setTimeout((()=>{
                    a(`Searching for: ${e.toString()}`)
                }
                ), 500);
                for (const r of n)
                    if (!f(r))
                        try {
                            const n = (0,
                            t.webpackRequire)(r);
                            if (e(n, r))
                                return a(`Module found: ${r} - ${e.toString()}`),
                                clearTimeout(o),
                                r
                        } catch (e) {
                            continue
                        }
ljj314zz commented 1 month ago

It is confirmed that this problem occurs after using electron's WebviewTag to inject the script

window.electronIPCHandlers.onInjWaThread(() => {
const activeWebview =  document.getElementById(
    `webview-${tabStore.selectedTabId}`
  ) as WebviewTag | null;
activeWebview?.executeJavaScript(scriptContent);
}
icleitoncosta commented 4 weeks ago

Hey, this is a mistake in your implementation, it's in our WhatsApp group, there are other people who use electron, we can help you better.

https://chat.whatsapp.com/LJaQu6ZyNvnBPNAVRbX00K