executeScript fails silently on *some* tabs

471 views
Skip to first unread message

IlkkaH

unread,
Apr 7, 2011, 1:51:12 PM4/7/11
to Chromium-extensions
Ok, here's a strange problem.

I'm trying to use chrome.tabs.executeScript, for the first time
though, and I'm having some trouble.

- I use the extension in an unpacked form.
- My Chrome version is 12.0.725.0 dev on Win7 64bit.
- I have these as permissions: ": [ "tabs", "contextMenus", "http://*/
*" ] }
- The extension used to be an icon on the taskbar, but it failed there
as well. I moved into context menus but it still keeps failing...

In background.html I have this
chrome.contextMenus.create({
title: "Testing",
contexts: ["page"],
onclick: function() { alert('hello'); chrome.tabs.executeScript(null,
{ file : "/bookmarklet.js" }, function() { alert('hello2') } ) }
});

Those alerts are just for some "debugging".

Now... what happens is that on *some* (like 50%) tabs/pages this fails
to execute. There is nothing in the javascript console. Also, when it
fails, the hello2 alert doesn't execute (it executes when this works).

It seems to work here on this page all the time, for example:
http://code.google.com/chrome/extensions/contextMenus.html
... and also all the other pages around there.

Sometimes it works elsewhere too, but it may fail or work on the same
page after browser restart - it varies.

I tried to put a try-catch around executeScript call but it didn't
produce anything.

Not sure how to debug this? Not sure how to proceed. Any ideas?

Thank you,
Ilkka

Scott Fujan

unread,
Apr 7, 2011, 1:58:27 PM4/7/11
to IlkkaH, Chromium-extensions
It may be an iframe thing. Also, try omitting the first parameter completely (remove 'null')


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


Ilkka Huotari

unread,
Apr 7, 2011, 2:13:08 PM4/7/11
to Chromium-extensions
Thanks for the quick response.

Yes, iframe sounds like a possible explanation. It didn't affect
though when I removed iframes with the developer tools (although that
probably doesn't prove anything).

I don't know how I could remove the first parameter though? As I need
to have the second parameter there, I probably should have something
as the first parameter? Maybe I'm wrong and missing something, but it
didn't seem to work when I tried these:
chrome.tabs.executeScript({ file : "/bookmarklet.js" })
chrome.tabs.executeScript('', { file : "/bookmarklet.js" })
chrome.tabs.executeScript(, { file : "/bookmarklet.js" } // that's
probably not valid javascript :)

So... is there another way I could call this function?

Ilkka Huotari

unread,
Apr 7, 2011, 2:22:52 PM4/7/11
to Chromium-extensions
Ok, got a bit further.

When I call the function like this
chrome.tabs.executeScript(0, { file : "/bookmarklet.js" }, function()
{alert('hello2')} )

... it gets to the hello2 part. It doesn't inject the script though,
so maybe tabId 0 isn't quite right. Maybe I can work around this when
I first look for the correct tabId and use it explicitly.

Seems like a Chrome issue though on the whole?

Scott Fujan

unread,
Apr 7, 2011, 2:26:38 PM4/7/11
to Ilkka Huotari, Chromium-extensions
Hmm, forget the first parameter suggestion. I suggest trying allFrames:true

chrome.tabs.executeScript(null, { file : "/bookmarklet.js", allFrames:true }, function(){alert('hello2')} )


--

Ilkka Huotari

unread,
Apr 7, 2011, 3:11:41 PM4/7/11
to Chromium-extensions
I guess I was wrong that in principle I could leave the first
parameter out. However, in practice all these attempts failed:

1)
chrome.tabs.executeScript({file : "bookmarklet.js"} );

2) allFrames:true doesn't seem to have an effect. I tried:
chrome.tabs.executeScript(null, {allFrames:true,
file:"bookmarklet.js"} );
chrome.tabs.executeScript(tab.id, {allFrames:true,
file:"bookmarklet.js"} );

Yes this can still be an iframe issue, but allFrames doesn't seem to
have an effect.

