Content Scripts Running Multiple Times on Certain WebPages

1,613 views
Skip to first unread message

Hecktarzuli

unread,
Mar 9, 2010, 3:27:42 PM3/9/10
to Chromium-extensions
I'm wondering if I'm just missing something. I have a simple test:

{
"name": "Blah",
"version": "1.0",
"description": "Blarg",
"permissions": ["http://*/", "https://*/"],
"content_scripts": [ {
"js": [ "foo.js" ],
"matches": [ "http://*/*" ],
"runat" : "document_end",
"all_frames" : false
} ]
}

..
foo.js
alert("foo href = " + location.href);

And the alert is showing up multiple times on certain web pages. What
gives?

Joshua Deltener

unread,
Mar 9, 2010, 3:47:43 PM3/9/10
to Chromium-extensions
Even for pages that run it once, if i go somewhere and hit back it
does it twice. Am I missing something?

Arne Roomann-Kurrik

unread,
Mar 9, 2010, 5:58:29 PM3/9/10
to Joshua Deltener, Chromium-extensions
I'm not able to reproduce this using a simple test extension.  Which version of chrome are you using?  Which URLs are you testing?

~Arne


On Tue, Mar 9, 2010 at 12:47 PM, Joshua Deltener <heckt...@gmail.com> wrote:
Even for pages that run it once, if i go somewhere and hit back it
does it twice.  Am I missing something?

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.


Joshua Deltener

unread,
Mar 9, 2010, 10:11:20 PM3/9/10
to Chromium-extensions
Using my own example, this very page alerts me twice as well as:

http://groups.google.com/a/chromium.org/group/chromium-extensions/topics
http://code.google.com/chrome/extensions/getstarted.html
http://code.google.com/chrome/extensions/index.html
http://validator.w3.org/ randomly goes from 1 to 2 when your refresh
(ctrl-r)
A number of other pages were doing it too..

I'm using Windows XP, SP2, Chrome "4.1.249.1025 unknown (40600)"

Ronald Schouten

unread,
Mar 9, 2010, 10:26:17 PM3/9/10
to Joshua Deltener, Chromium-extensions
I am also experiencing my content script being executed multiple times. In my case it is a content script that runs in Gmail and every time the hashcode changes, an additional content script is visible in the developer tools. I don't have a simplified test case (sorry, no time) and I am on Win7 5.0.342.2 (Official Build 40685dev.

As a work around, I wrap my content script in an if statement like the following:

if (window.inititalized)
{
  window.initialized = true;
  
  // do code
}

So at least the multiple content scripts are sharing the same world. This should also degrade nicely when/if the bug is fixed.

Ron


--

Joshua Deltener

unread,
Mar 9, 2010, 10:47:21 PM3/9/10
to Chromium-extensions
Ron, have you submitted a bug somewhere?

Mohamed Mansour

unread,
Mar 9, 2010, 11:01:47 PM3/9/10
to Joshua Deltener, Chromium-extensions
The random instances might be similar to this bug:

If its different, can you please open a new bug in crbug.com/new and I will tag it appropriately. And if you have a reduction test case (code), that would be very useful as well.

-
Mohamed Mansour
m...@chromium.org


On Tue, Mar 9, 2010 at 10:47 PM, Joshua Deltener <heckt...@gmail.com> wrote:
Ron, have you submitted a bug somewhere?

--

Ronald Schouten

unread,
Mar 10, 2010, 1:01:47 AM3/10/10
to Joshua Deltener, Chromium-extensions
Yes, and the problem seems t be fixed when I tested the latest trunk build of chromium.


Ron

On Tue, Mar 9, 2010 at 7:47 PM, Joshua Deltener <heckt...@gmail.com> wrote:
Ron, have you submitted a bug somewhere?

--

Arne Roomann-Kurrik

unread,
Mar 10, 2010, 12:17:46 PM3/10/10
to Ronald Schouten, Joshua Deltener, Chromium-extensions
Yeah, I wasn't able to reproduce on linux 5.0.342.1 dev.

~Arne

Scott

unread,
Mar 9, 2010, 6:24:17 PM3/9/10
to Chromium-extensions
runat should be run_at. Could be parsing all_frames weird after that,
leading to it alerting extra times if frames are present. But that is
just a shot in the dark.

On Mar 9, 4:58 pm, Arne Roomann-Kurrik <kur...@chromium.org> wrote:
> I'm not able to reproduce this using a simple test extension.  Which version
> of chrome are you using?  Which URLs are you testing?
>
> ~Arne
>

> On Tue, Mar 9, 2010 at 12:47 PM, Joshua Deltener <hecktarz...@gmail.com>wrote:
>
>
>
> > Even for pages that run it once, if i go somewhere and hit back it
> > does it twice.  Am I missing something?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Chromium-extensions" group.

> > To post to this group, send email to chromium-extensi...@chromium.org.


> > To unsubscribe from this group, send email to

> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>

Joshua Deltener

unread,
Mar 10, 2010, 10:54:27 PM3/10/10
to Chromium-extensions
Even if I remove runat completely I still get it.

I've also confirmed this is still a problem in today's Chrome update
(4.1.249.1030) so hopefully the "fix" isn't in this yet..

tech4computer

unread,
Mar 10, 2010, 11:05:02 PM3/10/10
to Chromium-extensions
A while back I was having this same issue. Instead of waiting for the
Chrome team to find the problem and fix it. I suggest you declare a
global variable and in beginning of your script just check if the
variable is already defined. Or if you are modifying the DOM then can
check if the modification is already performed.

Antony Sargent

unread,
Mar 11, 2010, 1:33:42 PM3/11/10
to Joshua Deltener, Chromium-extensions
This sounds like crbug.com/35924 which is fixed in trunk and the latest dev build, but the problem wasn't deemed critical enough (since there is a workaround of setting a global variable to ensure your code only runs once) to get the fix into the 4.1 branch.


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
Reply all
Reply to author
Forward
0 new messages