How to prevent idle state?

Introduction

I am writing my very first Firefox Extension and I got an issue where my content_script.js goes into idle state.

The purpose of my extension is very simple - click a button on youtube.com whenever the user is asked “Video paused. Continue watching?”. I do that by adding an event listener to the pause event of the video element and then search for the button. If the button is found, it is clicked.

"host_permissions": [
	"https://*.youtube.com/watch*"
],
"content_scripts": [{
	"matches": [
		"https://*.youtube.com/watch*"
	],
	"js": ["content_script.js"]
}]

manifest.json

However, if the browser window is minimized or the tab is not focused, the tab can go into “idle” mode and the video pause event is not caught. Or not emitted - I don’t know. But the music/video stops and as soon as I bring the Window or browser tab into focus (e.i. displayed) then the button is clicked and the video continue.

Question

  1. How do I prevent an extension from going into idle mode?
  2. Is the video element pause event emitted if the tab is in idle mode? Though the video does pause.

Other resources

I’ve read up on Background page but the background page seem to go into idle mode immediately and it’s not clear how that would solve the problem with the pause event on a video element on a page.

“Event Pages”, seems to be another name for “Background pages”.

Service workers are not supported in Firefox.

1 Like

I’d love to know that too, I have the same problem currently, with my background event page getting killed while my async background task is running :frowning: