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

Provide Custom Puppeteer Instance to Client #508

Closed
cstayyab opened this issue Dec 30, 2020 · 7 comments
Closed

Provide Custom Puppeteer Instance to Client #508

cstayyab opened this issue Dec 30, 2020 · 7 comments
Labels
enhancement New feature or request

Comments

@cstayyab
Copy link

Is your feature request related to a problem? Please describe.
I am using WhatsApp-Web.js with Electron and WhatsApp Web is opened in Electron Window. I am passing WhatsApp Web Session to WhatsApp-Web.js but as soon as I do that WhatsApp Web on Electron windows shows "You are using WhatsApp Web elsewhere" Dialog. I want to pass Custom puppeteer Instance to WhatsApp-Web.js using "Puppeteer-in-electron" Package so electron and WhatsApp-Web.js share the same instance of WhatsApp Web. Is there a way to achieve this?

Describe the solution you'd like
There should be an argument to pass puppeteer/puppeteer-core instance to Client constructor so it uses that instance of puppeteer instead of its own new instance.

Describe alternatives you've considered
Clone the repository making required changes myself but this way I have to manually integrate changes from new versions of WhatsApp-web.js and it is not convenient.

Additional context
image

@cstayyab cstayyab added the enhancement New feature or request label Dec 30, 2020
@cstayyab cstayyab changed the title Custom Puppeteer Instance to Client Provide Custom Puppeteer Instance to Client Dec 30, 2020
@arthurpadilha
Copy link

arthurpadilha commented Feb 9, 2021

@cstayyab
I've got this same error and fixed it by changing the first lines of the init function in the Client.js file:
previous:

async initialize() {
    const browser = await puppeteer.launch(this.options.puppeteer);
    const page = (await browser.pages())[0];
    page.setUserAgent(this.options.userAgent);
    (...)

current:

async initialize(browser, window, pie) {

    const page = await pie.getPage(browser, window);
    page.setUserAgent(this.options.userAgent);
    (...)

When I created the WA instance I just did like that:

const pie = require("puppeteer-in-electron")
const puppeteer = require("puppeteer-core");
const WhatsApp = require('whatsapp-web.js');
const { app } = require("electron");

const main = async () => {

	await pie.initialize(app);
	const browser = await pie.connect(app, puppeteer);
	
	var window = new BrowserWindow({
		webPreferences: {
		  contextIsolation: false,
		  nodeIntegration: true
		}
	});
	
	var client = new WhatsApp.Client();
	client.initialize(browser, window, pie);

};
main();

That worked for me just fine, until when I've closed and reopen the app:

The already authenticated WhatsApp session isn't reloading and I'm stucked with the google chrome update error : "WhatsApp works with Google Chrome 60+"

I've oppened DevTools in the app window and executed navigator.appVersion.match(/.*Chrome\/([0-9\.]+)/)[1] to check chromium version. I've got: "72.0.3626.109" which is higher than 60+ as requested by WhatsApp Web page. Any ideas on how to fix that? Doesn't seem to be related to the chromium version...

By the way I'm running on Windows 10.

@PurpShell
Copy link
Sponsor Collaborator

this is off-topic, and some people have released some projects for electron with some really good success

don't expect them to have documentation though

One that has caught my attention is https://github.com/Zzombiee2361/whatsapp-web-electron.js

you start the client with new Client(browser, window, ClientOptions)

some stuff that didn't work well with electron like sending stickers are not advised to be used.

Closing this thread.

@h110m
Copy link
Contributor

h110m commented Jul 12, 2021

@PurpShell This issue is still not resolved!
The package you mentioned still has the same error that @arthurpadilha has mentioned in his post.
The chrome version error still exists. Would be really nice if you could take a look at this!

@vtoskovic-mdx
Copy link

Coming late to the party, with the same issue. Did you guys @arthurpadilha @h110m managed to find some workaround?

@deadlinecode
Copy link

deadlinecode commented Aug 3, 2023

Bro its like way to late xD
This was from 2 years ago
Im sorry but i can hardly even remember what this was about 😅
(This is my sec acc btw)

@vtoskovic-mdx
Copy link

I know that feeling :D

@deadlinecode
Copy link

@vtoskovic-mdx i think i actually changed the user agent or smth but it was way to hacky what i did

@alechkos alechkos mentioned this issue Feb 1, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants