user730569
user730569

Reputation: 4004

How does Facebook manage to kill javascript when going to a new page?

Try this.

Type this code into your browser console on the homepage of Facebook (your Facebook feed):

setInterval(function(){console.log('blah')}, 100)

Then navigate to the "Messages" or "Events" section of the website. Notice that the whole page is not reloaded and the new html content is inserted dynamically with javascript. However, somehow Facebook cancels the setInterval. This also happens with setTimeout.

How is this happening?

Upvotes: 2

Views: 156

Answers (1)

user730569
user730569

Reputation: 4004

Turns out that Facebook is overriding the native setTimeout and setInterval functions with their own. You can see this by typing setTimeout into your browser console and it will return a function different from the typical native code function. Facebook therefore has access to all setTimeouts on the page, even ones by third party code, and can therefore clear them all when you access a new page (or whenever they want, really).

Upvotes: 2

Related Questions