james-fray / tab-reloader

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

Feature request : simulate a KeyPress in injected scripts with script.dispatchEvent (new KeyboardEvent...) #172

Open ighaouar opened 2 days ago

ighaouar commented 2 days ago

Hi,

Is it possible to add "KeyboardEvent" as a supported action in injected scripts to simulate a KeyPress.

Example:

{ const script = document.currentScript; const event = new KeyboardEvent('keydown', { key: 'a', // The key you want to simulate bubbles: true, // Whether the event bubbles up through the DOM cancelable: true // Whether the event is cancelable});

window.setTimeout(() => { script.dispatchEvent(event)); }, 500); }

james-fray commented 1 day ago

The code you provided should work. What is the problem?

ighaouar commented 1 day ago

I am trying to send any key to the tab or any mouse move to avoid an idle timeout but it doesn't work.

james-fray commented 1 day ago

If you simulate a click, browser ignores it. There is no way to fix this. If you are on Chrome, use https://chromewebstore.google.com/detail/caffeine-keep-awake/fcblbbbkcneogddmpmfdchnocbpfpmag

ighaouar commented 1 day ago

By "idle timeout", I meant that I am signed into a website and I am logged out after 15 minutes when I am not browsing or not moving my mouse in the corresponding browser tab.

I was not referring to a windows session lock or a system entering to hibernation mode.