3) Like in this example[1], I can get the explicit tab id for the
onclick handler.
When I use the tab id like this:
function myhandler(info, tab)
{
chrome.tabs.executeScript(tab.id, {file : "bookmarklet.js"} );
}
... I get nowhere. Even when I add the callback function for
executeScript, it doesn't get executed. Earlier when I tried with
tabid=0, I think the callback function got executed.

With the null parameter it works *sometimes*, but with explicit tab
id, it doesn't seem to work at all. So: with tabid set to null it has
worked the best, but not quite well enough :)

Here's a page (there are a lot of others though) where my script fails
every time: http://marcuswest.in/read/four-performance-elements/

So... still pretty much in the same place when I started. Explicitly
setting the tabId made things actually a bit worse.

[1]
http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/contextMenus/basic/sample.js?content-type=text/plain

Ilkka Huotari

unread,
Apr 8, 2011, 1:43:33 PM4/8/11
to Chromium-extensions
Any ideas how to debug this, how to see where the problem might be?

Maybe I need to install Chromium development environment?

Mihai Parparita

unread,
Apr 8, 2011, 2:59:42 PM4/8/11
to Ilkka Huotari, Chromium-extensions
Can you upload the smallest possible extension (e.g. if the contents
of bookmarklets.js don't seem to matter, just replace them with an
alert('here');) that exhibits this problem somewhere?

Mihai

On Fri, Apr 8, 2011 at 10:43 AM, Ilkka Huotari <ilk...@gmail.com> wrote:
> Any ideas how to debug this, how to see where the problem might be?
>
> Maybe I need to install Chromium development environment?
>

Ilkka Huotari

unread,
Apr 8, 2011, 4:22:19 PM4/8/11
to Chromium-extensions
Ok, done.

It should alert "extensiontest: init" if the call works, otherwise no
alert. It is activated from the context menu:
http://ilkkah.com/extensiontest.crx

Like I said, this is one page where it has consistently failed (I'm
not promoting this page though :-)
http://marcuswest.in/read/four-performance-elements/
Here is another:
http://www.kaleva.fi/uutiset/kasvisruualla-potkii-yllattavan-pitkalle/895229

I've had mixed results on some other pages. For example when I
restarted the browser a minute ago, it started working here (earlier
it failed):
http://cacm.acm.org/magazines/2011/4/106584-a-co-relational-model-of-data-for-large-shared-data-banks/fulltext

Thanks for your interest in this,
Ilkka

Mihai Parparita

unread,
Apr 8, 2011, 5:18:27 PM4/8/11
to Ilkka Huotari, Chromium-extensions
Thanks for the simplified test case and URLs. It looks like this
reproduces most reliably with
http://marcuswest.in/read/four-performance-elements/. I've filed
http://crbug.com/78854 about this, please star the bug if you'd like
be updated on its progress.

Mihai

Ilkka Huotari

unread,
Apr 8, 2011, 5:31:49 PM4/8/11
to Chromium-extensions
Thank you very much.

On Apr 9, 12:18 am, Mihai Parparita <mih...@chromium.org> wrote:
> Thanks for the simplified test case and URLs. It looks like this
> reproduces most reliably withhttp://marcuswest.in/read/four-performance-elements/. I've filedhttp://crbug.com/78854about this, please star the bug if you'd like
> be updated on its progress.
>
> Mihai
>
>
>
>
>
>
>
> On Fri, Apr 8, 2011 at 1:22 PM, Ilkka Huotari <ilk...@gmail.com> wrote:
> > Ok, done.
>
> > It should alert "extensiontest: init" if the call works, otherwise no
> > alert. It is activated from the context menu:
> >http://ilkkah.com/extensiontest.crx
>
> > Like I said, this is one page where it has consistently failed (I'm
> > not promoting this page though :-)
> >http://marcuswest.in/read/four-performance-elements/
> > Here is another:
> >http://www.kaleva.fi/uutiset/kasvisruualla-potkii-yllattavan-pitkalle...
>
> > I've had mixed results on some other pages. For example when I
> > restarted the browser a minute ago, it started working here (earlier
> > it failed):
> >http://cacm.acm.org/magazines/2011/4/106584-a-co-relational-model-of-...
>
> > Thanks for your interest in this,
> > Ilkka
>
> > --
> > 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.
Reply all
Reply to author
Forward
0 new messages