From c7aab5853881909d3a5a6c75d781a8bd7fed1587 Mon Sep 17 00:00:00 2001 From: Bradley Erickson Date: Tue, 10 Dec 2024 15:58:52 -0500 Subject: [PATCH 1/3] fixed bug with inject.js that caused issues with the google CSP --- VERSION | 1 + extension/writing-process/src/inject.js | 19 ------------------- 2 files changed, 1 insertion(+), 19 deletions(-) create mode 100644 VERSION delete mode 100644 extension/writing-process/src/inject.js diff --git a/VERSION b/VERSION new file mode 100644 index 000000000..7d5555de9 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2024-12-10-15:58:52.933-aabd8078-berickson/202412-extension-fixes diff --git a/extension/writing-process/src/inject.js b/extension/writing-process/src/inject.js deleted file mode 100644 index 613429ba3..000000000 --- a/extension/writing-process/src/inject.js +++ /dev/null @@ -1,19 +0,0 @@ -/* - Inject script. This is a web_accessible_resources used to pass the id - of the document as a globally accessible variable to the extension. - It is called by the injectScript function in writing.js to make the result - accessible using an event listener. - - TODO: - * We don't really understand this code. It should be commented - * In particular, why are we using an IIFE (immediately invoked function - expression) rather than just the code? - - If this is a relic, it should be cleaned up. If this has a - reason, it should be documented. -*/ - -(function() { - const result = JSON.stringify(_docs_flag_initialData.info_params.token); - window.postMessage({ from: 'inject.js', data: result }); -})(); From b49ac2f6e3fe344d38c4f0fc2f8d73be47750e6a Mon Sep 17 00:00:00 2001 From: Bradley Erickson Date: Tue, 10 Dec 2024 16:00:00 -0500 Subject: [PATCH 2/3] added the files this time --- VERSION | 1 - extension/writing-process/src/manifest.json | 5 -- extension/writing-process/src/writing.js | 84 ++++++++++----------- 3 files changed, 42 insertions(+), 48 deletions(-) delete mode 100644 VERSION diff --git a/VERSION b/VERSION deleted file mode 100644 index 7d5555de9..000000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -2024-12-10-15:58:52.933-aabd8078-berickson/202412-extension-fixes diff --git a/extension/writing-process/src/manifest.json b/extension/writing-process/src/manifest.json index 9d26efaa6..f663bf58f 100644 --- a/extension/writing-process/src/manifest.json +++ b/extension/writing-process/src/manifest.json @@ -36,11 +36,6 @@ "matches": ["*://docs.google.com/document/*"], "js": ["3rdparty/sha256.js", "writing_common.js", "writing.js"] }], - "web_accessible_resources": [{ - "resources": ["inject.js"], - "matches": ["*://docs.google.com/*"], - "use_dynamic_url": true - }], "host_permissions": [ "*://docs.google.com/document/*" ], diff --git a/extension/writing-process/src/writing.js b/extension/writing-process/src/writing.js index 1367e8a81..6a8cbc2ce 100644 --- a/extension/writing-process/src/writing.js +++ b/extension/writing-process/src/writing.js @@ -3,7 +3,7 @@ */ /* For debugging purposes: we know the extension is active */ -document.body.style.border = "5px solid blue"; +// document.body.style.border = "1px solid blue"; import { googledocs_id_from_url, treeget } from './writing_common'; /* @@ -142,29 +142,31 @@ function is_string(myVar) { } } -function injectScript(file_path, tag) { - /* - This function is to inject a script from 'file_path' - into a specific DOM tag passed in as 'tag' - */ - var node = document.getElementsByTagName(tag)[0]; - var script = document.createElement('script'); - script.setAttribute('type', 'text/javascript'); - script.setAttribute('src', file_path); - node.appendChild(script); -} - -function execute_on_page_space(code){ - /* This is from - https://stackoverflow.com/questions/9602022/chrome-extension-retrieving-global-variable-from-webpage - - It is used to run code outside of the extension isolation box, - for example to access page JavaScript variables. +function extractDocsToken() { + /** + * We need the doc token to be able to fetch the document + * history. This token is provided via a