Perhaps an insufficiency in chrome.tabs.detectLanguage()

30 views
Skip to first unread message

Ziyuan Yao

unread,
May 15, 2012, 7:52:14 PM5/15/12
to chromium-...@chromium.org
According to this API's documentation (http://code.google.com/chrome/extensions/tabs.html#method-detectLanguage), the API is:

chrome.tabs.detectLanguage(integer tabId, function callback)

And the callback is:

function(language);

Suppose I have multiple tabs whose content scripts all request the background page to tell the language code for each of these tabs, and when the callback function is called, the code will know the language code but not which tab this language code is for. I think it at least should have another parameter:

function(tabId, language);

Shouldn't it?

PhistucK

unread,
May 16, 2012, 1:47:57 AM5/16/12
to Ziyuan Yao, chromium-...@chromium.org
I think your suggestion makes sense.

PhistucK



--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/w5u6vahwb7wJ.
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.

Mihai Parparita

unread,
May 16, 2012, 2:03:26 AM5/16/12
to Ziyuan Yao, chromium-...@chromium.org
You can get get the equivalent behavior by using bind (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind) with your callback, so that it gets a copy of the tabId parameter:

chrome.tabs.detectLanguage(
    tabId,
    (function(tabId, language) {
      ...
    }).bind(this, tabId));

Mihai


--

Ziyuan Yao

unread,
May 16, 2012, 2:07:35 AM5/16/12
to chromium-...@chromium.org, Ziyuan Yao
Neat! Just what I want.


On Wednesday, May 16, 2012 2:03:26 PM UTC+8, Mihai Parparita wrote:
You can get get the equivalent behavior by using bind (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind) with your callback, so that it gets a copy of the tabId parameter:

chrome.tabs.detectLanguage(
    tabId,
    (function(tabId, language) {
      ...
    }).bind(this, tabId));

Mihai


On Tue, May 15, 2012 at 4:52 PM, Ziyuan Yao <yaoz...@gmail.com> wrote:
According to this API's documentation (http://code.google.com/chrome/extensions/tabs.html#method-detectLanguage), the API is:

chrome.tabs.detectLanguage(integer tabId, function callback)

And the callback is:

function(language);

Suppose I have multiple tabs whose content scripts all request the background page to tell the language code for each of these tabs, and when the callback function is called, the code will know the language code but not which tab this language code is for. I think it at least should have another parameter:

function(tabId, language);

Shouldn't it?

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/w5u6vahwb7wJ.
To post to this group, send email to chromium-extensions@chromium.org.
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-extensions@chromium.org.
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.

Ziyuan Yao

unread,
May 16, 2012, 2:37:37 AM5/16/12
to chromium-...@chromium.org, Ziyuan Yao
Mihai Parparita:

You're acknowledged on my project's Acknowledgments list :-)

On Wednesday, May 16, 2012 2:03:26 PM UTC+8, Mihai Parparita wrote:
You can get get the equivalent behavior by using bind (https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind) with your callback, so that it gets a copy of the tabId parameter:

chrome.tabs.detectLanguage(
    tabId,
    (function(tabId, language) {
      ...
    }).bind(this, tabId));

Mihai


On Tue, May 15, 2012 at 4:52 PM, Ziyuan Yao <yaoz...@gmail.com> wrote:
According to this API's documentation (http://code.google.com/chrome/extensions/tabs.html#method-detectLanguage), the API is:

chrome.tabs.detectLanguage(integer tabId, function callback)

And the callback is:

function(language);

Suppose I have multiple tabs whose content scripts all request the background page to tell the language code for each of these tabs, and when the callback function is called, the code will know the language code but not which tab this language code is for. I think it at least should have another parameter:

function(tabId, language);

Shouldn't it?

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-extensions/-/w5u6vahwb7wJ.
To post to this group, send email to chromium-extensions@chromium.org.
To unsubscribe from this group, send email to chromium-extensions+unsub...@chromium.org.
Reply all
Reply to author
Forward
0 new messages