Repository: OctoPrint/OctoPrint

Issue:
Webcam stream not loading
### The problem

The webcam stream isn't loading even though it's configured properly. Clicking the configured url link and the test button in settings work. 

GitHub keeps deleting my images so here's an imgur link I guess https://imgur.com/a/7wgjapi 

### Did the issue persist even in safe mode?

Yes, it did persist

### If you could not test in safe mode, please state why

_No response_

### Version of OctoPrint

1.5.3

### Operating system running OctoPrint

Raspian 10 Buster NOT octopi

### Printer model & used firmware incl. version

_No response_

### Browser and version of browser, operating system running browser

Chromium Edge, Brave, Firefox, mobile Safari

### Checklist of files to include below

- [X] octoprint.log
- [ ] serial.log or contents of your terminal tab (always include in cases of issues with printer communication)
- [X] Contents of the JavaScript browser console (always include in cases of issues with the user interface)
- [X] Screenshots and/or videos showing the problem (always include in case of issues with the user interface)
- [ ] GCODE file with which to reproduce (always include in case of issues with GCODE analysis or printing behaviour)

### Additional information & file uploads

octoprint.log: https://drive.google.com/file/d/1ibIms_IVGcAKo-Kkd9Gip-VR1jH795kq/view?usp=sharing
chrome console log: https://drive.google.com/file/d/18AWleeEC2xYrhQuFnauxox7PFFtmkWTk/view?usp=sharing



Discussion:
I am having this exact same issue.

Running Octoprint 1.5.3 installed using the manual steps on existing Pi4 running Raspberry Pi OS.
Please also upload the logs (JS console) and make sure it still works just going to the URL on its own.
@cp2004 Yes, if I click the URL that the webcam stream box says does not work, my .mjpg stream works fine immediately.
[octoprint.log](https://github.com/OctoPrint/OctoPrint/files/6370378/octoprint.log)

I just figured it out, looking at the log from my camera host (python script) I saw the line:
`192.168.18.133 - - [24/Apr/2021 15:15:57] code 404, message Not Found
192.168.18.133 - - [24/Apr/2021 15:15:57] "GET /stream.mjpg?1619291757638 HTTP/1.1" 404 -`

So I modified my camera server to ignore anything after the .mjpg (the number that octoprint adds)

Why does octoprint append this "?1619291757638" to the stream path?
> Why does octoprint append this "?1619291757638" to the stream path?

This is what's known as a cache buster... to force a reload I'd the file bypassing any local browser cache, very common. 
@charlespick do you have the same issue here, with the additional cache-buster? What webcam server are you using?

You could also post your reverse proxy configuration (is it haproxy?).
> > Why does octoprint append this "?1619291757638" to the stream path?
> 
> This is what's known as a cache buster... to force a reload I'd the file bypassing any local browser cache, very common.

Cool, I feel very lucky to have stumbled upon the actual issue here.  If there was a checkbox in the webcam/stream settings of octoprint to enable/disable cache busting I probably would have toggled it and figured it out within a few minuets of intial setup.  Then again, if we are the first two people to encounter this issue then it may not be worth the change.
You aren't the first, there's a bunch of requests here already, but so far no one has done anything about it. It shouldn't be too difficult to implement, I have it on my list of potential PRs.

If anyone wants to give it a go, the relevant setting needs plumbing in and adjusting here:

https://github.com/OctoPrint/OctoPrint/blob/6c0176455bd80551bcf473e424cd56f5aab04254/src/octoprint/static/js/app/viewmodels/control.js#L696

Maybe different for the timelapse as well, if it covers that. Just make sure you don't have a cache issue otherwise.
**mfurey** has contributed **$50.00** to [this issue](https://rysolv.com/issues/detail/435fe44a-daca-4bbb-b15d-eb9b709367c3) on Rysolv.<br/><br/>    The total bounty is now **$50.00**. Solve [this issue](https://rysolv.com/issues/detail/435fe44a-daca-4bbb-b15d-eb9b709367c3) on Rysolv to earn this bounty.<br/>  
I've run into this one as well. Not been a huge blocker, but it would be nice to have a cache_busting toggle somewhere. 
I added a $50 bounty if anyone is interested!


Resolving patch:
diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py
--- a/src/octoprint/server/api/settings.py
+++ b/src/octoprint/server/api/settings.py
@@ -139,6 +139,7 @@ def getSettings():
             "flipH": s.getBoolean(["webcam", "flipH"]),
             "flipV": s.getBoolean(["webcam", "flipV"]),
             "rotate90": s.getBoolean(["webcam", "rotate90"]),
+            "cacheBuster": s.getBoolean(["webcam", "cacheBuster"]),
         },
         "feature": {
             "temperatureGraph": s.getBoolean(["feature", "temperatureGraph"]),
@@ -593,6 +594,8 @@ def _saveSettings(data):
             s.setBoolean(["webcam", "flipV"], data["webcam"]["flipV"])
         if "rotate90" in data["webcam"]:
             s.setBoolean(["webcam", "rotate90"], data["webcam"]["rotate90"])
+        if "cacheBuster" in data["webcam"]:
+            s.setBoolean(["webcam", "cacheBuster"], data["webcam"]["cacheBuster"])
 
     if "feature" in data:
         if "temperatureGraph" in data["feature"]:
diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py
--- a/src/octoprint/settings.py
+++ b/src/octoprint/settings.py
@@ -265,6 +265,7 @@ def settings(init=False, basedir=None, configfile=None, overlays=None):
             "fps": 25,
         },
         "cleanTmpAfterDays": 7,
+        "cacheBuster": False,
     },
     "gcodeAnalysis": {
         "maxExtruders": 10,


Test patch: