Content scripts are not loaded for some page loads

7,588 views
Skip to first unread message

Greg Cooksey

unread,
Aug 23, 2010, 6:03:52 PM8/23/10
to Chromium-extensions
I'm seeing an issue where my content script is not loaded for page
loads that just add a fragment to the end of the URL. The following
sample extension exhibits this problem:

manifest.json:
{
"name": "Lost content script repro",
"version": "1.0",
"description": "Reproduces lost content script bug",
"content_scripts" : [
{
"matches": ["http://*.google.com/*"],
"js": ["repro.js"],
"run_at": "document_start"
}
]
}

repro.js:

alert("Content script loaded");

window.addEventListener("load", function () {
alert("Ready state changed");
}, false);

---

If I load www.google.com the alert boxes appear as expected. If I then
type "test" into the search box and press enter, the alert boxes do
not appear when the results page loads.

I've tested with a more complex extension to verify this. If I
sendRequest from my background page to my content script when the
chrome.tabs.onUpdated event fires, I get no response from the content
page when the search results page loads.

Has anyone else seen this issue? I'd appreciate any ideas for getting
around it.

PhistucK

unread,
Sep 6, 2010, 9:26:04 AM9/6/10
to Greg Cooksey, Chromium-extensions
Maybe the search is happening through AJAX, so no load event is triggered?

PhistucK




--
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.


Greg Cooksey

unread,
Sep 7, 2010, 10:02:06 AM9/7/10
to Chromium-extensions
A chrome.tabs.onUpdated event is definitely being triggered. My
workaround has been to inject the content script in response to that
event.

I will report this as a bug. If the browser unloads content scripts,
it should load them again.

-Greg

On Sep 6, 8:26 am, PhistucK <phist...@gmail.com> wrote:
> Maybe the search is happening through AJAX, so no load event is triggered?
>
> ☆*PhistucK*
>
>
>
> On Tue, Aug 24, 2010 at 01:03, Greg Cooksey <cook...@artoftest.com> wrote:
> > I'm seeing an issue where my content script is not loaded for page
> > loads that just add a fragment to the end of the URL. The following
> > sample extension exhibits this problem:
>
> > manifest.json:
> > {
> >    "name": "Lost content script repro",
> >    "version": "1.0",
> >    "description": "Reproduces lost content script bug",
> >    "content_scripts" : [
> >        {
> >            "matches": ["http://*.google.com/*"],
> >            "js": ["repro.js"],
> >            "run_at": "document_start"
> >        }
> >    ]
> > }
>
> > repro.js:
>
> > alert("Content script loaded");
>
> > window.addEventListener("load", function () {
> >    alert("Ready state changed");
> > }, false);
>
> > ---
>
> > If I loadwww.google.comthe alert boxes appear as expected. If I then
> > type "test" into the search box and press enter, the alert boxes do
> > not appear when the results page loads.
>
> > I've tested with a more complex extension to verify this. If I
> > sendRequest from my background page to my content script when the
> > chrome.tabs.onUpdated event fires, I get no response from the content
> > page when the search results page loads.
>
> > Has anyone else seen this issue? I'd appreciate any ideas for getting
> > around it.
>
> > --
> > 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>
> > .

PhistucK

unread,
Sep 7, 2010, 10:57:53 AM9/7/10
to Greg Cooksey, Chromium-extensions
If it goes through AJAX to get the result, it usually replaces the hash of the URL (stuff after the "#" sign). So that may be the reason for the onUpdated triggering. Though, I do not think Chrome is ever "unloading" the content script if the page has not actually navigated.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Greg Cooksey

unread,
Sep 7, 2010, 11:01:47 AM9/7/10
to Chromium-extensions
After the search, my background page does not get any responses from
my content script, so I assume that the content script is no longer
loaded in the tab. I don't know how else to check for its presence.

I have logged this as issue 54693 (http://code.google.com/p/chromium/
issues/detail?id=54693)

-Greg

On Sep 7, 9:57 am, PhistucK <phist...@gmail.com> wrote:
> If it goes through AJAX to get the result, it usually replaces the hash of
> the URL (stuff after the "#" sign). So that may be the reason for the
> onUpdated triggering. Though, I do not think Chrome is ever "unloading" the
> content script if the page has not actually navigated.
>
> ☆*PhistucK*
> > > > If I loadwww.google.comthealert boxes appear as expected. If I then
> > > > type "test" into the search box and press enter, the alert boxes do
> > > > not appear when the results page loads.
>
> > > > I've tested with a more complex extension to verify this. If I
> > > > sendRequest from my background page to my content script when the
> > > > chrome.tabs.onUpdated event fires, I get no response from the content
> > > > page when the search results page loads.
>
> > > > Has anyone else seen this issue? I'd appreciate any ideas for getting
> > > > around it.
>
> > > > --
> > > > 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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

PhistucK

unread,
Sep 7, 2010, 11:51:46 AM9/7/10
to Greg Cooksey, Chromium-extensions
I checked your reproduction and it reproduces, but it is doing the right thing.
Add this to the reproduction script -
window.addEventListener("hashchange", function () {
    alert("Hash changed");
}, false);

Google does not load another page per se, it uses AJAX to get the search results, so it the current document does not "load". Only its hash changes and AJAX is going on behind the scenes.

I am going to close it as WontFix, unless you have something else to show.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Greg Cooksey

unread,
Sep 7, 2010, 12:12:14 PM9/7/10
to Chromium-extensions
Okay. I put together a sample extension that more closely resembles
what my extension really does and it seems to work alright with the
beta channel. I'm guessing this was fixed since I first ran into it.

Thanks for looking into it.

-Greg

On Sep 7, 10:51 am, PhistucK <phist...@gmail.com> wrote:
> I checked your reproduction and it reproduces, but it is doing the right
> thing.
> Add this to the reproduction script -
> window.addEventListener("hashchange", function () {
>     alert("Hash changed");
>
> }, false);
>
> Google does not load another page per se, it uses AJAX to get the search
> results, so it the current document does not "load". Only its hash changes
> and AJAX is going on behind the scenes.
>
> I am going to close it as WontFix, unless you have something else to show.
>
> > > > > > If I loadwww.google.comthealertboxes appear as expected. If I then
> > > > > > type "test" into the search box and press enter, the alert boxes do
> > > > > > not appear when the results page loads.
>
> > > > > > I've tested with a more complex extension to verify this. If I
> > > > > > sendRequest from my background page to my content script when the
> > > > > > chrome.tabs.onUpdated event fires, I get no response from the
> > content
> > > > > > page when the search results page loads.
>
> > > > > > Has anyone else seen this issue? I'd appreciate any ideas for
> > getting
> > > > > > around it.
>
> > > > > > --
> > > > > > 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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
>
> > > > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
> > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>

PhistucK

unread,
Sep 7, 2010, 12:15:33 PM9/7/10
to Greg Cooksey, Chromium-extensions
Note that the beta channel and the stable channel are currently sharing the exact same version.
I am closing the issue you opened.
Thank you.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

bryanosaurus

unread,
Sep 7, 2010, 12:05:47 PM9/7/10
to Chromium-extensions
I am having a similar issue, only my google search results page opens
in a new tab when the user clicks the extension button in the
browser.
I cannot get my content script to load when the tab is created, but
works as normal if I then refresh the page.
I tried using the hashchange check, and it doesn't work in this
scenario.
Any idea for a workaround/solution?

On Sep 7, 11:51 am, PhistucK <phist...@gmail.com> wrote:
> I checked your reproduction and it reproduces, but it is doing the right
> thing.
> Add this to the reproduction script -
> window.addEventListener("hashchange", function () {
>     alert("Hash changed");
>
> }, false);
>
> Google does not load another page per se, it uses AJAX to get the search
> results, so it the current document does not "load". Only its hash changes
> and AJAX is going on behind the scenes.
>
> I am going to close it as WontFix, unless you have something else to show.
>
> > > > > > If I loadwww.google.comthealertboxes appear as expected. If I then
> > > > > > type "test" into the search box and press enter, the alert boxes do
> > > > > > not appear when the results page loads.
>
> > > > > > I've tested with a more complex extension to verify this. If I
> > > > > > sendRequest from my background page to my content script when the
> > > > > > chrome.tabs.onUpdated event fires, I get no response from the
> > content
> > > > > > page when the search results page loads.
>
> > > > > > Has anyone else seen this issue? I'd appreciate any ideas for
> > getting
> > > > > > around it.
>
> > > > > > --
> > > > > > 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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
>
> > > > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
> > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>

PhistucK

unread,
Sep 7, 2010, 12:23:01 PM9/7/10
to bryanosaurus, Chromium-extensions
If you could provide me with a reduced test case that does not work, I will investigate.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Greg Cooksey

unread,
Sep 7, 2010, 12:26:31 PM9/7/10
to Chromium-extensions
I can't :)

It looks like the original issue I ran into a few weeks ago has been
fixed. The reduced case I posted was incorrect, but a more accurate
reduced case works correctly.

On Sep 7, 11:23 am, PhistucK <phist...@gmail.com> wrote:
> If you could provide me with a reduced test case that does not work, I will
> investigate.
>
> > > > > > > > If I loadwww.google.comthealertboxesappear as expected. If I
> > > > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>
> > <chromium-extensions%25252Bunsubscr...@chromium.org<chromium-extensions%2525252Bunsubscr...@chromium.org>

PhistucK

unread,
Sep 7, 2010, 12:29:05 PM9/7/10
to Greg Cooksey, Chromium-extensions
Sorry, you were listed as a CC recipient. I was replying to bryansaurus.

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

bryanosaurus

unread,
Sep 7, 2010, 12:35:01 PM9/7/10
to Chromium-extensions
Sure, thanks!

OK here is a trivial example:

background page
---------------

chrome.tabs.getSelected(null, function(tab) {
document.body.innerHTML = tab.url;
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({url: tab.url });
});
});

content script
--------------

window.addEventListener("mousemove", function () {
console.log("mouse moved");

}, false);


