electron/spec/fixtures/extensions/chrome-i18n/v3/main.js
Shelley Vohr 303b707fbf
fix: update chrome.i18n for Manifest v3 (#39291)
fix: update chrome.i18n for Manifest v3
2023-08-02 11:02:16 +02:00

36 lines
932 B
JavaScript

/* global chrome */
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
sendResponse(request);
});
const map = {
getAcceptLanguages () {
chrome.i18n.getAcceptLanguages().then((languages) => {
console.log(JSON.stringify(languages));
});
},
getMessage () {
const message = chrome.i18n.getMessage('extName');
console.log(JSON.stringify(message));
},
getUILanguage () {
const language = chrome.i18n.getUILanguage();
console.log(JSON.stringify(language));
},
async detectLanguage (texts) {
const result = [];
for (const text of texts) {
const language = await chrome.i18n.detectLanguage(text);
result.push(language);
}
console.log(JSON.stringify(result));
}
};
const dispatchTest = (event) => {
const { method, args = [] } = JSON.parse(event.data);
map[method](...args);
};
window.addEventListener('message', dispatchTest, false);