pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.41k stars 3.44k forks source link

Whatsapp Web Js for Chrome Extensions #2595

Closed geanrt closed 8 months ago

geanrt commented 8 months ago

Is there an existing issue for this?

Is your feature request related to a problem? Please describe.

For some time I have been looking for a way to use this library in a Chrome extension, but without success, as to do so I would need 4 pieces of information: WaBrowserId, WaSecretBundle, WAToken1 and WAToken2.

Describe the solution you'd like.

I don't have a complete solution, that's why I come here (if I don't have an answer I will bring a solution in the next few weeks). The question for this would be, what functions of Whatsapp Web Js or other libs (non-Node) to generate these 4 information within an Extension environment with Whatsapp Web as Host and later send it to a Node environment?

Describe an alternate solution.

As I know that Whatsapp Web Js first scans the QR code and then these 4 extra pieces of information on the website, I tried to map the path for this, but without success either.

Another way I tried was to copy all the information contained in the cache, in indexDB and Storage with this function:

function getResultFromRequest(request) {
  return new Promise((resolve, reject) => {
      request.onsuccess = function (event) {
          resolve(request.result);
      };
  });
}

async function getDB() {
  var request = window.indexedDB.open("wawc");
  return await getResultFromRequest(request);
}

async function readAllKeyValuePairs() {
  var db = await getDB();
  var objectStore = db.transaction("user").objectStore("user");
  var request = objectStore.getAll();
     return await getResultFromRequest(request);
}

session = await readAllKeyValuePairs();
JSON.stringify(session)

I copied and tried in another browser to save this information on WhatsApp:

function getResultFromRequest(request) {
    return new Promise((resolve, reject) => {
        request.onsuccess = function(event) {
            resolve(request.result);
        };
    })
}

async function getDB() {
    var request = window.indexedDB.open("wawc");
    return await getResultFromRequest(request);
}

async function injectSession(SESSION_STRING) {
    var session = JSON.parse(SESSION_STRING);
    var db = await getDB();
    var objectStore = db.transaction("user", "readwrite").objectStore("user");
    for(var keyValue of session) {
        var request = objectStore.put(keyValue);
        await getResultFromRequest(request);
    }
}

var SESSION_STRING = "";
await injectSession(SESSION_STRING);

But I wasn't successful either.

I found other useful things like: localStorage.getItem('WANoiseInfo')

So the question remains, how could we get these 4 pieces of information (WaBrowserId, WaSecretBundle, WAToken1 and WAToken2)? to later send to a Node environment.

I may be being stupid, if you have other solutions, I'm willing to listen to them.

geanrt commented 8 months ago

I really solved all the automation problems in my Extension, but this part of sending media messages, audios and much more that Whatsapp Web Js can offer would be too necessary

geanrt commented 8 months ago

Another thing that I've always had doubts about, Whatsapp Web Js works on top of another Lib or makes its own communications with Whatsapp... but we can take advantage of this, if Whatsapp web Js does its own communication, how does this communication work, would it be through Rest API or with interactions on the website? or both.

geanrt commented 8 months ago

2686257c-1723-4c0a-b054-2829c2417b36

Creating or inserting sections is another automatic process, and what would that process look like? I just need a way to save some data, or create it from an open WhatsApp web session using javascript in the console or within a Chrome extension and send it to another environment and create a new session

geanrt commented 8 months ago

??

geanrt commented 8 months ago

??

dvrfluxchat commented 8 months ago

This is awesome, i was looking for the same thing, glad you figured it out. can you share a sample project?

loic-hamdi commented 4 months ago

@geanrt could you please share your solution?

geanrt commented 4 months ago

@loic-hamdi call me on LinkedIn linkedin.com/in/geanrt