Skip to content

Commit

Permalink
fix: Fixed DataCloneError error after WPP.contact.queryExists call
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Nov 21, 2022
1 parent fea5b67 commit fabe916
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/contact/functions/queryExists.ts
Expand Up @@ -80,9 +80,25 @@ export async function queryExists(
if (useInternationalMode) {
const internationalWid = assertWid(contactId);

internationalWid.toString = () => `+${internationalWid._serialized}`;
// Make a backup of original method
const originalToString = internationalWid.toString;

// Change 'toString' function without enumerating it
Object.defineProperty(internationalWid, 'toString', {
configurable: true,
enumerable: false,
value: () => `+${internationalWid._serialized}`,
});

result = await sendQueryExists(internationalWid).catch(() => null);

// Restore 'toString' function without enumerating it
// Note: using `internationalWid = toString` make it enumerable
Object.defineProperty(internationalWid, 'toString', {
configurable: true,
enumerable: false,
value: originalToString,
});
}

if (!result) {
Expand Down

0 comments on commit fabe916

Please sign in to comment.