problem with chrome.tabs.executeScript

6,406 views
Skip to first unread message

Oleg Sokolov

unread,
May 26, 2011, 5:06:25 PM5/26/11
to Chromium-extensions
Chrome sees this code, but doesn't execute the script. Although if I
put a line "window.close();" - it works. But with
"chrome.tabs.executeScript" it doesn;t.

chrome.tabs.executeScript(null, {code: "window.close();"});

What can be the reason?
Please, don't advise me to use simply "window.close()". My problem is
more complicated, with tabId instead of null, so I need this chrome
method.
I just changed tabId to null to find out if the problem was in tabId.

Arne Roomann-Kurrik

unread,
May 27, 2011, 11:37:07 AM5/27/11
to Oleg Sokolov, Chromium-extensions
Can you be a bit clearer about what you're trying to do, how your extension is structured, and what exactly "works" or doesn't?  

What do you mean by "Chrome sees this code"?

You say window.close works but chrome.tabs.executeScript doesn't.  But this line has both: chrome.tabs.executeScript(null, {code: "window.close();"}); - so what happens there?

What part of your extension is calling chrome.tabs.executeScript?

~Arne



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


Yoyo Zhou

unread,
May 26, 2011, 5:58:50 PM5/26/11
to Oleg Sokolov, Chromium-extensions

Can you use chrome.tabs.remove(tabId)?

Otherwise, do you have host permissions? If not, you should see errors
in your extension's page's developer tools console. "To insert code
into a page, your extension must have cross-origin permissions for the
page. It also must be able to use the chrome.tabs module."
http://code.google.com/chrome/extensions/content_scripts.html#pi

Yoyo Zhou

Oleg Sokolov

unread,
May 28, 2011, 10:19:10 AM5/28/11
to Chromium-extensions
OK, I'll describe the situation in details.

My extension overrides chrome://newtab/ with specific page. Imagine
that some amount of them is opened in different tabs.
I have got an array with all these tabs' IDs.

Then, something happens on one page and I need to update the
information on some of the rest.
First, I used chrome.tabs.update(tabId, ...) and all was going right.
But now I don't want to reload pages, but to update one element on
them.
So I wrote:

chrome.tabs.executeScript(parseInt(tabId), {code:
"document.getElementById('box' + " + slot + ").innerHTML =
boxContent(" + thumbId + ");"});

And it doesn't work. Yes, I suppose that the problem is in
permissions, but what should I do to solve it?
In manifest I have "permissions": [ "tabs", ..., "*://*/*"]
If I want to insert code into a page that I created myself earlier,
there should be a way to do it!

Arne Roomann-Kurrik

unread,
May 31, 2011, 11:38:27 AM5/31/11
to Oleg Sokolov, Chromium-extensions
You can't call executeScript on chrome-extension:// pages, even if the page is in your own extension.

You should call chrome.extension.getViews to get a list of all the windows open in your application instead:

var wins = chrome.extension.getViews({type:'tab'});
for (var i = 0, win; win = wins[i]; i++) {
  win.document.getElementById .... // etc
}

~Arne


Oleg Sokolov

unread,
Jun 2, 2011, 4:34:56 PM6/2/11
to Chromium-extensions
Thanks a lot! This was exactly what I needed.
Reply all
Reply to author
Forward
0 new messages