Reputation: 46
I'm using the Chrome Extension Custom JavaScript for Websites 2
to inject some simple JavaScript into each webpage I visit. I want to be able to run some code one time when the page is done loading. I've been using window.onload = myFunction
however looking at the console output, I noticed that my function is being called multiple times. Depending on the webpage, my function is being called anywhere from 2 to 6 times. I have no clue why this would be happening. Even if my code was executing multiple times, it should just be resetting the onLoad handler, not actually calling my function right?
Current code that I'm injecting:
function ready(){
console.log('page loaded');
}
window.onload = ready;
Upvotes: 0
Views: 1054
Reputation: 46
wOxxOm gave me the correct answer in the comments.
"You must be using all_frames parameter in manifest.json which runs your content script in each iframe."
After creating my own extension to inject code, I no longer had this issue.
Upvotes: 1