If the page has more than one frame, frames will conflict and the count for the last frame processed is the one that is going to prevail for that tab.
Clever way to fix it: instead of having the foreground script ask for scripts, the background script will listen for tab switching activities. When one happens, it will check if the tab has already loaded Witchcraft scripts. If it has, do nothing; if it hasn't load them now for each and every frame in the tab. That way we can easily count how many scripts were loaded through all frames at once (question: how do we find all the existing frames? And how do we inject scripts in the frames without them asking?).
If the page has more than one frame, frames will conflict and the count for the last frame processed is the one that is going to prevail for that tab.
Clever way to fix it: instead of having the foreground script ask for scripts, the background script will listen for tab switching activities. When one happens, it will check if the tab has already loaded Witchcraft scripts. If it has, do nothing; if it hasn't load them now for each and every frame in the tab. That way we can easily count how many scripts were loaded through all frames at once (question: how do we find all the existing frames? And how do we inject scripts in the frames without them asking?).
The other easier way would be to make a note of the frame id as requests arrive (https://developer.chrome.com/extensions/runtime#type-MessageSender) and add them to a set by tab id.