Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): leave a missing window.require out of the navigation 409
Yudhi Armyndharisb2c73f20e59e
diff --git a/src/engine/adapters/wwebjs-lifecycle.ts b/src/engine/adapters/wwebjs-lifecycle.tsindex 6813a4048..b1dad933e 100644--- a/src/engine/adapters/wwebjs-lifecycle.ts+++ b/src/engine/adapters/wwebjs-lifecycle.ts@@ -76,17 +76,18 @@ export const PAGE_RELOADING_MESSAGE =/*** Whether a page call was cut short by the page navigating away under it (WhatsApp Web reloading). Puppeteer* rewrites its three CDP shapes of this into 'Execution context was destroyed, most likely because of a- * navigation.', and a call that lands on the new document before WhatsApp Web has booted dies on the missing- * `window.require`. The page is alive and re-injecting, so unlike a death this is not reported, and a retry- * a few seconds later succeeds. Not an HttpException, and not a failure captured inside the page, whose text- * quotes WhatsApp Web and says nothing about our page.+ * navigation.' The page is alive and re-injecting, so unlike a death this is not reported, and a retry a few+ * seconds later succeeds. Not an HttpException, and not a failure captured inside the page, whose text quotes+ * WhatsApp Web and says nothing about our page. The `window.require is not a function` of a document that has+ * not booted is left out: nothing here bounds it, so a page that stays like that would answer this retryable+ * status for good, where the liveness probe and the watchdog deal with it as a failure.*/export function isNavigationError(error: unknown): boolean {if (error instanceof HttpException) {return false;}const message = error instanceof Error ? error.message : String(error);- return !message.startsWith(CAPTURED_PAGE_ERROR_PREFIX) && isNavigationShapedInitRejection(message);+ return !message.startsWith(CAPTURED_PAGE_ERROR_PREFIX) && isExecutionContextDestroyedError(message);}/**diff --git a/src/engine/adapters/wwebjs-navigation-error.spec.ts b/src/engine/adapters/wwebjs-navigation-error.spec.tsindex 4e0e78323..9fb831c5f 100644--- a/src/engine/adapters/wwebjs-navigation-error.spec.ts+++ b/src/engine/adapters/wwebjs-navigation-error.spec.ts@@ -27,11 +27,7 @@ const logger = createLogger('wwebjs-navigation-error.spec');const NAVIGATION = 'Execution context was destroyed, most likely because of a navigation.';describe('isNavigationError', () => {- it.each([- NAVIGATION,- 'Evaluation failed: TypeError: window.require is not a function',- 'execution context was destroyed',- ])('reads %p as a navigation', message => {+ it.each([NAVIGATION, 'execution context was destroyed'])('reads %p as a navigation', message => {expect(isNavigationError(new Error(message))).toBe(true);});@@ -45,6 +41,8 @@ describe('isNavigationError', () => {'Protocol error (Runtime.callFunctionOn): Target closed',"Runtime.callFunctionOn timed out. Increase the 'protocolTimeout' setting in launch/connect calls",'Evaluation failed: TypeError: Cannot read properties of null',+ // Nothing bounds this one, so a page that stays like it must reach the liveness probe as a failure.+ 'Evaluation failed: TypeError: window.require is not a function','',])('does not read %p as a navigation', message => {expect(isNavigationError(new Error(message))).toBe(false);