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

Farewell, Webpack! Re-injection, Pairing Code login, and 2.24x jumbofix #2816

Open
wants to merge 35 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c1ae300
fix(webpack-exodus): Added the new patch
PurpShell Mar 14, 2024
db72385
fix(webpack-exodus): Fixed v2.3000.x and v2.24
PurpShell Apr 3, 2024
24196db
chore(webpack-exodus): eslint
PurpShell Apr 3, 2024
f001408
Merge branch 'main' into webpack-exodus
PurpShell Apr 3, 2024
eda1920
fix(webpack-exodus): Fixed Store
PurpShell Apr 3, 2024
467f6d2
Merge branch 'webpack-exodus' of https://github.com/pedroslopez/whats…
PurpShell Apr 3, 2024
21904ef
fix(webpack-exodus): slight store fix
PurpShell Apr 3, 2024
5969892
chore(webpack-exodus): fix example so that I don't crash on every load
PurpShell Apr 3, 2024
1df7e4f
chore: eslint fix
alechkos Apr 3, 2024
77f9c18
fix(webpack-exodus): prevent confusion with build systems
PurpShell Apr 3, 2024
75623c8
Merge branch 'webpack-exodus' of https://github.com/pedroslopez/whats…
PurpShell Apr 3, 2024
5b1e911
fix(webpack-exodus): Add proper groups module
PurpShell Apr 3, 2024
78dc055
fix(webpack-exodus): Fix order queries
PurpShell Apr 3, 2024
269e44e
fix(webpack-exodus): Bad export name
PurpShell Apr 9, 2024
85db3d2
feat(webpack-exodus): Re-injection, No more selectors, Pairing Code auth
PurpShell Apr 14, 2024
27621f1
fix(webpack-exodus): Eslint and better login/logout handling
PurpShell Apr 14, 2024
dd75967
fix(webpack-exodus): 2.24 compatibility
PurpShell Apr 14, 2024
e7ae65f
revert testing options
PurpShell Apr 14, 2024
cad33ec
chore(webpack-exodus): ESLint
PurpShell Apr 14, 2024
452b712
chore(webpack-exodus): final eslint tweak (did not commit with last c…
PurpShell Apr 14, 2024
b347aa6
Merge branch 'main' into webpack-exodus
alechkos Apr 22, 2024
fac0d81
style: fix broken link in readme file
alechkos Apr 22, 2024
53672d0
Merge branch 'main' into webpack-exodus
alechkos Apr 27, 2024
c1d8e04
fix(webpack-exodus): Fix forwarding messages
PurpShell Apr 28, 2024
86d5dc4
Merge branch 'webpack-exodus' of https://github.com/pedroslopez/whats…
PurpShell Apr 28, 2024
650cd0d
fix(webpack-exodus): finish forwarding function
PurpShell Apr 28, 2024
64491be
Making the ESLint god happy
tuyuribr May 14, 2024
975819d
Fix window.Store.ProfilePic.profilePicFind is not a function error (#…
seowzhenjun0126 May 14, 2024
e4c208c
Sanitize, improves and fixes
tuyuribr May 15, 2024
252ed8f
make ESList god happy
tuyuribr May 15, 2024
2798396
fix getInviteCode for group (#3007) (#3029)
themazim May 15, 2024
6df4eef
fixes
tuyuribr May 16, 2024
1ecdc42
Update LocalWebCache.js
tuyuribr May 21, 2024
96b4742
fix delete on 2.3000 (#3048)
jrocha May 24, 2024
bbb8d18
Implement bot invoking capabilities (#3009)
MatMercer May 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ module.exports = {
NoAuth: require('./src/authStrategies/NoAuth'),
LocalAuth: require('./src/authStrategies/LocalAuth'),
RemoteAuth: require('./src/authStrategies/RemoteAuth'),
LegacySessionAuth: require('./src/authStrategies/LegacySessionAuth'),

...Constants
};
58 changes: 30 additions & 28 deletions src/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ const moduleRaid = require('@pedroslopez/moduleraid/moduleraid');
const Util = require('./util/Util');
const InterfaceController = require('./util/InterfaceController');
const { WhatsWebURL, DefaultOptions, Events, WAState } = require('./util/Constants');
const { ExposeStore, LoadUtils } = require('./util/Injected');
const { ExposeStore } = require('./util/Injected/Store');
const { LoadUtils } = require('./util/Injected/Utils');
const { ExposeLegacyStore } = require('./util/Injected/LegacyStore');
const ChatFactory = require('./factories/ChatFactory');
const ContactFactory = require('./factories/ContactFactory');
const WebCacheFactory = require('./webCache/WebCacheFactory');
const { ClientInfo, Message, MessageMedia, Contact, Location, Poll, GroupNotification, Label, Call, Buttons, List, Reaction } = require('./structures');
const LegacySessionAuth = require('./authStrategies/LegacySessionAuth');
const NoAuth = require('./authStrategies/NoAuth');

/**
Expand Down Expand Up @@ -62,20 +63,7 @@ class Client extends EventEmitter {
this.options = Util.mergeDefault(DefaultOptions, options);

if(!this.options.authStrategy) {
if(Object.prototype.hasOwnProperty.call(this.options, 'session')) {
process.emitWarning(
'options.session is deprecated and will be removed in a future release due to incompatibility with multi-device. ' +
'Use the LocalAuth authStrategy, don\'t pass in a session as an option, or suppress this warning by using the LegacySessionAuth strategy explicitly (see https://wwebjs.dev/guide/authentication.html#legacysessionauth-strategy).',
'DeprecationWarning'
);

this.authStrategy = new LegacySessionAuth({
session: this.options.session,
restartOnAuthFail: this.options.restartOnAuthFail
});
} else {
this.authStrategy = new NoAuth();
}
this.authStrategy = new NoAuth();
} else {
this.authStrategy = this.options.authStrategy;
}
Expand All @@ -85,6 +73,8 @@ class Client extends EventEmitter {
this.pupBrowser = null;
this.pupPage = null;

this.currentIndexHtml = null;

Util.setFfmpegPath(this.options.ffmpegPath);
}

Expand Down Expand Up @@ -125,7 +115,8 @@ class Client extends EventEmitter {
await this.authStrategy.afterBrowserInitialized();
await this.initWebVersionCache();

// ocVesion (isOfficialClient patch)
// ocVersion (isOfficialClient patch)
// remove on after 2.3000.x
await page.evaluateOnNewDocument(() => {
const originalError = Error;
//eslint-disable-next-line no-global-assign
Expand Down Expand Up @@ -336,7 +327,23 @@ class Client extends EventEmitter {
};
});

await page.evaluate(ExposeStore, moduleRaid.toString());
const version = await this.getWWebVersion();
const isCometOrAbove = parseInt(version.split('.')?.[1]) >= 3000;

if (this.options.webVersionCache.type === 'local' && this.currentIndexHtml) {
const { type: webCacheType, ...webCacheOptions } = this.options.webVersionCache;
const webCache = WebCacheFactory.createWebCache(webCacheType, webCacheOptions);

await webCache.persist(this.currentIndexHtml, version);
}

if (isCometOrAbove) {
await page.evaluate(ExposeStore);
} else {
await page.evaluate(ExposeLegacyStore, moduleRaid.toString());
}


const authEventPayload = await this.authStrategy.getAuthEventPayload();

/**
Expand Down Expand Up @@ -768,7 +775,8 @@ class Client extends EventEmitter {
} else {
this.pupPage.on('response', async (res) => {
if(res.ok() && res.url() === WhatsWebURL) {
await webCache.persist(await res.text());
const indexHtml = await res.text();
this.currentIndexHtml = indexHtml;
}
});
}
Expand Down Expand Up @@ -1087,14 +1095,8 @@ class Client extends EventEmitter {
async setDisplayName(displayName) {
const couldSet = await this.pupPage.evaluate(async displayName => {
if(!window.Store.Conn.canSetMyPushname()) return false;

if(window.Store.MDBackend) {
await window.Store.Settings.setPushname(displayName);
return true;
} else {
const res = await window.Store.Wap.setPushname(displayName);
return !res.status || res.status === 200;
}
await window.Store.Settings.setPushname(displayName);
return true;
}, displayName);

return couldSet;
Expand Down Expand Up @@ -1416,7 +1418,7 @@ class Client extends EventEmitter {
const statusCode = participant.error ?? 200;

if (autoSendInviteV4 && statusCode === 403) {
window.Store.ContactCollection.gadd(participant.wid, { silent: true });
window.Store.Contact.gadd(participant.wid, { silent: true });
const addParticipantResult = await window.Store.GroupInviteV4.sendGroupInviteMessage(
await window.Store.Chat.find(participant.wid),
createGroupResult.wid._serialized,
Expand Down
72 changes: 0 additions & 72 deletions src/authStrategies/LegacySessionAuth.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/structures/GroupChat.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class GroupChat extends Chat {
419: 'The participant can\'t be added because the group is full'
};

await window.Store.GroupMetadata.queryAndUpdate(groupWid);
await window.Store.GroupQueryAndUpdate(groupWid);
const groupMetadata = group.groupMetadata;
const groupParticipants = groupMetadata?.participants;

Expand Down Expand Up @@ -152,7 +152,7 @@ class GroupChat extends Chat {

if (autoSendInviteV4 && rpcResultCode === 403) {
let userChat, isInviteV4Sent = false;
window.Store.ContactCollection.gadd(pWid, { silent: true });
window.Store.Contact.gadd(pWid, { silent: true });

if (rpcResult.name === 'ParticipantRequestCodeCanBeSent' &&
(userChat = await window.Store.Chat.find(pWid))) {
Expand Down
149 changes: 149 additions & 0 deletions src/util/Injected/LegacyStore.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
'use strict';

//TODO: To be removed y version 2.3000.x hard release

// Exposes the internal Store to the WhatsApp Web client
exports.ExposeStore = (moduleRaidStr) => {
eval('var moduleRaid = ' + moduleRaidStr);
// eslint-disable-next-line no-undef
window.mR = moduleRaid();
window.Store = Object.assign({}, window.mR.findModule(m => m.default && m.default.Chat)[0].default);
window.Store.AppState = window.mR.findModule('Socket')[0].Socket;
window.Store.Conn = window.mR.findModule('Conn')[0].Conn;
window.Store.BlockContact = window.mR.findModule('blockContact')[0];
window.Store.Call = window.mR.findModule((module) => module.default && module.default.Call)[0].default.Call;
window.Store.Cmd = window.mR.findModule('Cmd')[0].Cmd;
window.Store.CryptoLib = window.mR.findModule('decryptE2EMedia')[0];
window.Store.DownloadManager = window.mR.findModule('downloadManager')[0].downloadManager;
window.Store.GroupMetadata = window.mR.findModule('GroupMetadata')[0].default.GroupMetadata;
window.Store.GroupQueryAndUpdate = window.mR.findModule('queryAndUpdateGroupMetadataById')[0].queryAndUpdateGroupMetadataById;
window.Store.Label = window.mR.findModule('LabelCollection')[0].LabelCollection;
window.Store.MediaPrep = window.mR.findModule('prepRawMedia')[0];
window.Store.MediaObject = window.mR.findModule('getOrCreateMediaObject')[0];
window.Store.NumberInfo = window.mR.findModule('formattedPhoneNumber')[0];
window.Store.MediaTypes = window.mR.findModule('msgToMediaType')[0];
window.Store.MediaUpload = window.mR.findModule('uploadMedia')[0];
window.Store.MsgKey = window.mR.findModule((module) => module.default && module.default.fromString)[0].default;
window.Store.OpaqueData = window.mR.findModule(module => module.default && module.default.createFromData)[0].default;
window.Store.QueryProduct = window.mR.findModule('queryProduct')[0];
window.Store.QueryOrder = window.mR.findModule('queryOrder')[0];
window.Store.SendClear = window.mR.findModule('sendClear')[0];
window.Store.SendDelete = window.mR.findModule('sendDelete')[0];
window.Store.SendMessage = window.mR.findModule('addAndSendMsgToChat')[0];
window.Store.EditMessage = window.mR.findModule('addAndSendMessageEdit')[0];
window.Store.SendSeen = window.mR.findModule('sendSeen')[0];
window.Store.User = window.mR.findModule('getMaybeMeUser')[0];
window.Store.ContactMethods = window.mR.findModule('getUserid')[0];
window.Store.UploadUtils = window.mR.findModule((module) => (module.default && module.default.encryptAndUpload) ? module.default : null)[0].default;
window.Store.UserConstructor = window.mR.findModule((module) => (module.default && module.default.prototype && module.default.prototype.isServer && module.default.prototype.isUser) ? module.default : null)[0].default;
window.Store.Validators = window.mR.findModule('findLinks')[0];
window.Store.VCard = window.mR.findModule('vcardFromContactModel')[0];
window.Store.WidFactory = window.mR.findModule('createWid')[0];
window.Store.ProfilePic = window.mR.findModule('profilePicResync')[0];
window.Store.PresenceUtils = window.mR.findModule('sendPresenceAvailable')[0];
window.Store.ChatState = window.mR.findModule('sendChatStateComposing')[0];
window.Store.findCommonGroups = window.mR.findModule('findCommonGroups')[0].findCommonGroups;
window.Store.StatusUtils = window.mR.findModule('setMyStatus')[0];
window.Store.ConversationMsgs = window.mR.findModule('loadEarlierMsgs')[0];
window.Store.sendReactionToMsg = window.mR.findModule('sendReactionToMsg')[0].sendReactionToMsg;
window.Store.createOrUpdateReactionsModule = window.mR.findModule('createOrUpdateReactions')[0];
window.Store.EphemeralFields = window.mR.findModule('getEphemeralFields')[0];
window.Store.MsgActionChecks = window.mR.findModule('canSenderRevokeMsg')[0];
window.Store.QuotedMsg = window.mR.findModule('getQuotedMsgObj')[0];
window.Store.LinkPreview = window.mR.findModule('getLinkPreview')[0];
window.Store.Socket = window.mR.findModule('deprecatedSendIq')[0];
window.Store.SocketWap = window.mR.findModule('wap')[0];
window.Store.SearchContext = window.mR.findModule('getSearchContext')[0].getSearchContext;
window.Store.DrawerManager = window.mR.findModule('DrawerManager')[0].DrawerManager;
window.Store.LidUtils = window.mR.findModule('getCurrentLid')[0];
window.Store.WidToJid = window.mR.findModule('widToUserJid')[0];
window.Store.JidToWid = window.mR.findModule('userJidToUserWid')[0];
window.Store.getMsgInfo = (window.mR.findModule('sendQueryMsgInfo')[0] || {}).sendQueryMsgInfo || window.mR.findModule('queryMsgInfo')[0].queryMsgInfo;
window.Store.pinUnpinMsg = window.mR.findModule('sendPinInChatMsg')[0].sendPinInChatMsg;

/* eslint-disable no-undef, no-cond-assign */
window.Store.QueryExist = ((m = window.mR.findModule('queryExists')[0]) ? m.queryExists : window.mR.findModule('queryExist')[0].queryWidExists);
window.Store.ReplyUtils = (m = window.mR.findModule('canReplyMsg')).length > 0 && m[0];
/* eslint-enable no-undef, no-cond-assign */

window.Store.Settings = {
...window.mR.findModule('ChatlistPanelState')[0],
setPushname: window.mR.findModule((m) => m.setPushname && !m.ChatlistPanelState)[0].setPushname
};
window.Store.StickerTools = {
...window.mR.findModule('toWebpSticker')[0],
...window.mR.findModule('addWebpMetadata')[0]
};
window.Store.GroupUtils = {
...window.mR.findModule('createGroup')[0],
...window.mR.findModule('setGroupDescription')[0],
...window.mR.findModule('sendExitGroup')[0],
...window.mR.findModule('sendSetPicture')[0]
};
window.Store.GroupParticipants = {
...window.mR.findModule('promoteParticipants')[0],
...window.mR.findModule('sendAddParticipantsRPC')[0]
};
window.Store.GroupInvite = {
...window.mR.findModule('resetGroupInviteCode')[0],
...window.mR.findModule('queryGroupInvite')[0]
};
window.Store.GroupInviteV4 = {
...window.mR.findModule('queryGroupInviteV4')[0],
...window.mR.findModule('sendGroupInviteMessage')[0]
};
window.Store.MembershipRequestUtils = {
...window.mR.findModule('getMembershipApprovalRequests')[0],
...window.mR.findModule('sendMembershipRequestsActionRPC')[0]
};

if (!window.Store.Chat._find) {
window.Store.Chat._find = e => {
const target = window.Store.Chat.get(e);
return target ? Promise.resolve(target) : Promise.resolve({
id: e
});
};
}

// eslint-disable-next-line no-undef
if ((m = window.mR.findModule('ChatCollection')[0]) && m.ChatCollection && typeof m.ChatCollection.findImpl === 'undefined' && typeof m.ChatCollection._find !== 'undefined') m.ChatCollection.findImpl = m.ChatCollection._find;

const _isMDBackend = window.mR.findModule('isMDBackend');
if(_isMDBackend && _isMDBackend[0] && _isMDBackend[0].isMDBackend) {
window.Store.MDBackend = _isMDBackend[0].isMDBackend();
} else {
window.Store.MDBackend = true;
}

const _features = window.mR.findModule('FEATURE_CHANGE_EVENT')[0];
if(_features) {
window.Store.Features = _features.LegacyPhoneFeatures;
}

/**
* Target options object description
* @typedef {Object} TargetOptions
* @property {string|number} module The name or a key of the target module to search
* @property {number} index The index value of the target module
* @property {string} function The function name to get from a module
*/

/**
* Function to modify functions
* @param {TargetOptions} target Options specifying the target function to search for modifying
* @param {Function} callback Modified function
*/
window.injectToFunction = (target, callback) => {
const module = typeof target.module === 'string'
? window.mR.findModule(target.module)
: window.mR.modules[target.module];
const originalFunction = module[target.index][target.function];
const modifiedFunction = (...args) => callback(originalFunction, ...args);
module[target.index][target.function] = modifiedFunction;
};

window.injectToFunction({ module: 'mediaTypeFromProtobuf', index: 0, function: 'mediaTypeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage ? null : func(...args); });

window.injectToFunction({ module: 'typeAttributeFromProtobuf', index: 0, function: 'typeAttributeFromProtobuf' }, (func, ...args) => { const [proto] = args; return proto.locationMessage || proto.groupInviteMessage ? 'text' : func(...args); });
};