diff --git a/src/auth.js b/src/auth.js index d5514a4..1b40860 100644 --- a/src/auth.js +++ b/src/auth.js @@ -1,7 +1,7 @@ const authorize = function() { if (IS_CHROMIUM && IS_DESKTOP) { return function() { - return new Promise(function(resolve, reject) { + return new Promise(function(resolve) { chrome.identity.getAuthToken({interactive: true}, resolve); }); } @@ -64,7 +64,7 @@ const authorize = function() { }); } } - return new Promise(function (resolve, reject) { + return new Promise(function (resolve) { return invokeWhenReady(250, () => ACCESS_TOKEN, () => resolve(ACCESS_TOKEN)); }); } diff --git a/src/manifest-chrome-dev.json b/src/manifest-chrome-dev.json index fc0a7ba..f60ef04 100644 --- a/src/manifest-chrome-dev.json +++ b/src/manifest-chrome-dev.json @@ -1,4 +1,7 @@ { + "background": { + "service_worker": "service-worker.js" + }, "key": "iihhhbkpnemncnmefhffhfiecmilppnf", "oauth2": { "client_id": "28806920398-1469m84teijjb48roc8vbrg4m4eoe23b.apps.googleusercontent.com" diff --git a/src/manifest-chrome.json b/src/manifest-chrome.json index 109a1ed..101e6af 100644 --- a/src/manifest-chrome.json +++ b/src/manifest-chrome.json @@ -1,4 +1,7 @@ { + "background": { + "service_worker": "service-worker.js" + }, "oauth2": { "client_id": "444973037518-n5dc9rpf1hs992un81kjh3m1jdo7vomc.apps.googleusercontent.com", "scopes": [ diff --git a/src/manifest-firefox.json b/src/manifest-firefox.json index 6e3f2a1..614c757 100644 --- a/src/manifest-firefox.json +++ b/src/manifest-firefox.json @@ -1,4 +1,7 @@ { + "background": { + "page": "background.html" + }, "browser_specific_settings": { "gecko": { "id": "{7cadcc4b-af6c-4227-a247-7122bfeea911}" diff --git a/src/manifest.json b/src/manifest.json index 337fdbb..f1b3830 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -1,12 +1,9 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "__MSG_extensionName__", "description": "__MSG_extensionDescription__", "default_locale": "en", - "background": { - "page": "background.html" - }, - "browser_action": { + "action": { "default_icon": "icons/icon128.png" }, "content_scripts": [{ @@ -23,7 +20,9 @@ "permissions": [ "identity", "storage", - "webRequest", + "webRequest" + ], + "host_permissions": [ "http://localhost/vocabulary-add/*", "https://www.googleapis.com/*" ] diff --git a/src/polyfills.js b/src/polyfills.js index 9ab2a2e..27f6984 100644 --- a/src/polyfills.js +++ b/src/polyfills.js @@ -10,7 +10,7 @@ if (IS_CHROMIUM) { runtime: { onMessage: { addListener: function(callback) { - chrome.extension.onMessage.addListener(callback); + chrome.runtime.onMessage.addListener(callback); } }, openOptionsPage: function() { diff --git a/src/service-worker.js b/src/service-worker.js new file mode 100644 index 0000000..aafd0b8 --- /dev/null +++ b/src/service-worker.js @@ -0,0 +1,10 @@ +function tryImportScript(script) { + try { + importScripts(script); + } catch (e) { + console.log(e); + } +} +tryImportScript("polyfills.js"); +tryImportScript("auth.js"); +tryImportScript("background.js");