diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2023-12-29 00:01:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-29 05:01:11 +0000 |
commit | 0a68020771fc5b9dd437a90d5aac5e8a0c66719b (patch) | |
tree | 48a0c4c25977343dd15da06e19807f332ca62ddb /ext/js/accessibility/accessibility-controller.js | |
parent | d90d408279938d389019a8bed15c5eb95af7c8bc (diff) |
Fix google docs (#473)
* Add support for content script execution world
* Update manifest version to support world parameter in Chromium browsers
* Update google docs injection
* Reuse code for registration
* Add info
Diffstat (limited to 'ext/js/accessibility/accessibility-controller.js')
-rw-r--r-- | ext/js/accessibility/accessibility-controller.js | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/ext/js/accessibility/accessibility-controller.js b/ext/js/accessibility/accessibility-controller.js index 2b352948..4dced51b 100644 --- a/ext/js/accessibility/accessibility-controller.js +++ b/ext/js/accessibility/accessibility-controller.js @@ -86,14 +86,13 @@ export class AccessibilityController { try { if (forceGoogleDocsHtmlRenderingAny) { if (await isContentScriptRegistered(id)) { return; } - /** @type {import('script-manager').RegistrationDetails} */ - const details = { - allFrames: true, - matches: ['*://docs.google.com/*'], - runAt: 'document_start', - js: ['js/accessibility/google-docs.js'] - }; - await registerContentScript(id, details); + try { + await this._registerGoogleDocsContentScript(id, false); + } catch (e) { + // Firefox doesn't support `world` field and will throw an error. + // In this case, use the xray vision version. + await this._registerGoogleDocsContentScript(id, true); + } } else { await unregisterContentScript(id); } @@ -101,5 +100,25 @@ export class AccessibilityController { log.error(e); } } -} + /** + * @param {string} id + * @param {boolean} xray + * @returns {Promise<void>} + */ + _registerGoogleDocsContentScript(id, xray) { + /** @type {import('script-manager').RegistrationDetails} */ + const details = { + allFrames: true, + matches: ['*://docs.google.com/*'], + runAt: 'document_start', + js: [ + xray ? + 'js/accessibility/google-docs-xray.js' : + 'js/accessibility/google-docs.js' + ] + }; + if (!xray) { details.world = 'MAIN'; } + return registerContentScript(id, details); + } +} |