Skip to content
Advertisement

Userscript works only on pages served from backend, but not on frontend in a SPA way

I have the following userscript I run on Greasemonkey/Tampermonkey.

I run it on facebook.com which serves some of the webpages from backend, in bootstrapping, and some others on the fly, in front-end, via HRO, just as a Single Page Application (SPA) would.

JavaScript

If I run this script on console, even in HRO based webpages, it runs fine, but when runned from Greasemoneky/Tampermonkey it won’t run in these particular webpages.

How could I make the script to work without problem on SPA-like webpages as well?

Advertisement

Answer

In such a case when setTimeout, setInterval, and event delegation doesn’t work by themselves, it is possible to push a state that implements them into the memory, then replacing the existing state with it, so that the webpage’s DOM content will change.

Here’s a code used to replace data that was loaded with AJAX instead directly from PHP:

JavaScript

That’s what I understood from reading here.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement