Caddy fileserver does not remember position when using back-button on browser

1. Caddy version:

v2.4.3 h1:Y1FaV2N4WO3rBqxSYA8UZsZTQdN+PwcoOcAiZTM8C0I=

2. How I run Caddy:

a. System environment:

systemd, Caddyfile

b. Command:

systemctl start caddy

c. Service/unit/compose file:

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target

d. My complete Caddyfile or JSON config:

:8888 {
    root * /var/www

    templates

    @listing {
        path_regexp ^/(temp/.+|etc)(/.*)?$
    }

    handle @listing {
        file_server * browse
        basicauth /etc/secret/* {
            user pass
        }
    }

    handle {
        respond 403 {
            close
        }
    }

    log
}

3. The problem I’m having:

  1. open caddy-example in browser
  2. scroll to bottom
  3. open folder 100
  4. go back

What should happen?

What happens?

  • Position returns back to top.

4. Error messages and/or full log output:

No error log, just wrong behaviour with default template.

5. What I already tried:

I’ve read through relevant documentation and tried to find file listing template that works properly, but my search skills are failing me.

6. Links to relevant resources:

https://github.com/caddyserver/caddy/blob/master/modules/caddyhttp/fileserver/browsetpl.go

I can’t replicate the issue.

Are you clicking the “Go up” link, or are you clicking the back button in your browser?

If you click “Go up”, then it makes a new request with fresh state, going forwards in history, so the scroll position will be lost.

If you click the back button in your browser, then your browser will restore the state from the previous page and go backwards one step in your history.

This has nothing to do with the template itself, this is just how browsers work.

Back button. Tried now with different browsers:

Works: firefox (desktop and android).

Doesn’t work: Chrome (desktop and android), Opera (desktop)

1 Like

I wouldn’t go as far as saying that template has nothing to do with this. Since there’s definitely something in the implementation that prevents chromium-based browsers working correctly when restoring state (go back/forward)

Edit: I removed the script-block from page source and now history works.

Example (copied template generated html by hand, with script-block removed): caddy-example (katiska.dy.fi)

Edit: It seems to be this line filterEl.focus(); caddy/modules/caddyhttp/fileserver/browsetpl.go at a2119c09e95eeb871c2b30046f596d61257b108c · caddyserver/caddy · GitHub

Edit Fix

Seems to be fixed by adding preventScroll=true

i.e. filterEl.focus({preventScroll:true});

Interesting. Thanks for going the extra step of tracking down the cause :+1:

This topic was automatically closed after 30 days. New replies are no longer allowed.