Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: EME Logger Manifest V3 Migration (#51)
The Chrome browser will no longer run Manifest V2 extensions after January 2023 as per [The transition of Chrome extensions to Manifest V3](https://developer.chrome.com/blog/mv2-transition/). Hence, EME Logger's Manifest version needs to be updated from V2 to V3: * log-window.js: * The background page is replaced with a service worker since the background page cannot be used with manifest v3. * `chrome.extension.getURL` is replaced with `chrome.runtime.getURL`. * Removed this line `window.EmeLogWindow = EmeLogWindow;` because `window` is not defined in the log_window.js since the script is running in a service worker (a separate thread). Now the singleton instance of EmeLogWindow (`EmeLogWindow.instance`) lives in the service worker. * Replaced `window.open` with `chrome.windows.create` to create a new window * `chrome.browerAction` is replaced with `chrome.action`. * Moved the logic handling DOM from the service worker (log-window.js) to the log window (log.js) and communicated between two scripts via chrome message handling APIs since a service worker cannot access the `document` or DOM object. As a result, `EmeLogWindow.appendLog()` and `clear()` code dealing with the document object has been moved to the log window script (log.js) * Used `chrome.downloads.download` APIwith adding "downloads" to the "permission" section in the manifest file since `URL.createObjectURL` is not available in a service worker. * manifest.json: * `web_accessible_resources` is now an array of objects instead of a single object. * `browser_action` is replaced with `action`. * Added "<all_urls>" into `matches` in the `web_accessible_resources` section because no log is getting collected due to the permission issue. * log.js: * Used `chrome.runtime.onMessage.addListener` and `chrome.runtime.sendMessage` APIs to communicate because the pop-up window (log.js) cannot access the EmeLogWindow instance in the service worker (log-window.js). * Used `chrome.windows.onRemoved.addListener` to observe the termination of window because there is no `.closed `property in the window created by `chrome.windows.create`. * content-script.js: * `chrome.extension.getURL` is replaced with `chrome.runtime.getURL`. * spec/log-window-tests.js: * Added the mock & fake properties/methods for `chrome.runtime` and `chrome.windows` APIs because Jasmine-browser and Selenium-webdriver are not working with chrome APIs and we need test code changes to test async calls. * Updated the required dependency packages: `npm run build & npm test` complains about the out-dated versions of selenium-webdriver and other dependencies * Used Promise/async-wait patterns for `EmeLogWindow.instance.open()` API tests. Otherwise, EmeLogWindow.instance.isOpen()'s return value is not guaranteed since `.open()` is an async operation. * Added new test cases for `EmeLogWindow.instance.appendLog()` and `EmeLogWindow.instance.clear()` APIs * spec/support/jasmine-browser.json: * Added "log.js" to the `srcFiles` section because we cannot directly test the `appendLog()` logic without the chrome messaging APIs that are not available on the Jasmine framework. As a workaround, log-window-tests.js calls the `appendLog()` method defined in the log.js first and passes it down `EmeLogWindow.appendLog()` in the tests. * package-lock.json: * Updated selenium-webdriver to the latest version (4.3.1) to fix the Invalid URL issue by selenium-webdriver when running `npm test`. Other dependencies are updated together. Co-authored-by: Sangbaek Park <[email protected]>
- Loading branch information