Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wapi inject directly on whatsapp web does not work again #2795

Open
josephMblT opened this issue Aug 6, 2024 · 8 comments
Open

Wapi inject directly on whatsapp web does not work again #2795

josephMblT opened this issue Aug 6, 2024 · 8 comments
Labels
bug Something isn't working needs triage Needs avaliation

Comments

@josephMblT
Copy link

##Issue
Before, I used to inject the WAPI script directly into WhatsApp Web and could successfully get messages and create listeners. However, now when I try to retrieve all contacts or perform similar operations, it fails, and I notice that the Store object is always empty. I’m unsure if others have encountered this issue. While creating a new client with a Node.js server works, my use case requires running it directly on WhatsApp Web. Can you provide any insights or solutions for this problem?

i do this by running the bundle Wapi

i get and error here

Code

(async()=>{
        if (window.__debug)
            await A(),
            m();
        else {
            await A();
            const e = window[o.webpack].length - 1;
            !window[o.webpack][e][0].includes(o.parasite) && document.querySelectorAll("#app .two").length && m()
        }
    }

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading '0')

when i try getting all contacts

WAPI.getAllContacts();
VM2465:1 Uncaught TypeError: Cannot read properties of undefined (reading 'map')
at window.WAPI.window.WAPI.getAllContacts (:1:86008)

what i this is happening

function injectParasite() {
if (window.__debug) {
getStore(window.getModuleList()).finally();
} else {
if (
window.webpackChunkwhatsapp_web_client &&
Array.isArray(window.webpackChunkwhatsapp_web_client)
) {
const parasite = injectConfig.parasite;
window[injectConfig.webpack].push([
[parasite],
{},
async function (o) {
let modules = [];
for (let idx in o.m) {
modules.push(o(idx));
}
await getStore(modules);
}
]);
}
}
}

I try tracing the code and I noticed that

this inject parasite is been set and i don't think it is ever been called because from what I see when its been call, the Store is been populated

Please I really need help in this,

you can try by running
yarn build:wapi

copy the code in the dist/lib/wapi/wapi.js and paste on the whatsapp web console and press Enter and try any WAPI function, none will work

@josephMblT josephMblT added bug Something isn't working needs triage Needs avaliation labels Aug 6, 2024
@ghayman
Copy link
Collaborator

ghayman commented Aug 6, 2024

Can you install the code from Github orkestral/master directly?

There was a big update to WhatsApp a couple of months ago that totally broke the WAPI insertion and Store item generation.

A new method has been devised but has not been officially release yet - so if you can try master branch here, let us know how you get on

@josephMblT
Copy link
Author

Hi @ghayman, normally if i create a node server and I install it as a dependency, it work well, my use case is am using an electron application and i need to inject the venom as a preload script into the webview.

@Aetiru
Copy link

Aetiru commented Aug 8, 2024

Hi @ghayman, I am currently needing the same thing you mentioned, I thought about extracting the WhatsApp session this way

const sessionData = await view1.webContents.executeJavaScript(new Promise((resolve, reject) => { var request = window.indexedDB.open("wawc"); request.onsuccess = function() { var db = request.result; var transaction = db.transaction(["user"], "readonly"); var objectStore = transaction.objectStore("user"); var getAllRequest = objectStore.getAll(); getAllRequest.onsuccess = function() { resolve(getAllRequest.result); }; getAllRequest.onerror = function() { reject(getAllRequest.error); }; }; request.onerror = function() { reject(request.error); }; }););

And then inject it into venom but I don't know if it's possible

@ghayman
Copy link
Collaborator

ghayman commented Aug 9, 2024

I'm not really familiar with how to use this with Electron.
Does it use Chrome/Chromium browser?

Look at the latest code in master branch to see how this now does the code injection
https://github.com/orkestral/venom/blob/master/src/api/whatsapp.ts : initService()

@josephMblT
Copy link
Author

thanks for the above response,
currently if am running with puppeteer, it appears that with puppeteer, wapi works well, am still trying to find out why it is not working when i code the webpack bundle of wapi and paste on the console it does not work.

am trying to figure out how the puppeteer Store gets populated

@josephMblT
Copy link
Author

` await this.page.evaluate(() => {
window['__debug'] = eval("require('__debug');");
console.log({code:window['__debug']});

  });`
  
  
  please i was able to trace the code and i know where my problem is coming from, please this
  `require('__debug` i need to know were it is coming from, so i can inject it to my script,

@ghayman
Copy link
Collaborator

ghayman commented Aug 13, 2024

__debug is the module that allows to access all the WhatsApp modules. (NOTE: webpack no longer exists due to WhatsApp changes - there is some backwards compatible code still in there to help when web.whatsapp.com updates in the browser)

It should be established before you try and inject wapi.js - here is venom code location
src/api/whatsapp.ts: line 51

On line 60 you can see venom injecting wapi.js

@josephMblT
Copy link
Author

@ghayman thanks for your help, i was able to have venom working as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage Needs avaliation
Projects
None yet
Development

No branches or pull requests

3 participants