My approach ended up being different from what was proposed on #1. I decided to, instead of storing the script count, storing script names in a set instead. That way the script can just add new script names to the set and, in case they were already loaded by another frame in the same tab, we still won't count them more than once. The second necessary change is to clear that set whenever a new request for frameId 0 (i.e., the top frame on that tab) is made. This way we can know when a page refresh is taking place, so we can invalidate the previous set of script names and the count will always be consistent.
My approach ended up being different from what was proposed on #1. I decided to, instead of storing the script count, storing script names in a set instead. That way the script can just add new script names to the set and, in case they were already loaded by another frame in the same tab, we still won't count them more than once. The second necessary change is to clear that set whenever a new request for frameId 0 (i.e., the top frame on that tab) is made. This way we can know when a page refresh is taking place, so we can invalidate the previous set of script names and the count will always be consistent.