Skip to content

Commit

Permalink
Disabled logs hooking to avoid InvalidStateError in IndexedDB
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer8007 committed Jul 1, 2022
1 parent 90272e1 commit e463081
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
35 changes: 10 additions & 25 deletions core/interception.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,15 @@ initialize();
//
wsHook.before = function (originalData, url)
{
var isMultiDevice = !WACrypto.isTagBasedPayload(originalData);

var promise = async function(originalData) {

if (WAPassthrough) return originalData;

try
{
var data = originalData;
var isMultiDevice = !WACrypto.isTagBasedPayload(data);
var isMultiDevice = !WACrypto.isTagBasedPayload(originalData);

var tag = "";
if (!isMultiDevice)
{
payload = WACrypto.parseWebSocketPayload(data);
data = payload.data;
tag = payload.tag;
}
var {tag, data} = isMultiDevice ? {tag: "", data: originalData} : WACrypto.parseWebSocketPayload(originalData);

if (data instanceof ArrayBuffer || data instanceof Uint8Array)
{
Expand Down Expand Up @@ -111,6 +102,8 @@ wsHook.before = function (originalData, url)

};

var isMultiDevice = !WACrypto.isTagBasedPayload(originalData);

return isMultiDevice ? MultiDevice.enqueuePromise(promise, originalData, false) : promise(originalData);
}

Expand All @@ -119,25 +112,15 @@ wsHook.before = function (originalData, url)
//
wsHook.after = function (messageEvent, url)
{
var data = messageEvent.data;
var isMultiDevice = !WACrypto.isTagBasedPayload(data);

var promise = async function(messageEvent) {

var data = messageEvent.data;
var isMultiDevice = !WACrypto.isTagBasedPayload(data);

if (WAPassthrough) return messageEvent;

try
{
var tag = "";
if (!isMultiDevice)
{
payload = WACrypto.parseWebSocketPayload(data);
tag = payload.tag;
data = payload.data;
}
var isMultiDevice = !WACrypto.isTagBasedPayload(messageEvent.data);

var {tag, data} = isMultiDevice ? {tag: "", data: messageEvent.data} : WACrypto.parseWebSocketPayload(messageEvent.data);

if (data instanceof ArrayBuffer || data instanceof Uint8Array)
{
Expand Down Expand Up @@ -205,6 +188,8 @@ wsHook.after = function (messageEvent, url)

};

var isMultiDevice = !WACrypto.isTagBasedPayload(messageEvent.data);

return isMultiDevice ? MultiDevice.enqueuePromise(promise, messageEvent, true) : promise(messageEvent);
}

Expand Down Expand Up @@ -562,7 +547,7 @@ function exposeWhatsAppAPI()

function initialize()
{
hookLogs();
//hookLogs();
initializeDeletedMessagesDB();
}

Expand Down
17 changes: 10 additions & 7 deletions core/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ function onMainUIReady()
setTimeout(checkInterception, 1000);

// if the menu item is gone somehow after a short period of time (e.g because the layout changes from right-to-left) add it again
// TODO: a race can make the icon added twice
setTimeout(addIconIfNeeded, 1000);
}

Expand Down Expand Up @@ -328,19 +329,21 @@ document.addEventListener('onInterceptionWorking', function (e)
isInterceptionWorking = data.isInterceptionWorking;
isMultiDevice = data.isMultiDevice;

var deletedDB = indexedDB.open("deletedMsgs", 1);
deletedDB.onsuccess = () => {
var keys = deletedDB.result.transaction('msgs', "readonly")
.objectStore("msgs").getAll();
// populate pseudoMsgsIDs
var deletedDBOpenRequest = indexedDB.open("deletedMsgs", 1);
deletedDBOpenRequest.onsuccess = () =>
{
var deletedMsgsDB = deletedDBOpenRequest.result;
var keys = deletedMsgsDB.transaction('msgs', "readonly").objectStore("msgs").getAll();
keys.onsuccess = () => {
keys.result.forEach((v) => {
pseudoMsgsIDs.add(v.originalID);
keys.result.forEach((value) => {
pseudoMsgsIDs.add(value.originalID);
});
document.addEventListener("pseudoMsgs", (e) => {
pseudoMsgsIDs.add(e.detail);
});
};
deletedDB.result.close();
deletedMsgsDB.close();
};
});

Expand Down

0 comments on commit e463081

Please sign in to comment.