On any page, click the extension icon, opens a new tab - move the
mouse and console logs it.
But, say I google "foo", and open the results page as my new tab. The
content script doesn't load at all.
This was NOT always how it worked, as I have had this extension
published and working since May.
(The actual extension in question lets the user open a new tab on a
google search result that adds numbers to the results and shows 100
per page. I have narrowed the error coming from the content script not
loading on a search result page.)

Any insight would be much appreciated!



On Sep 7, 12:23 pm, PhistucK <phist...@gmail.com> wrote:
> If you could provide me with a reduced test case that does not work, I will
> investigate.
>
> > > > > > > > If I loadwww.google.comthealertboxesappear as expected. If I
> > > > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>
> > <chromium-extensions%25252Bunsubscr...@chromium.org<chromium-extensions%2525252Bunsubscr...@chromium.org>

PhistucK

unread,
Sep 9, 2010, 3:21:11 AM9/9/10
to bryanosaurus, Chromium-extensions
Please, pack the directory of this sample into ZIP or something so I will not have to build it myself...

PhistucK



To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

Ben

unread,
Sep 9, 2010, 1:44:32 PM9/9/10
to PhistucK, bryanosaurus, Chromium-extensions
Here you go, zip attached, contains both the unpacked extension files
and a crx in case you don't feel like packing it yourself or running it
unpacked.

I always keep a simple extension unpacked for testing purposes, in case
I get interested in a certain possible extension or something. ;-)

On Thu, 2010-09-09 at 10:21 +0300, PhistucK wrote:
> Please, pack the directory of this sample into ZIP or something so I
> will not have to build it myself...
>
> ☆PhistucK
>


--
Ben

test-ext.zip

Ben

unread,
Sep 9, 2010, 1:49:03 PM9/9/10
to PhistucK, bryanosaurus, Chromium-extensions
Ah, I forgot to add the tabs permission, so you'll have to modify the
manifest before you load it. Sorry about that.

PhistucK

unread,
Sep 9, 2010, 2:12:00 PM9/9/10
to benj...@gmail.com, bryanosaurus, Chromium-extensions
Thank you, Ben, for stepping in, but this extension should have a browser action and the one you sent me (which is the same one for which bryanosaurus send the partial code) do not have one.

bryanosaurus, please, send me a full sample that is supposed to work but does not, in a ZIP file, so I could help you.

PhistucK

Scott

unread,
Sep 10, 2010, 12:24:46 PM9/10/10
to Chromium-extensions
I have an issue that sounds very much like this, but I have not been
able to pin it down reliably yet. I have noticed unreliable content
script loading problems on gmail, yahoo groups, and some other pages.
It started about 2-3 weeks ago on the dev channel, I think.

I'm trying to get something reproducible

On Sep 9, 1:12 pm, PhistucK <phist...@gmail.com> wrote:
> Thank you, Ben, for stepping in, but this extension should have a browser
> action and the one you sent me (which is the same one for which bryanosaurus
> send the partial code) do not have one.
>
> bryanosaurus, please, send me a full sample that is supposed to work but
> does not, in a ZIP file, so I could help you.
>
> ☆*PhistucK*

skeeJay

unread,
Nov 6, 2010, 12:33:19 AM11/6/10
to Chromium-extensions
Scott, I'm seeing the same random behavior with a content script
failing to load into Gmail. Dev channel, Chrome 9.0.572.0. After
reloading once or twice, the content script finally loads. Have you
been able to reproduce the problem at all or find a workaround?

On Sep 10, 12:24 pm, Scott <scottfu...@gmail.com> wrote:
> I have an issue that sounds very much like this, but I havenotbeen
> able to pin it down reliably yet. I have noticed unreliablecontentscriptloadingproblems on gmail, yahoo groups, and some other pages.
> It started about 2-3 weeks ago on the dev channel, I think.
>
> I'm trying to get something reproducible
>
> On Sep 9, 1:12 pm, PhistucK <phist...@gmail.com> wrote:
>
>
>
>
>
>
>
> > Thank you, Ben, for stepping in, but this extension should have a browser
> > action and the one you sent me (which is the same one for which bryanosaurus
> > send the partial code) donothave one.
>
> > bryanosaurus, please, send me a full sample that is supposed to work but
> > doesnot, in a ZIP file, so I could help you.
>
> > ☆*PhistucK*
>
> > On Thu, Sep 9, 2010 at 20:44, Ben <benjo...@gmail.com> wrote:
> > > Here you go, zip attached, contains both the unpacked extension files
> > > and a crx in case you don't feel like packing it yourself or running it
> > > unpacked.
>
> > > I always keep a simple extension unpacked for testing purposes, in case
> > > I get interested in a certain possible extension or something. ;-)
>
> > > On Thu, 2010-09-09 at 10:21 +0300, PhistucK wrote:
> > > > Please, pack the directory of this sample into ZIP or something so I
> > > > willnothave to build it myself...
>
> > > > ☆PhistucK
>
> > > --
> > > Ben
Reply all
Reply to author
Forward
0 new messages