mukulhase / WebWhatsapp-Wrapper

An API for sending and receiving messages over web.whatsapp [Working as of 18th May 2018]
https://webwhatsapi.readthedocs.io/en/latest/
MIT License
2.03k stars 797 forks source link

[URGENT] Browser script insertion issue #898

Open ShethBeerud opened 4 years ago

ShethBeerud commented 4 years ago

I'm having trouble getting messages.

I'm doing a test with 3 contacts (A, B and C).

Contact A is integrated and is receiving messages from B and C. Contact B already has a conversation with contact A and when sending messages to him the message arrives and it is possible to get it with the function WAPI.getUnreadMessages (). Contact C never sent messages to contact A and when calling the WAPI.getUnreadMessages () function an empty array is returned.

Using a visual tool I notice that when contact B talks to A the page changes and the new message is displayed normally, however when contact C talks to contact A the page remains unchanged.

I'm suspecting that WhatsApp is detecting the script and blocking it, as it's still possible to send messages, but not receive them.

Help me please.

g4w4 commented 4 years ago

I ran into this same problem after applying the solutions in other threads. In the end I solved it by removing the "precense" element from the "store", thus leaving my code in wapi.js

if (!window.Store) { (function () { function getStore(modules) { let foundCount = 0; let neededObjects = [ { id: "Store", conditions: (module) => (module.default && module.default.Chat && module.default.Msg) ? module.default : null}, { id: "MediaCollection", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.processAttachments) ? module.default : null }, { id: "MediaProcess", conditions: (module) => (module.BLOB) ? module : null }, { id: "Wap", conditions: (module) => (module.createGroup) ? module : null }, { id: "ServiceWorker", conditions: (module) => (module.default && module.default.killServiceWorker) ? module : null }, //{ id: 'Presence', conditions: (value) => (value.default && value.default.Presence) ? value.default : null }, { id: "State", conditions: (module) => (module.STATE && module.STREAM) ? module : null }, { id: "WapDelete", conditions: (module) => (module.sendConversationDelete && module.sendConversationDelete.length == 2) ? module : null }, { id: "Conn", conditions: (module) => (module.default && module.default.ref && module.default.refTTL) ? module.default : null }, { id: "WapQuery", conditions: (module) => (module.queryExist) ? module : ((module.default && module.default.queryExist) ? module.default : null) }, { id: "CryptoLib", conditions: (module) => (module.decryptE2EMedia) ? module : null }, { id: "OpenChat", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.openChat) ? module.default : null }, { id: "UserConstructor", conditions: (module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null }, { id: "SendTextMsgToChat", conditions: (module) => (module.sendTextMsgToChat) ? module.sendTextMsgToChat : null }, { id: "SendSeen", conditions: (module) => (module.sendSeen) ? module.sendSeen : null }, { id: "sendDelete", conditions: (module) => (module.sendDelete) ? module.sendDelete : null } ]; for (let idx in modules) { if ((typeof modules[idx] === "object") && (modules[idx] !== null)) { let first = Object.values(modules[idx])[0]; if ((typeof first === "object") && (first.exports)) { for (let idx2 in modules[idx]) { let module = modules(idx2); if (!module) { continue; } neededObjects.forEach((needObj) => { if (!needObj.conditions || needObj.foundedModule) return; let neededModule = needObj.conditions(module); if (neededModule !== null) { foundCount++; needObj.foundedModule = neededModule; } }); if (foundCount == neededObjects.length) { break; } } let neededStore = neededObjects.find((needObj) => needObj.id === "Store"); window.Store = neededStore.foundedModule ? neededStore.foundedModule : {}; neededObjects.splice(neededObjects.indexOf(neededStore), 1); neededObjects.forEach((needObj) => { console.log(window.Store[needObj.id] ? true : false, needObj.id) if (needObj.foundedModule) { window.Store[needObj.id] = needObj.foundedModule; } }); window.Store.sendMessage = function (e) { return window.Store.SendTextMsgToChat(this, ...arguments); }; return window.Store; } } } if (window.Store.Presence) { for (const prop in window.Store.Presence) { if (prop === "Presence") { continue; } window.Store[prop] = window.Store.Presence[prop] || window.Store[prop]; } } } if (typeof webpackJsonp === 'function') { webpackJsonp([], {'parasite': (x, y, z) => getStore(z)}, ['parasite']); } else { webpackJsonp.push([ ['parasite'], { parasite: function (o, e, t) { getStore(t); } }, [['parasite']] ]); } })(); }

erm3nda commented 3 years ago

@g4w4 Does this removal affect other parts of the code?? What if you need the presence for other things?