Howard
Howard

Reputation: 35

Why content.js load twice or more when in facebook.com with chrome extension?

I have a chrome extension. The manifest.json is

"content_scripts": [ 
    {
        "all_frames": true,
        "js": [ "content.js" ],
        "css": ["style.css"],
        "matches": [ "*://www.facebook.com/*"],
        "run_at": "document_start"
    }, 

The content.js just is

console.log("say hi");

And console is Please see this picture https://i.sstatic.net/SRrkv.png

It called four times. It just happened in facebook.com, not happened in other website such as www.google.com. Any idea? Thanks.

Upvotes: 1

Views: 102

Answers (2)

zkwentz
zkwentz

Reputation: 1105

You've specified all_frames: true. There's likely a few iframes on the page causing content.js to be executed multiple times.

Upvotes: 0

Drew
Drew

Reputation: 2299

I'm not sure if Facebook uses frames, but if it does it is possible that there are four frames that are executing your code once each. Chrome console doesn't give any visual indication that this is what is happening. Try setting all_frames to false so that it only executes on the top frame.

Upvotes: 1

Related Questions