idle-js icon indicating copy to clipboard operation
idle-js copied to clipboard

Iframe support

Open joeheyming opened this issue 5 years ago • 6 comments

I tried this library out. It is great, but I need a way to listen to click/keypress events on an iframe as well.

joeheyming avatar Jul 15 '20 18:07 joeheyming

I was able to hack it to get iframes to work:

idle.settings.events.forEach(event => {
  iframe.contentWindow.addEventListener(event, idle.idlenessEventsHandler)
});

I'm sure this could easily be a flag or 'querySelector' driven config.

e.g. targetIframes: ['#myframe']

fwiw, I ran the code above after the iframe was loaded, so that might be a reasonable assumption

joeheyming avatar Jul 15 '20 19:07 joeheyming

Hello, It's a nice improvement. I would be happy to know more about the use case.

gabrielstuff avatar Jan 06 '22 00:01 gabrielstuff

My users interact with inner iframes and I want to be able to detect click and mouse interaction inside the iframe as well as outside it. I'm using this to keep a user's login alive when they are not idle.

joeheyming avatar Jan 06 '22 00:01 joeheyming

ok ! Made minor changes but might impact your project if you support IE11. Will publish on npm this updated version, mostly because it is lighter and I'd like to add the two features you suggested.

gabrielstuff avatar Jan 06 '22 01:01 gabrielstuff

thanks for doing this. I'm fine with my workarounds for now, but I hope this helps others in the future.

joeheyming avatar Jan 06 '22 17:01 joeheyming

Note: This addEventListener will only catch iframes events which share the same origin.

PS: You might need to watch via mutationObserver for new iframe elements.

HolgerJeromin avatar Jan 24 '23 13:01 HolgerJeromin