Detects the primary language of the content in a tab, using the Compact Language Detector (CLD).


  tabId,                   // optional integer
  function(language) {...} // function

This API is also available as browser.tabs.detectLanguage() in a version that returns a promise.


integer. Defaults to the active tab of the current window.
function. The function is passed the following arguments:
string. An ISO language code such as en or fr. For a complete list of languages supported by this method, see the CLD2 README. For an unknown language, "und" will be returned (but see bug 1288263).

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes Yes 45.0 No 33


Detect and log the language of the active tab when the user clicks a browser action:

function onLanguageDetected(lang) {
  console.log("Language is: " + lang);

chrome.browserAction.onClicked.addListener(function() {

Detect and log the language of every open tab when the user clicks a browser action (note that this example requires the "tabs" permission):

function onLanguageDetected(url, lang) {
  console.log("Language in " + url + " is: " + lang);

function detectLanguages(tabs) {
  for (tab of tabs) {
    var callback = onLanguageDetected.bind(null, tab.url);
    chrome.tabs.detectLanguage(, callback);

chrome.browserAction.onClicked.addListener(function() {
  chrome.tabs.query({}, detectLanguages);


This API is based on Chromium's chrome.tabs API. This documentation is derived from tabs.json in the Chromium code.

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: Makyen, wbamberg
 Last updated by: Makyen,