I am writing a Chrome extension that scrapes data from Twitter, specifically from twitter.com/following, using a content script. I want to run this in a tab/window that is not active or visible to the user, so as to not be disruptive.
Now, Twitter loads much of its content using scripts, so I am using MutationObserver
and window.scrollBy
to force the content to load. This works perfectly fine when the tab is visible. However, when the tab is not visible (inacive tab or window that is minimized/offscreen), it does not work. Firstly, the setInterval
timers get throttled to once a second. I did some research and I think I can fix this using requestAnimationFrame
, but have not tested yet. The more pressing problem is that the content that I am looking for, ie. the list of followed accounts, no longer gets loaded by Twitter's scripts.
I have tried to spoof the tab as always visible using this code snippet, but it did not fix the issue.
Object.defineProperty(document, "visibilityState", {
get() {
return "visible";
}
});
document.addEventListener("visibilitychange", function(e) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
});
Is there any way to give non-visible tabs the functionality of visible tabs, if temporarily?
PS: I know that Twitter has an API, but I would prefer to not have to deal with hosting an application if I can avoid it.