1

I, like many, learnt how to use Google Chrome extensions to inject scripts into pre-existing webpages from Rob W's excellent answer here.

One thing I've become curious about is this part of his code:

s.onload = function() { this.remove(); };

Why do we need to remove the script after injecting it? I can't seem to find an answer.

Community
  • 1
  • 1
user5508297
  • 805
  • 2
  • 9
  • 24

1 Answers1

2

I believe it's an attempt to reduce observable side-effects.

E.g. a webpage might have some code to check how many script tags are on the page, or expect a certain number of script tags to be present.

In practice it probably doesn't matter at all whether you remove the injected script or not.

kzahel
  • 2,765
  • 1
  • 22
  • 31