Skip to content

Commit

Permalink
fix: Fixed WAPI is not defined (#2215) (close #2206
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta committed Jun 12, 2024
1 parent 8f5f36b commit 2962aac
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/api/layers/host.layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export class HostLayer {
.catch((e) => {
console.log(e);
this.log('verbose', 'wapi.js failed');
this.log('error', e);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/config/create-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const defaultOptions: CreateConfig = {
waitForLogin: true,
logger: defaultLogger,
tokenStore: 'file',
whatsappVersion: '2.2413.x',
whatsappVersion: '2.3000.1014014368-alpha',
deviceName: false,
linkPreviewApiServers: null,
disableGoogleAnalytics: true,
Expand Down
34 changes: 5 additions & 29 deletions src/controllers/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,44 +217,20 @@ export async function injectApi(
if (injected) {
return;
}

// Wait for some loaded modules
await page
.waitForFunction(
() => ((window as any)?.webpackChunkwhatsapp_web_client?.length || 0) > 3
)
.catch(() => null);

await sleep(100);

await page.addScriptTag({
path: require.resolve('@wppconnect/wa-js'),
});

await page
.evaluate(() => {
WPP.chat.defaultSendMessageOptions.createChat = true;
WPP.conn.setKeepAlive(true);
})
.catch(() => false);

await page.evaluate(() => {
WPP.chat.defaultSendMessageOptions.createChat = true;
WPP.conn.setKeepAlive(true);
});
await page.addScriptTag({
path: require.resolve(
path.join(__dirname, '../../dist/lib/wapi', 'wapi.js')
),
});

await onLoadingScreen(page, onLoadingScreenCallBack);
// Make sure WAPI is initialized
await page
.waitForFunction(() => {
return (
typeof window.WAPI !== 'undefined' &&
typeof window.Store !== 'undefined' &&
window.WPP.isReady
);
})
.catch(() => false);
onLoadingScreen(page, onLoadingScreenCallBack);
}

/**
Expand Down

0 comments on commit 2962aac

Please sign in to comment.