-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Google Docs will now use canvas based rendering: this may impact some Chrome extensions #10
Comments
Thank you, don't look like there is any workaround. Will have to build an actual Google Workspace addon. |
Maybe it is only for For For me, at the moment, But yes, if there will be canvas-rendering instead of HTML-rendering, then it will be a problem. |
How you created this preview? Can you provide steps? |
The original post from Google can be found here: https://workspaceupdates.googleblog.com/2021/05/Google-Docs-Canvas-Based-Rendering-Update.html Do they support any kind of accessibility API with the new design? |
An discussion can be found here: https://news.ycombinator.com/item?id=27129858 |
Google have updated their post and opened a small possibility. If you open "Accessibility Settings" --> "Turn on Screen reader support", Google Docs will emit Readable HTML with the actual text. If possible the Google Docs Util code should:
|
Thank you @JensPLarsen
I suppose no. For external JS, which didn't create the canvas, it is very hard to interact with 2D context of canvas (I mean, CRUD operations with canvas content). For example, Yandex.Disk Word editor uses canvas based rendering and for me it wasn't possible to somehow interact with document content.
The problem here is that this provides only ability to read document content. But this library need to have all CRUD operations in order to provide all already implemented functionality. Sure, I will check possibility to interact with document through that "small possibility", but highly unlikely that it will provide all needed things to support this project. |
So, I think this project will die when Google Docs will release the canvas based rendering feature. Unfortunately, at the moment it doesn't look like there is anything that can be done about it |
I agree, if anything it would most likely result in a new project which contains a subset of what this can. And I fear a new project may have the same issue when Google Docs changes to use WebAssembly (or something else) and everything changes again in X years. |
Are there any alternatives to this library that work with with the canvas based rendering, or are there plans to update the library? |
No, as I'm aware.
No, at the moment. |
Darn that sucks. |
How is Grammarly doing it then? https://chrome.google.com/webstore/detail/grammarly-for-chrome/kbfnbcaeplbcioakkpcpgfkobkghlhen?hl=en |
Google provided temporary support for such extensions. If the extension needs to interact with a document through DOM, then the extension can force Google Docs to use HTML-based rendering instead of canvas-based rendering. It is controller via In that case Google Docs will use HTML instead of canvas.
However, only whitelisted extensions can use this But anyway, this feature is just a temporary workaround to give developers some time to adapt their extensions. This feature will be disabled soon, maybe in 2021, so it is not reliable. After that we will see which extensions are able to interact with Google Docs through canvas. |
According to my above answer. If you want to use this library, you should install extension which enables HTML-based rendering instead of canvas-based rendering: Grammarly, Smart Copy, etc. |
I see, I'll try and contact Google to get whitelisted, although having to install a second extension just to use mine wouldn't be very practical for users. |
You don't actually need to be whitelisted or install any other extensions. You can force html rendering by adding |
Confirm 👍 Although Google clearly specifies that HTML fallback option has been deprecated and will slowly be removed from production. |
Thanks! @Amaimersion Does Google mention any specific date? Where do they mention it will be removed from production? |
They mention it through email. Emails are send to those who is subscribed to https://sites.google.com/corp/google.com/docs-canvas-migration/home They planning to remove it completely to the end of February. |
Sad times. |
Sad indeed : / |
Wait a minute: @Amaimersion Do you know how did Grammarly make it work on canvas? They are not using the whitelisting anymore, if you inspect the DOM when Grammarly is enabled you can see it works on canvas. I have tried forcing ?mode=html and it also works. Which means Grammarly somehow managed to make it work to read the text from canvas. Now the question is, how? Grammarly using CanvasGrammarly using DOM |
I have just downloaded the source code from the Grammarly extension and I found some interesting stuff there. For instance, there is getText function They have a file named I have used this extension to get Grammarly source code https://chrome.google.com/webstore/detail/chrome-extension-source-v/jifpbeccnghkjeaalbbjmodiffmgedin?hl=en |
@gzomer this is interesting, did you happen to get it to work of the grammarly extension? |
That code is a bit complicated but if we can put a breakpoint in that getText function it will be clear |
I was able to partially get the full text. On the onRender function here you can just call However, there is one downside. I couldn't make it work without Grammarly extension enabled. There is a sort of a connection between docs and Grammarly So it seems to be possible, we just need to figure out how. I have pushed the whole source code here: https://github.com/gzomer/grammarly-extension So far the ones that seem to be relevant are: |
I think this function gets the relevant elements for extracting text. Then this function decodes it into usable text. Neither of those steps looks trivial. |
@Omegastick I use Chrome DevTools to put a breakpoint in that content script It turns out That variable isn't accessible from the content script's context. I'm not sure how they are able to access it from their content script. The only way I know how to do something like that is by adding a script tag that will execute in the page's JavaScript context, JSON.stringify that variable and pass it to the content script via postMessage. But maybe they're doing some other way. Edit: ah, got it. The bulk of their scripts executes in the page's JS context. The content script is Edit: and the statement on line 943 is how they search for the text. |
For any one interested, I made a list of the whitelisted ids with most downloads. Here is a sample
|
Just for anyone who applys to get white listed. Mine got approved but I was never notified of it. |
I'm not exactly sure what this repo is for, but I stumbled upon it trying to figure out how to force google docs into html render mode, and I ended up giving the code from @dbjpanda above to ChatGPT and it helped me make this userscript that can be run with Tampermonkey to solve the issue! Just in case it helps anyone else that stumbles here:
|
I finally able to achieve it and built a chrome extension that works on Google Docs https://chrome.google.com/webstore/detail/chatgpt-chrome-extension/gabfffndnhbbjlgmbogpfaciajcbpkdn |
Can you share how you got this library to work? |
Anyone willing to share how they're able to get this library to work. @dbjpanda @lionelhorn I'm able to get docs to render the svgs. Can access a few things like However, I'm not able to get the selected text. I've tried: Doesn't trigger anything when text is selected
GoogleDocsUtils.getSelection(); returns an empty array
|
I am trying to use a whitelisted ID but can not see any difference in how the canvas is rendered. Could it be that Google implemented a fix that compares the extension ID with the ID in the code? Also how long does it take to get whitelisted? |
@RobertJGabriel Hello, could you please tell me how long does it take to get whitelisted? I applied it two days ago, but my extension id is not in whitelist yet. |
The link is not working. Would love to see the code in the link. |
Mine took around three weeks to be whitelisted 🙈 |
How to get whitelisted? What to expect after whitelisting? |
You can get whitelisted here: Once you are whitelisted you will be able to use your extension ID to convert the canvas to a readable DOM. Important: Google will not inform you once you are whiltelisted, you need to constantly try it to see whether you are whitelisted yet. Previous answers include IDs that you can use to test it while you wait for your extension to be whitelisted |
is this with whitelisting id or works without it as well? |
I guess it won't, bc it operates with svg annotated from canvas after injecting: |
I am thinking to create a package https://github.com/dbjpanda/gdocs-utils. I will push some snippets by EOD. |
OK, thanks. (This takes really long ORZ) |
@ElijZhang Sorry, have you found out a way to get the selected text? |
@RafaOstrovskiy I found a not a very good way to get the selected text by analyzing some extension that are in the whitelist.In google docs page which is rendered with
Now you get the |
I have spent the last 3 days reverse engineering Language Tool's code, and it's really easy once you get the initial hold of it. If there is no selection, you will need to make one. You can check this by it's class ( To create a selection, you essentially have to simulate mouse events, which then selects the text in docs. After making a selection, you send a copy event ( This does not seem to edit clipboard content in my experience. |
@swoorpious or @dbjpanda Can you help me with changing text in the doc? Currently I can get the caret, the selected text, I can list the paragraphs, etc. The only thing I really want to do is "typing" into the document.
Seems like none of this worked. What is the trick here? |
@tg44 got write working with the below: gdocs-enable-annotated-canvas.js window._docs_annotate_canvas_by_ext = "ogmnaimimemjmbakcfefmnahgdfhfami"; contentScript.js const writeTextToGDoc = 'hello world'
// write letter to gdoc
function write(letter, doc) {
const i = new KeyboardEvent("keypress", {
repeat: !1,
isComposing: !1,
bubbles: !0,
cancelable: !0,
ctrlKey: !1,
shiftKey: !1,
altKey: !1,
metaKey: !1,
target: doc,
currentTarget: doc,
key: letter,
code: "Key" + letter.toUpperCase(),
keyCode: letter.codePointAt(0),
charCode: letter.codePointAt(0),
which: letter.codePointAt(0),
...{}
})
doc.dispatchEvent(i)
}
setTimeout(() => {
const doc = document.querySelector(".docs-texteventtarget-iframe").contentDocument
for (const letter of writeTextToGDoc) write(letter, doc)
}, 5000); manifest.json ...
"content_scripts": [
{
"matches": [
"*://docs.google.com/document/*"
],
"run_at": "document_start",
"js": [
"gdocs-enable-annotated-canvas.js"
],
"world": "MAIN"
},
{
"matches": [
"*://docs.google.com/document/*"
],
"js": [
"contentScript.js"
],
"all_Frames": false,
"run_at": "document_end"
}
],
... |
@tg44 The way docs handles events is a little unintuitive. If you want to enter text in the document, you use
Example code for the above: static InsertChar (char) {
const IFTarget = GoogleDocsUtils.GetIFEventTarget();
for (let i = 0; i < char.length; i++) {
const eventObj = {
bubbles: true, // important
cancelable: true, // important
key: char,
keyCode: char.charCodeAt(i), // important
ctrlKey: false,
shiftKey: false,
}
IFTarget.dispatchEvent(new KeyboardEvent("keypress", eventObj))
}
return 1;
} If you want to move the caret with keyboard events, or delete characters (backspace and delete on keyboard), you use Example code for the above: static MoveCaretToLeft (n) {
const IFTarget = GoogleDocsUtils.GetIFEventTarget();
const eventObj = {
bubbles: true, // important
cancelable: true, // important
code: "ArrowLeft",
key: "ArrowLeft",
keyCode: 37, // important
ctrlKey: false,
shiftKey: false,
}
for (let i = 0; i < n; i++) {
IFTarget.dispatchEvent(new KeyboardEvent("keydown", eventObj))
}
return 1;
} If you want to select text and move it to other locations in the document, you will need a sequence of mouse and keyboard events. You can try to write them based on how you select text with your mouse. Mouse events need to be dispatched at screen coordinates (pixels) that you can calculate with indexes or caret position.
|
Can you tell me how to get the selected text? I looked at the sample code above and I can insert text. |
@zdw189803631 You can reach out to me https://www.linkedin.com/in/dbjpanda/ or send me an email, drop your code, I will try to look into it. |
@dbjpanda i have send email by https://dbjpanda.me/contact website |
@zdw189803631 |
swoorpious/web_server_cpp#1 |
Just bring it up as and issue and will be willing to help on any develop to get it ready.
Here is the canvas based example https://docs.google.com/document/d/1N1XaAI4ZlCUHNWJBXJUBFjxSTlsD5XctCz6LB3Calcg/preview
@menicosia @ken107 @bboydflo @Amaimersion @JensPLarsen
The text was updated successfully, but these errors were encountered: