topeterk / HitCounterManager

Free Hit Counter / Death Counter that is running in the background, so you can focus on your stream. No need to keep any windows open for a window capture any more. Initially designed for Dark Souls and similar games but supports any game.
MIT License
87 stars 19 forks source link

HitCounterGui.html does not update when using http url from remote machine. #20

Closed hooddanielc closed 3 years ago

hooddanielc commented 3 years ago

Describe the bug OBS browser does not update when using http url (ex. http://192.168.169.69:8800/Designs/HitCounterGui.html because chromium embedded framework caches http responses.

To Reproduce Steps to reproduce the behavior:

  1. Launch static http server serving static files where root path point to directory containing Designs folder.
  2. Launch latest obs on linux with obs-browser plugin installed
  3. Display the browser source in the scene

Expected behavior The page is updated when the iframe is reloaded.

Additional context

I was able to fix this issue by changing

 iframe.src = '../HitCounter.html';

to call a hardRefreshIframe() function

hardRefreshIframe();

definition of hardRefreshIframe

var iframe;
function hardRefreshIframe() {
    if (!iframe) {
        iframe = document.getElementsByTagName('iframe')[0];
    }
    if (iframe.contentWindow.location.href.indexOf('HitCounter.html') >= 0) {
        // force hard refresh
        iframe.contentWindow.location.reload(true);
    } else {
        iframe.src = '../HitCounter.html';
    }
}
hooddanielc commented 3 years ago

I can make a pr if that is ok. Also would like to know where the change should be made.

topeterk commented 3 years ago

Hi, I need to check first if this works in most common browsers or have you checked that already? I'm testing on Opera, Firefox, InternetExplorer, Edge, Chrome and I also check TwitchStudio, OBS, OBS Studio and StreamLabs.

I also thought, if it might be better to use meta tags in order to disable caching as when the tag is unknown it will be ignored, but if javascript is not known it most likey crashes/breaks the whole thing.

hooddanielc commented 3 years ago

I agree javascript change is risky. The only api that might not have much support is the window.location.reload api, which is available on caniuse.com's support tables it's supported on all browsers except the ones that it has not checked, which appear to be mobile browsers.... Opera Mini, UC Browser for Android, QQ Browser, Baidu Browser, KaiOS Browser looks like it is supported on IE6 too. The support tables for location.href are the same