From 9efb1a24c3c526486b55003ca298007287394edb Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 13:26:56 +0100 Subject: [PATCH 01/10] ASP-2684: refactor service workers to use es module imports/exports --- background.js | 3 +++ js/allTenants.js | 2 +- js/background.js | 2 ++ js/options.js | 9 +++++---- js/tenants.js | 10 +++++----- manifest.json | 8 ++++---- 6 files changed, 20 insertions(+), 14 deletions(-) create mode 100644 background.js diff --git a/background.js b/background.js new file mode 100644 index 0000000..9666e79 --- /dev/null +++ b/background.js @@ -0,0 +1,3 @@ +import {allTenants} from "./js/allTenants"; +import * as Tenants from "./js/tenants"; +import * as Background from "./js/background" diff --git a/js/allTenants.js b/js/allTenants.js index 6085efb..7d8a7b6 100644 --- a/js/allTenants.js +++ b/js/allTenants.js @@ -5,7 +5,7 @@ * The non-branded 'Talis' extension should use the tenant list from: * https://talis-public.s3-eu-west-1.amazonaws.com/talis.com/customers.json */ -var allTenants = { +export const allTenants = { "broadminster" : { "name" : "Broadminster University", "apps" : { diff --git a/js/background.js b/js/background.js index d061bef..1ccb7c7 100644 --- a/js/background.js +++ b/js/background.js @@ -1,3 +1,5 @@ +import {chromeOrBrowser, getActiveTenant} from "./tenants"; + /** * Background script. * diff --git a/js/options.js b/js/options.js index b8dc069..d01dcef 100644 --- a/js/options.js +++ b/js/options.js @@ -1,3 +1,4 @@ +import {buildTenant, chromeOrBrowser, getActiveTenant, getTenants, saveActiveTenant} from "./tenants"; $(function() { $('#tenantList').on('change', function() { @@ -10,8 +11,8 @@ $(function() { }); $('#save').on('click', function() { if ($('#specifyTenant:selected').length > 0) { - var otherTenantCode = $('#tenantCode').val(); - var otherTenantRegion = $('#tenantRegion').val(); + const otherTenantCode = $('#tenantCode').val(); + const otherTenantRegion = $('#tenantRegion').val(); if (!otherTenantCode.trim()) { $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantShortCodeAlert') + '
'); @@ -64,8 +65,8 @@ function loadTenantList() { } getTenants(function(tenants) { - var matched = false; - for (var tenantCode in tenants) { + let matched = false; + for (const tenantCode in tenants) { if (activeTenant && tenantCode === activeTenant.code) { matched = true; $('#tenantList option:last-of-type').before(''); diff --git a/js/tenants.js b/js/tenants.js index 621981c..2b01df3 100644 --- a/js/tenants.js +++ b/js/tenants.js @@ -4,7 +4,7 @@ * * @returns {Object} */ -function chromeOrBrowser() { +export function chromeOrBrowser() { return this.browser || chrome; } @@ -23,7 +23,7 @@ if (!storage) { * * @param {activeTenant} cb */ -function getActiveTenant(cb) { +export function getActiveTenant(cb) { storage.get({ activeTenant: null }, function(tenants, err) { @@ -94,7 +94,7 @@ function convertActiveTenantToObject(activeTenant, cb) { * @param {object} tenant * @param {function()} cb - Callback to run once stored */ -function saveActiveTenant(tenant, cb) { +export function saveActiveTenant(tenant, cb) { storage.set({ activeTenant: tenant }, function() { @@ -126,7 +126,7 @@ function saveActiveTenant(tenant, cb) { * * @param {allTenants} cb */ -function getTenants(cb) { +export function getTenants(cb) { var tenants = {}; getTenantList(function(tenantList) { for (var code in tenantList) { @@ -166,7 +166,7 @@ function getTenantList(cb) { * @param {string} tenantCode - the tenant short code * @param {string} tenantRegion - the region for this tenancy */ -function buildTenant(tenantCode, tenantRegion) { +export function buildTenant(tenantCode, tenantRegion) { return { "name" : tenantCode, "code" : tenantCode, diff --git a/manifest.json b/manifest.json index e7b47e8..212ce1b 100644 --- a/manifest.json +++ b/manifest.json @@ -10,8 +10,8 @@ "176": "images/icon176.png" }, "background": { - "page": "background.html", - "persistent": false + "service_worker": "background.js", + "type": "module" }, "permissions": [ "activeTab", "storage", "https://talis-public.talis.com/*" @@ -34,5 +34,5 @@ } }, "default_locale": "en", - "manifest_version": 2 -} \ No newline at end of file + "manifest_version": 3 +} From c223dfbbed9b94428647c3920dd8c7d933395494 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 13:31:16 +0100 Subject: [PATCH 02/10] ASP-2684: refactor permissions per v3 spec --- manifest.json | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/manifest.json b/manifest.json index 212ce1b..4fe5899 100644 --- a/manifest.json +++ b/manifest.json @@ -1,9 +1,9 @@ { "name": "__MSG_extensionName__", "author": "Talis Education Limited", - "description":"__MSG_description__", + "description": "__MSG_description__", "version": "__VERSION__", - "icons": { + "icons": { "16": "images/icon16.png", "48": "images/icon48.png", "128": "images/icon128.png", @@ -14,7 +14,11 @@ "type": "module" }, "permissions": [ - "activeTab", "storage", "https://talis-public.talis.com/*" + "activeTab", + "storage" + ], + "host_permissions": [ + "https://talis-public.talis.com/*" ], "options_ui": { "page": "options.html", @@ -31,7 +35,7 @@ "30": "images/icon30.png", "32": "images/icon32.png", "40": "images/icon40.png" - } + } }, "default_locale": "en", "manifest_version": 3 From 201f29157eff2a5bfa239e8673549405bbd561a3 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 13:33:05 +0100 Subject: [PATCH 03/10] ASP-2684: refactor to action per v3 spec --- manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifest.json b/manifest.json index 4fe5899..d62c667 100644 --- a/manifest.json +++ b/manifest.json @@ -25,7 +25,7 @@ "chrome_style": true }, "options_page": "options.html", - "browser_action": { + "action": { "default_title": "__MSG_browserActionTitle__", "default_icon": { "16": "images/icon16.png", From 06142b199cf3b6fbd49057b33a5bdb9b717118ac Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 13:56:24 +0100 Subject: [PATCH 04/10] ASP-2684: refactor for scripting differences per v3 spec (https://developer.chrome.com/docs/extensions/mv3/mv3-migration-checklist/#api-tabs) --- js/background.js | 24 +++++++++++++++++------- manifest.json | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/js/background.js b/js/background.js index 1ccb7c7..99e72f9 100644 --- a/js/background.js +++ b/js/background.js @@ -1,11 +1,20 @@ import {chromeOrBrowser, getActiveTenant} from "./tenants"; +async function getCurrentTab() { + let queryOptions = {active: true, lastFocusedWindow: true}; + // `tab` will either be a `tabs.Tab` instance or `undefined`. + let [tab] = await chrome.tabs.query(queryOptions); + return tab; +} + +let tab = await getCurrentTab(); + /** * Background script. * * This only does anything when the bookmarking button is clicked */ -chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) { +chromeOrBrowser().browserAction.onClicked.addListener(function (currentTab) { // If no institution has been set, go to the options page to set one getActiveTenant(function (tenant) { if (!tenant) { @@ -14,12 +23,13 @@ chromeOrBrowser().browserAction.onClicked.addListener(function(currentTab) { url: chromeOrBrowser().extension.getURL("options.html") }); } else { - chromeOrBrowser().tabs.executeScript(null, { - file: "/js/bookmarker.js", - runAt: 'document_end' - }, function () { - chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenant: tenant}); - }); + chromeOrBrowser().scripting.executeScript( + { + target: {tabId: tab.id}, + files: ['/js/bookmarker.js'] + }, function () { + chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenant: tenant}); + }); } }); }); diff --git a/manifest.json b/manifest.json index d62c667..4cd6f3e 100644 --- a/manifest.json +++ b/manifest.json @@ -15,6 +15,7 @@ }, "permissions": [ "activeTab", + "scripting", "storage" ], "host_permissions": [ From 10d83392a144df3336378ba6daeb2b44f6cd93f1 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 14:01:27 +0100 Subject: [PATCH 05/10] ASP-2684: remove deprecated API --- js/background.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/background.js b/js/background.js index 99e72f9..51b3a3f 100644 --- a/js/background.js +++ b/js/background.js @@ -20,7 +20,7 @@ chromeOrBrowser().browserAction.onClicked.addListener(function (currentTab) { if (!tenant) { // browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround chromeOrBrowser().tabs.create({ - url: chromeOrBrowser().extension.getURL("options.html") + url: 'options.html' }); } else { chromeOrBrowser().scripting.executeScript( From e044aff89582b9b48f4acc6150e2bb0f516352f8 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Fri, 30 Sep 2022 14:16:40 +0100 Subject: [PATCH 06/10] ASP-2684: tweak gruntfile --- Gruntfile.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index 676bdfe..add69a7 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -25,6 +25,7 @@ module.exports = function(grunt) { cwd: './', src: [ '*.html', + 'background.js', '_locales/**', 'images/**', 'css/**', @@ -80,4 +81,4 @@ module.exports = function(grunt) { ['create-dist-dir', 'write-manifest:manifold', 'copy:dependencies', 'copy:common'] ); grunt.registerTask('default', ['dist-common']); -}; \ No newline at end of file +}; From 93374825e3eb81ac37ed38e306ded8913268932f Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Mon, 3 Oct 2022 09:12:40 +0100 Subject: [PATCH 07/10] ASP-2684: tweak background script imports --- background.js | 3 --- importBackgroundScripts.js | 3 +++ manifest.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 background.js create mode 100644 importBackgroundScripts.js diff --git a/background.js b/background.js deleted file mode 100644 index 9666e79..0000000 --- a/background.js +++ /dev/null @@ -1,3 +0,0 @@ -import {allTenants} from "./js/allTenants"; -import * as Tenants from "./js/tenants"; -import * as Background from "./js/background" diff --git a/importBackgroundScripts.js b/importBackgroundScripts.js new file mode 100644 index 0000000..2c73cfb --- /dev/null +++ b/importBackgroundScripts.js @@ -0,0 +1,3 @@ +import "./js/allTenants.js"; +import "./js/tenants.js"; +import "./js/background.js" diff --git a/manifest.json b/manifest.json index 4cd6f3e..7688fe3 100644 --- a/manifest.json +++ b/manifest.json @@ -10,7 +10,7 @@ "176": "images/icon176.png" }, "background": { - "service_worker": "background.js", + "service_worker": "importBackgroundScripts.js", "type": "module" }, "permissions": [ From 23e197c01338d7dd8b855ca6c73d5b060362fc46 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Mon, 3 Oct 2022 16:21:59 +0100 Subject: [PATCH 08/10] ASP-2684: fiddling to try and get it to work --- Gruntfile.js => Gruntfile.cjs | 0 background.js | 4 +++ importBackgroundScripts.js | 3 -- js/allTenants.js | 2 +- js/background.js | 35 -------------------- js/backgroundExecutor.js | 62 +++++++++++++++++++++++++++++++++++ js/bookmarker.js | 8 ++--- js/options.js | 12 +++---- js/tenants.js | 28 ++++++++-------- manifest.json | 8 ++--- options.html | 15 +++++++++ package.json | 1 + 12 files changed, 111 insertions(+), 67 deletions(-) rename Gruntfile.js => Gruntfile.cjs (100%) create mode 100644 background.js delete mode 100644 importBackgroundScripts.js delete mode 100644 js/background.js create mode 100644 js/backgroundExecutor.js diff --git a/Gruntfile.js b/Gruntfile.cjs similarity index 100% rename from Gruntfile.js rename to Gruntfile.cjs diff --git a/background.js b/background.js new file mode 100644 index 0000000..5f2e684 --- /dev/null +++ b/background.js @@ -0,0 +1,4 @@ +import "/js/allTenants.js"; +import "/js/tenants.js"; +import "/js/backgroundExecutor.js" + diff --git a/importBackgroundScripts.js b/importBackgroundScripts.js deleted file mode 100644 index 2c73cfb..0000000 --- a/importBackgroundScripts.js +++ /dev/null @@ -1,3 +0,0 @@ -import "./js/allTenants.js"; -import "./js/tenants.js"; -import "./js/background.js" diff --git a/js/allTenants.js b/js/allTenants.js index 7d8a7b6..6eeecee 100644 --- a/js/allTenants.js +++ b/js/allTenants.js @@ -5,7 +5,7 @@ * The non-branded 'Talis' extension should use the tenant list from: * https://talis-public.s3-eu-west-1.amazonaws.com/talis.com/customers.json */ -export const allTenants = { +const allTenants = { "broadminster" : { "name" : "Broadminster University", "apps" : { diff --git a/js/background.js b/js/background.js deleted file mode 100644 index 51b3a3f..0000000 --- a/js/background.js +++ /dev/null @@ -1,35 +0,0 @@ -import {chromeOrBrowser, getActiveTenant} from "./tenants"; - -async function getCurrentTab() { - let queryOptions = {active: true, lastFocusedWindow: true}; - // `tab` will either be a `tabs.Tab` instance or `undefined`. - let [tab] = await chrome.tabs.query(queryOptions); - return tab; -} - -let tab = await getCurrentTab(); - -/** - * Background script. - * - * This only does anything when the bookmarking button is clicked - */ -chromeOrBrowser().browserAction.onClicked.addListener(function (currentTab) { - // If no institution has been set, go to the options page to set one - getActiveTenant(function (tenant) { - if (!tenant) { - // browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround - chromeOrBrowser().tabs.create({ - url: 'options.html' - }); - } else { - chromeOrBrowser().scripting.executeScript( - { - target: {tabId: tab.id}, - files: ['/js/bookmarker.js'] - }, function () { - chromeOrBrowser().tabs.sendMessage(currentTab.id, {tenant: tenant}); - }); - } - }); -}); diff --git a/js/backgroundExecutor.js b/js/backgroundExecutor.js new file mode 100644 index 0000000..9cafc45 --- /dev/null +++ b/js/backgroundExecutor.js @@ -0,0 +1,62 @@ +import {getActiveTenant} from "/js/tenants.js"; + +async function getCurrentTab() { + let queryOptions = {active: true, lastFocusedWindow: true}; + // `tab` will either be a `tabs.Tab` instance or `undefined`. + let [tab] = await chrome.tabs.query(queryOptions); + return tab; +} + +// let tab = await getCurrentTab(); + +/** + * Background script. + * + * This only does anything when the bookmarking button is clicked + */ +// chrome.action.onClicked.addListener(function (currentTab) { +// // If no institution has been set, go to the options page to set one +// getActiveTenant(function (tenant) { +// const tab = await getCurrentTab(); +// if (!tenant) { +// // browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround +// chrome.tabs.create({ +// url: 'options.html' +// }); +// } else { +// chrome.scripting.executeScript( +// { +// target: {tabId: tab.id}, +// files: ['/js/bookmarker.js'] +// }, function () { +// chrome.tabs.sendMessage(currentTab.id, {tenant: tenant}); +// }); +// } +// }); +// }); + +chrome.action.onClicked.addListener(bookmark) + +async function bookmark() { + try { + const tab = await getCurrentTab(); + getActiveTenant(function (tenant) { + if (!tenant) { + // browser.runtime.openOptionsPage() not supported by ms-edge, so here's a workaround + chrome.tabs.create({ + url: 'options.html' + }); + } else { + chrome.scripting.executeScript( + { + target: {tabId: tab.id}, + files: ['/js/bookmarker.js'] + }, function () { + chrome.tabs.sendMessage(currentTab.id, {tenant: tenant}); + }); + } + }); + } catch (error) { + console.error(error); + } +} diff --git a/js/bookmarker.js b/js/bookmarker.js index 5bb773d..52ed978 100644 --- a/js/bookmarker.js +++ b/js/bookmarker.js @@ -2,9 +2,9 @@ * Content script to inject the dynamic bookmarking JS directly into the page. */ (function() { - function chromeOrBrowser() { - return this.browser || chrome; - } + // function chromeOrBrowser() { + // return this.browser || chrome; + // } /** * Injected into page to redirect to the dynamic page parser @@ -39,7 +39,7 @@ } } - chromeOrBrowser().runtime.onMessage.addListener(function (message) { + chrome.runtime.onMessage.addListener(function (message) { bookmarkPage(message.tenant); }); })(); diff --git a/js/options.js b/js/options.js index d01dcef..9236678 100644 --- a/js/options.js +++ b/js/options.js @@ -1,4 +1,4 @@ -import {buildTenant, chromeOrBrowser, getActiveTenant, getTenants, saveActiveTenant} from "./tenants"; +import {getActiveTenant} from "./tenants"; $(function() { $('#tenantList').on('change', function() { @@ -15,12 +15,12 @@ $(function() { const otherTenantRegion = $('#tenantRegion').val(); if (!otherTenantCode.trim()) { - $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantShortCodeAlert') + '
'); + $('#optionsHelp').html('
' + chrome.i18n.getMessage('noTenantShortCodeAlert') + '
'); return; } if (!otherTenantRegion.trim()) { - $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantRegionAlert') + '
'); + $('#optionsHelp').html('
' + chrome.i18n.getMessage('noTenantRegionAlert') + '
'); return; } @@ -41,7 +41,7 @@ $(function() { var objects = document.getElementsByTagName('*'), i; for(i = 0; i < objects.length; i++) { if (objects[i].dataset && objects[i].dataset.message) { - objects[i].innerHTML = chromeOrBrowser().i18n.getMessage(objects[i].dataset.message); + objects[i].innerHTML = chrome.i18n.getMessage(objects[i].dataset.message); } } loadTenantList(); @@ -50,7 +50,7 @@ $(function() { function saveActiveTenantAndUpdateStatus(tenant) { saveActiveTenant(tenant, function() { // Update status to let user know options were saved. - $('#status').html('
' + chromeOrBrowser().i18n.getMessage('optionsSettingsSaved') + '
'); + $('#status').html('
' + chrome.i18n.getMessage('optionsSettingsSaved') + '
'); $('#optionsHelp').addClass('hidden'); setTimeout(function() { $('#status').textContent = ''; @@ -61,7 +61,7 @@ function saveActiveTenantAndUpdateStatus(tenant) { function loadTenantList() { getActiveTenant(function(activeTenant) { if (!activeTenant) { - $('#optionsHelp').html('
' + chromeOrBrowser().i18n.getMessage('noTenantAlert') + '
'); + $('#optionsHelp').html('
' + chrome.i18n.getMessage('noTenantAlert') + '
'); } getTenants(function(tenants) { diff --git a/js/tenants.js b/js/tenants.js index 2b01df3..2b26a4a 100644 --- a/js/tenants.js +++ b/js/tenants.js @@ -4,14 +4,14 @@ * * @returns {Object} */ -export function chromeOrBrowser() { - return this.browser || chrome; -} +// export function chrome { +// return this.browser || chrome; +// } -var storage = chromeOrBrowser().storage.sync; +var storage = chrome.storage.sync; if (!storage) { - storage = chromeOrBrowser().storage.local; + storage = chrome.storage.local; } /** * @callback activeTenant @@ -27,12 +27,12 @@ export function getActiveTenant(cb) { storage.get({ activeTenant: null }, function(tenants, err) { - if (chromeOrBrowser().runtime.lastError || typeof tenants === 'undefined' || !tenants.activeTenant) { - chromeOrBrowser().storage.local.get({ + if (chrome.runtime.lastError || typeof tenants === 'undefined' || !tenants.activeTenant) { + chrome.storage.local.get({ activeTenant: null }, function(tenants) { if (tenants.activeTenant) { - storage = chromeOrBrowser().storage.local; + storage = chrome.storage.local; } convertActiveTenantToObject(tenants.activeTenant, function(updatedTenant){ @@ -94,17 +94,17 @@ function convertActiveTenantToObject(activeTenant, cb) { * @param {object} tenant * @param {function()} cb - Callback to run once stored */ -export function saveActiveTenant(tenant, cb) { +function saveActiveTenant(tenant, cb) { storage.set({ activeTenant: tenant }, function() { - if (chromeOrBrowser().runtime.lastError) { - storage = chromeOrBrowser().storage.local; + if (chrome.runtime.lastError) { + storage = chrome.storage.local; return saveActiveTenant(tenant, cb); } else { getActiveTenant(function(t) { if (typeof t === 'undefined') { - storage = chromeOrBrowser().storage.local; + storage = chrome.storage.local; return saveActiveTenant(tenant, cb); } else { cb(); @@ -126,7 +126,7 @@ export function saveActiveTenant(tenant, cb) { * * @param {allTenants} cb */ -export function getTenants(cb) { +function getTenants(cb) { var tenants = {}; getTenantList(function(tenantList) { for (var code in tenantList) { @@ -166,7 +166,7 @@ function getTenantList(cb) { * @param {string} tenantCode - the tenant short code * @param {string} tenantRegion - the region for this tenancy */ -export function buildTenant(tenantCode, tenantRegion) { +function buildTenant(tenantCode, tenantRegion) { return { "name" : tenantCode, "code" : tenantCode, diff --git a/manifest.json b/manifest.json index 7688fe3..cdbbfde 100644 --- a/manifest.json +++ b/manifest.json @@ -10,20 +10,20 @@ "176": "images/icon176.png" }, "background": { - "service_worker": "importBackgroundScripts.js", + "service_worker": "background.js", "type": "module" }, "permissions": [ "activeTab", "scripting", - "storage" + "storage", + "tabs" ], "host_permissions": [ "https://talis-public.talis.com/*" ], "options_ui": { - "page": "options.html", - "chrome_style": true + "page": "options.html" }, "options_page": "options.html", "action": { diff --git a/options.html b/options.html index c214937..d427756 100644 --- a/options.html +++ b/options.html @@ -10,6 +10,21 @@ + + + + + + + + + + + + + + +
diff --git a/package.json b/package.json index 57c8756..182097c 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "talis-reading-lists-bookmarker", "version": "0.3.10", "description": "A browser extension to bookmark resources to Talis Aspire Reading Lists", + "type":"module", "devDependencies": { "grunt": "^1.0.1", "grunt-contrib-copy": "^1.0.0", From 2a7e3d49b1bd2a9a72e723eed84bb67b69ea8d92 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Tue, 4 Oct 2022 09:48:31 +0100 Subject: [PATCH 09/10] ASP-2684: more fiddling - now getting csp violations --- js/allTenants.js | 2 +- js/backgroundExecutor.js | 2 +- js/options.js | 2 +- js/tenants.js | 6 +++--- manifest.json | 4 ++++ options.html | 7 ++++--- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/js/allTenants.js b/js/allTenants.js index 6eeecee..7d8a7b6 100644 --- a/js/allTenants.js +++ b/js/allTenants.js @@ -5,7 +5,7 @@ * The non-branded 'Talis' extension should use the tenant list from: * https://talis-public.s3-eu-west-1.amazonaws.com/talis.com/customers.json */ -const allTenants = { +export const allTenants = { "broadminster" : { "name" : "Broadminster University", "apps" : { diff --git a/js/backgroundExecutor.js b/js/backgroundExecutor.js index 9cafc45..7dd3112 100644 --- a/js/backgroundExecutor.js +++ b/js/backgroundExecutor.js @@ -52,7 +52,7 @@ async function bookmark() { target: {tabId: tab.id}, files: ['/js/bookmarker.js'] }, function () { - chrome.tabs.sendMessage(currentTab.id, {tenant: tenant}); + chrome.tabs.sendMessage(tab.id, {tenant: tenant}); }); } }); diff --git a/js/options.js b/js/options.js index 9236678..76f5498 100644 --- a/js/options.js +++ b/js/options.js @@ -1,4 +1,4 @@ -import {getActiveTenant} from "./tenants"; +import {buildTenant, getActiveTenant, getTenants, saveActiveTenant} from "./tenants.js"; $(function() { $('#tenantList').on('change', function() { diff --git a/js/tenants.js b/js/tenants.js index 2b26a4a..fcd3ebb 100644 --- a/js/tenants.js +++ b/js/tenants.js @@ -94,7 +94,7 @@ function convertActiveTenantToObject(activeTenant, cb) { * @param {object} tenant * @param {function()} cb - Callback to run once stored */ -function saveActiveTenant(tenant, cb) { +export function saveActiveTenant(tenant, cb) { storage.set({ activeTenant: tenant }, function() { @@ -126,7 +126,7 @@ function saveActiveTenant(tenant, cb) { * * @param {allTenants} cb */ -function getTenants(cb) { +export function getTenants(cb) { var tenants = {}; getTenantList(function(tenantList) { for (var code in tenantList) { @@ -166,7 +166,7 @@ function getTenantList(cb) { * @param {string} tenantCode - the tenant short code * @param {string} tenantRegion - the region for this tenancy */ -function buildTenant(tenantCode, tenantRegion) { +export function buildTenant(tenantCode, tenantRegion) { return { "name" : tenantCode, "code" : tenantCode, diff --git a/manifest.json b/manifest.json index cdbbfde..1524a76 100644 --- a/manifest.json +++ b/manifest.json @@ -38,6 +38,10 @@ "40": "images/icon40.png" } }, + "content_security_policy": { + "extension_pages": "script-src 'self'; object-src 'self'", + "sandbox": "sandbox allow-scripts; script-src 'self' object-src 'self'" + }, "default_locale": "en", "manifest_version": 3 } diff --git a/options.html b/options.html index d427756..ef39161 100644 --- a/options.html +++ b/options.html @@ -7,9 +7,10 @@ - - - + + + + From 4ef3a5f76ba99b23b46ffe764d7370b515676608 Mon Sep 17 00:00:00 2001 From: Mike Rudd Date: Tue, 4 Oct 2022 10:23:51 +0100 Subject: [PATCH 10/10] ASP-2684: remove csp from manifest --- manifest.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/manifest.json b/manifest.json index 1524a76..cdbbfde 100644 --- a/manifest.json +++ b/manifest.json @@ -38,10 +38,6 @@ "40": "images/icon40.png" } }, - "content_security_policy": { - "extension_pages": "script-src 'self'; object-src 'self'", - "sandbox": "sandbox allow-scripts; script-src 'self' object-src 'self'" - }, "default_locale": "en", "manifest_version": 3 }