cap icon indicating copy to clipboard operation
cap copied to clipboard

[BUG] Worker fails to fallback to JavaScript solver when WASM is available but not fully supported

Open izanhzh opened this issue 1 year ago • 5 comments

Describe the bug In certain older browsers (e.g., Chrome 86), WebAssembly is reported as supported but some WASM features may not be fully implemented. When the WASM solver fails in these environments, the system logs the message "[cap worker] using fallback solver due to error:", but does not actually fallback to the JavaScript solver, causing the CAPTCHA solving process to fail completely.

Affects:

  • [] Standalone mode
  • [x] Widget
  • [] Server
  • [] WASM
  • [] Solver
  • [] Solver CLI

To Reproduce Steps to reproduce the behavior:

  1. Use an older browser with partial WASM support (e.g., Chrome 86)
  2. Attempt to solve a CAPTCHA challenge
  3. Observe that WASM loading or execution fails
  4. Check console logs for "[cap worker] using fallback solver due to error:" message
  5. Note that the fallback JavaScript solver is not actually triggered

Expected behavior When WASM is available but fails during loading or execution, the worker should properly fallback to the JavaScript-based solver implementation.

Screenshots Image

Desktop (please complete the following information):

  • OS: [win10]
  • Browser [chrome]
  • Version [86]

Additional context This issue affects users on older browsers that claim to support WASM but don't have complete implementation, potentially blocking them from completing CAPTCHA challenges entirely.

izanhzh avatar Aug 22 '25 01:08 izanhzh

fixed by [email protected]

tiagozip avatar Aug 26 '25 11:08 tiagozip

@tiagozip Still having issues with v0.1.26. I think the code logic shown below is problematic - it might not re-enter the if block

Image

izanhzh avatar Aug 27 '25 01:08 izanhzh

Same issue. @cap.js/widget: v0.1.30 @cap.js/server: v4.0.3

Image

pxgo avatar Oct 22 '25 10:10 pxgo

mind sharing a github repo or codesandbox reproducing the error so i can look into your specific case further?

tiagozip avatar Oct 22 '25 16:10 tiagozip

mind sharing a github repo or codesandbox reproducing the error so i can look into your specific case further?

Here is a minimal example of using Cap.js with the Express framework: https://github.com/pxgo/capjs-demo To reproduce the issue, you can install Chrome 86.0.4240.111 in a system sandbox for testing. Recommended Chrome download link: https://github.com/dengcao/chrome/tree/main/windows/64Bit.

pxgo avatar Oct 23 '25 02:10 pxgo

it seems to work perfectly fine, both with and without wasm enabled, on chrome and firefox.

Image Image

tiagozip avatar Oct 24 '25 12:10 tiagozip

@tiagozip Are you using the browser version mentioned in @pxgo comment? If WASM is completely disabled, there's no problem. However, some older browser versions support WASM but lack certain features, which causes the code execution to reach the following section.

	self.onmessage = async ({ data: { salt, target, wasmUrl } }) => {
		let fb;

		if (wasmCacheUrl !== wasmUrl) {
			wasmCacheUrl = wasmUrl;
			await import(wasmUrl)
				.then((wasmModule) => {
					return wasmModule.default().then((instance) => {
						solve_pow_function = (
							instance?.exports ? instance.exports : wasmModule
						).solve_pow;
					});
				})
				.catch((e) => {
					console.error("[cap worker] using fallback solver due to error:", e);
					fb = true;

					return solveFallback({ salt, target });
				});

			if (fb) return;
		}

Please pay attention to the condition if (wasmCacheUrl !== wasmUrl). Depending on the challenge difficulty setting, this will be executed many times. It works normally for the first solveFallback, but on the second attempt, it will skip this if condition.

izanhzh avatar Oct 25 '25 01:10 izanhzh

it seems to work perfectly fine, both with and without wasm enabled, on chrome and firefox.

Image Image

What version of browser are you using? I can stably reproduce the issue in Chrome 86.0.4240.111.

pxgo avatar Nov 03 '25 02:11 pxgo

ill look into it

tiagozip avatar Nov 03 '25 22:11 tiagozip