Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): read a missing window.require as a navigation again
Yudhi Armyndharis9a2d57d6b3c3
diff --git a/src/engine/adapters/wwebjs-lifecycle.ts b/src/engine/adapters/wwebjs-lifecycle.tsindex b1dad933e..1ae1b4557 100644--- a/src/engine/adapters/wwebjs-lifecycle.ts+++ b/src/engine/adapters/wwebjs-lifecycle.ts@@ -76,18 +76,20 @@ 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.' 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.+ * 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. A page that stays without `window.require` is not+ * hidden by this answer: it is not reported here, but the liveness probe fails outside the re-inject window+ * and the watchdog reconnects. Left unread, the same message became a false 404 or 400 at the catches that+ * fold a failed lookup into "not found", or a bare 500.*/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) && isExecutionContextDestroyedError(message);+ return !message.startsWith(CAPTURED_PAGE_ERROR_PREFIX) && isNavigationShapedInitRejection(message);}/**diff --git a/src/engine/adapters/wwebjs-navigation-error.spec.ts b/src/engine/adapters/wwebjs-navigation-error.spec.tsindex 9fb831c5f..4e0e78323 100644--- a/src/engine/adapters/wwebjs-navigation-error.spec.ts+++ b/src/engine/adapters/wwebjs-navigation-error.spec.ts@@ -27,7 +27,11 @@ const logger = createLogger('wwebjs-navigation-error.spec');const NAVIGATION = 'Execution context was destroyed, most likely because of a navigation.';describe('isNavigationError', () => {- it.each([NAVIGATION, 'execution context was destroyed'])('reads %p as a navigation', message => {+ it.each([+ NAVIGATION,+ 'Evaluation failed: TypeError: window.require is not a function',+ 'execution context was destroyed',+ ])('reads %p as a navigation', message => {expect(isNavigationError(new Error(message))).toBe(true);});@@ -41,8 +45,6 @@ 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);