From 3557097c72b8cb8fab7b744a703086d347c4407d Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 18 Jan 2018 07:28:25 +1000 Subject: [PATCH] check if contextMenus is available to make it possible to run in mobile firefox browser. --- extension/manifest.json | 2 +- src/entry/background.js | 32 +++++++++++++++++--------------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/extension/manifest.json b/extension/manifest.json index dee320f..74e1e6b 100644 --- a/extension/manifest.json +++ b/extension/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Leo Translate", - "version": "1.8.6", + "version": "1.8.7", "description": "Translate words on the internet pages using LinguaLeo API and add words to the LinguaLeo Dictionary.", diff --git a/src/entry/background.js b/src/entry/background.js index 4f81827..2d1012b 100644 --- a/src/entry/background.js +++ b/src/entry/background.js @@ -10,21 +10,23 @@ import { import { removeHtmlTags } from '../helpers'; // Create context item -chrome.contextMenus.create({ - id: 'leo-translate', - title: 'Translate with Leo', - contexts: ['selection'], - onclick: (info, tab) => { - chrome.tabs.sendMessage(tab.id, { - id: CONTENT_OPEN_POPUP, - text: info.selectionText, - context: '' - }); - }, - icons: { - '16': '../icons/icon.svg' - } -}); +if (chrome.contextMenus !== undefined) { + chrome.contextMenus.create({ + id: 'leo-translate', + title: 'Translate with Leo', + contexts: ['selection'], + onclick: (info, tab) => { + chrome.tabs.sendMessage(tab.id, { + id: CONTENT_OPEN_POPUP, + text: info.selectionText, + context: '' + }); + }, + icons: { + '16': '../icons/icon.svg' + } + }); +} // Listen for message to show in system notification chrome.runtime.onMessage.addListener((message, sender) => {