james-fray / tab-reloader

Multiple-browser tab reloader extension
https://webextension.org/listing/tab-reloader.html
107 stars 31 forks source link

The page updates when it wants (time interval is ignored) #169

Open advanc3dUA opened 1 month ago

advanc3dUA commented 1 month ago

Hello,

First, I want to say that the flexibility of the extension is right I was searching for. Thanks a lot for your work.

But I have a few things which I can't get over by myself:

  1. It doesn't matter which URL, period, or which way I start the job - the extension refreshes the tab randomly. For example: with 20 seconds set I get the first reload in time (not every time but mostly) but then the next few are skipped. After that, the tab could be updated when the timer hits 0 or even in the middle of the timer. The same behavior at MacOS with the latest Chrome and Raspberry OS with Chromium - also fully updated to the latest version. What am I doing wrong?

Here is my simple example:

[
  {
    "dd": 0,
    "hh": 0,
    "hostname": "www.mydomain.com",
    "mm": 0,
    "ss": 20,
    "visual-countdown": true
  }
]
  1. I want to get full automation of the refresh process, so I need to set my tab to update only from Monday until Saturday, from 7:00 until 21:00. I don't need updates at night and on Sunday. Is it possible to get with Tab Reloader? On the FAQ page, I have found, that for testing in the console, I should use ".test('10/7/2019, 2:47:35 PM')" format. Is it possible to turn on the full date with the day of the week in the extension to be able to check it too?

If the day of the week is not supported yet, then it would be awesome to see this in the next updates. If it is already supported, please explain how it should be used.

Cheers.

james-fray commented 1 month ago

This extension uses Chrome's built-in timer to notify you when a refresh is needed. It appears that Chrome's scheduling may be inaccurate in your case. In the latest commit, I've added a method for the visual counter to alert the worker when the countdown is complete. Please try the "v3" directory of this repository in the developer mode and report back.

I want to get full automation of the refresh process

The extension supports "Policy Code". You can write a simple JS to let the extension know if the refresh is needed or not. You can use the "new Date()" to find if the time is in the range or not.

advanc3dUA commented 1 month ago

With v3 I get updates in time, whenever the timer hits 0:00. Looks good but Chrome says (on the extension's page) that there is a problem with the extension on line 117 of worker.js. The line is: "api.tabs.countdown(tab.id, request.profile.period).catch(e => console.error(e));".

UPDATE: I have found the solution, I need the page to be permitted to access.

Regarding my schedule problem: I try something like this:

{
  "www.mydomain.com/*": {
    "date": "(function() { const currentDate = new Date(); const day = currentDate.getDay(); const hours = currentDate.getHours(); const isWorkingDay = day >= 1 && day <= 6; const isWorkingHours = hours >= 7 && hours < 21; return isWorkingDay && isWorkingHours; })()"
  }
}

Unfortunately, it doesn't work. Do I have to put it in another place or I got your hint wrong? :)

advanc3dUA commented 1 month ago

Ooooookey. I have all understood. At first, I tried to add the code to the "code" key in the "Custom Jobs" section. It works but after the page is reloaded. Then I found in FAQ that if I want to preload the code, I have to add it to the "Run Policy Code" and to use it, I need to activate it in the popup. After saving it as the custom job I have found, that the code should be saved in "pre-code". So, it seems to be good for now because today is Sunday and the Tab Reloader is skipping reloads.

Btw, in the FAQ there is no information about the "pre-code" key, only that I can add it in the popup. Should it be there? Up to you.

Maybe someone will find it useful, so here is my example. Works only from 7:00 until 21:00, Sunday is a day off:

[
  {
    "blocked-words": "",
    "cache": false,
    "current": false,
    "discarded": false,
    "form": false,
    "hh": 0,
    "hostname": "put_the_domain_here",
    "mm": 0,
    "nodiscard": false,
    "nofocus": false,
    "offline": false,
    "pre-code": "(function() { const currentDate = new Date(); const day = currentDate.getDay(); const hours = currentDate.getHours(); const isWorkingDay = day >= 1 && day <= 6; const isWorkingHours = hours >= 7 && hours < 21; console.log('Current day: ' + day + ', Current hour: ' + hours); console.log('Is working day: ' + isWorkingDay + ', Is working hours: ' + isWorkingHours); document.currentScript.dataset.continue = (isWorkingDay && isWorkingHours) ? 'true' : 'false'; })();",
    "randomize": false,
    "scroll-to-end": false,
    "sound": false,
    "sound-value": "1",
    "ss": 10,
    "switch": false,
    "variation": 0,
    "visual-countdown": true
  }
]
ray-lothian commented 1 month ago

there is a problem with the extension on line 117 of worker.js

Do you have the error log?

ray-lothian commented 1 month ago

Btw, in the FAQ there is no information about the "pre-code" key, only that I can add it in the popup. Should it be there? Up to you.

Since the extension's popup now creates the code for the user, there is no need for manually generating the JSON object. Anyhow, I'll update the FAQs page.

advanc3dUA commented 1 month ago

there is a problem with the extension on line 117 of worker.js

Do you have the error log?

That is not necessary. The small problem is that for some reason the v3 version doesn't ask for the permissions automatically (both at MacOS + Chrome and Raspberry OS + Chromium), therefore I got that error. However after the "Host permission" button is clicked manually, the error no longer appears.

Since the extension's popup now creates the code for the user, there is no need for manually generating the JSON object. Anyhow, I'll update the FAQs page.

As for me, writing a long script in the popup window is not very comfortable. Having information about the "pre-code" key in the FAQ will make it clearer for weirdos like me :).