alpheios-project / webextension

Alpheios Browser Extensions
ISC License
6 stars 2 forks source link

upgrade to Manifest V3 (Chrome and FF) #324

Open balmas opened 2 years ago

balmas commented 2 years ago

FF will start supporting their implementation of Manifest V3 in 2022 and will deprecate support for V2 in 2023. Chrome already supports Manifest V3 and will stop accepting new extensions using V2 in 2022 (although will allow update of existing extensions).

Sometime in early 2022 we should update both FF and Chrome to V3.

References: https://blog.mozilla.org/addons/2021/05/27/manifest-v3-update/?utm_source=newsletter&utm_medium=email&utm_campaign=about-addons-2021-august https://developer.chrome.com/docs/extensions/mv3/mv2-sunset/ https://developer.chrome.com/docs/extensions/mv3/intro/

See also related issue #270

irina060981 commented 2 years ago

I examined steps - and the biggest:

a. we need to change one technology (background script) to the other (service workers) - I don't have an estimation for this task as I didn't do such work before

b. we need to remove direct executing code from Events (like this BackgroundProcess.executeScript(tabId, { code: "document.body.dispatchEvent(new Event('Alpheios_Embedded_Check'))" })

it would need some refactoring - I don't think that it would need a lot of time

c. we need to refactor permissions (again) and check that everything is still working

d. we need to refactor browserAction and update to new API

e. we need to refactor tabs.executeScript and update to new API

f. We need to Move CORS requests to the background service worker.

We have different remote requests - from client-adapters, from chinese dictionary, may be something else - I am not sure - do they consider to be CORS requests. Will need investigation and tests

irina060981 commented 2 years ago

If you need to run Auth0 in Content Script or Background

Special thanks to @dhruv2204 for guiding me with this.

Use Manifest V2. Also Use @auth0/auth0-spa-js inside the background page and make the calls there.

The reason for this is because auth0 needs access to the DOM and background service workers (from manifest v3) do not have access to the DOM. Please not that manifest v2 will be deprecated soon. They just have not released an official deprecation date so for now this can work

Just use the chrome messaging API to call the the methods from content script if necessary. Doing this still works with the earlier mentioned methods.

Background.html

Background.js:

import { Auth0Client } from '@auth0/auth0-spa-js'

const auth0 = new Auth0Client({ domain: , client_id: , redirect_uri: //chrome-extension:extensionid })

const getToken = async () => { const token = await auth0.getTokenSilently() return token } from https://community.auth0.com/t/ultimate-guide-to-auth0-in-a-chrome-extension-popup/61362/6

irina060981 commented 2 years ago

Release without Auth support - https://github.com/alpheios-project/webextension-manifest-v3