cap icon indicating copy to clipboard operation
cap copied to clipboard

[BUG] Self-hosted widget script-tag not working

Open saufdermaur opened this issue 1 year ago • 1 comments

Describe the bug I've been using both the Cap Standalone and the correspondig self-hosted widget. I’m not sure exactly since when, but I noticed (presumably due to a new Standalone version) that the self-hosted widget no longer works.

I get the following traffic on the redeem endpoint:

Request header:

POST /231ccd324a/redeem HTTP/1.1
Host: 192.168.1.2:4000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0
Accept: */*
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
Referer: http://localhost:5173/
Content-Type: application/json
Content-Length: 77
Origin: http://localhost:5173
DNT: 1
Sec-GPC: 1
Connection: keep-alive
Priority: u=4

Request body:

{"token":"3bbcb51466397a80f692d72a92e1d6be9cf83270fd024b865d","solutions":[]}

Response header:

HTTP/1.1 403 Forbidden
Access-Control-Allow-Credentials: true
Vary: *
Access-Control-Allow-Origin: http://localhost:5173
Access-Control-Allow-Methods: POST
Access-Control-Allow-Headers: host, user-agent, accept, accept-language, accept-encoding, referer, content-type, content-length, origin, dnt, connection, sec-gpc, priority
Access-Control-Expose-Headers: host, user-agent, accept, accept-language, accept-encoding, referer, content-type, content-length, origin, dnt, connection, sec-gpc, priority
Content-Type: application/json
RateLimit-Limit: 45
RateLimit-Remaining: 42
RateLimit-Reset: 5
Date: Fri, 04 Jul 2025 20:25:09 GMT
Content-Length: 28

Response body:

{"error":"Invalid solution"}

And these console logs:

[cap] Invalid solution widget.js:1:12040
    error widget.js:1
    solve widget.js:1
    addEventListeners widget.js:1
    (Async: EventListener.handleEvent)
    addEventListeners widget.js:1
    connectedCallback widget.js:1
    insert runtime-dom.esm-bundler.js:28
    mountElement runtime-core.esm-bundler.js:4925
    processElement runtime-core.esm-bundler.js:4851
    patch runtime-core.esm-bundler.js:4717
    mountChildren runtime-core.esm-bundler.js:4963
    mount runtime-core.esm-bundler.js:824
    mountToTarget runtime-core.esm-bundler.js:846
    process runtime-core.esm-bundler.js:868
    patch runtime-core.esm-bundler.js:4741
    patchKeyedChildren runtime-core.esm-bundler.js:5761
    patchChildren runtime-core.esm-bundler.js:5543
    processFragment runtime-core.esm-bundler.js:5187
    patch runtime-core.esm-bundler.js:4703
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
Uncaught (in promise) Error: Invalid solution
    solve widget.js:1
    addEventListeners widget.js:1
    addEventListeners widget.js:1
    connectedCallback widget.js:1
    insert runtime-dom.esm-bundler.js:28
    mountElement runtime-core.esm-bundler.js:4925
    processElement runtime-core.esm-bundler.js:4851
    patch runtime-core.esm-bundler.js:4717
    mountChildren runtime-core.esm-bundler.js:4963
    mount runtime-core.esm-bundler.js:824
    mountToTarget runtime-core.esm-bundler.js:846
    process runtime-core.esm-bundler.js:868
    patch runtime-core.esm-bundler.js:4741
    patchKeyedChildren runtime-core.esm-bundler.js:5761
    patchChildren runtime-core.esm-bundler.js:5543
    processFragment runtime-core.esm-bundler.js:5187
    patch runtime-core.esm-bundler.js:4703
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
    componentUpdateFn runtime-core.esm-bundler.js:5438
    run reactivity.esm-bundler.js:237
    updateComponent runtime-core.esm-bundler.js:5289
    processComponent runtime-core.esm-bundler.js:5224
    patch runtime-core.esm-bundler.js:4729
widget.js:1:4198

Fix: Using the CDN script.

This: <script src="https://cdn.jsdelivr.net/npm/@cap.js/widget"></script>
Instead of: <script src="https://<server url>/assets/widget.js"></script>

Affects:

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

To Reproduce Steps to reproduce the behavior:

  1. Include the self-hosted widget.js in the index.html:
<script src="https://<server url>/assets/widget.js"></script>
  1. Go to 'the widget'
  2. Click on 'the checkbox labeled "I'm a human"'
  3. See error

Expected behavior Clicking the checkbox should challenge the user.

Screenshots

Image

Desktop (please complete the following information):

  • OS: [Cap Standalone on Raspberry Pi with Docker, demo-page on windows(localhost)]
  • Browser [Firefox]
  • Version [140.0.2]

saufdermaur avatar Jul 04 '25 20:07 saufdermaur

You're most likely using an outdated version of the widget.

Can you try setting the widget version env variables to the latest version of the widget npm package and then manually deleting the assets cache files? (they're in the .data folder)

tiagozip avatar Jul 05 '25 06:07 tiagozip

I'm having a similar issue with @cap.js/checkpoint-express. The challenge fails with "Invalid solution" in Firefox and Chrome, but if I refresh I pass through.

I see the built-in template uses an old version of the widget (v0.1.17): https://github.com/tiagozip/cap/blob/main/checkpoints/template.html#L166

Let me know if I should open a new issue. Thanks!

alanorth avatar Aug 10 '25 09:08 alanorth

most likely a new issue, feel free to open it.

tiagozip avatar Aug 12 '25 06:08 tiagozip