Execute javascript on web page in background

You might want to take a look at this

It's for Chrome but you might get something useful out of it.