1

I am currently working on a Chrome extension and want it to work on Google Docs to highlight the text. Google docs is moving to the Canvas rendering for pages which basically removes all the text from the DOM and we only have a canvas element in the DOM for every page.

I have noticed that by setting window._docs_force_html_by_ext = <extension-id> on the Google docs webpage, we can force it to render DOM as HTML, not as canvas. This works fine for me. I have also seen some extensions set window._docs_annotate_canvas_by_ext = <extension-id> and that ensures that the canvas rendered is annotated with a lot DOM elements inside the canvas element. This annotated canvas allows for positional computations for the text.

I have tried inserting the script the same way but it does not seem to have any effect on the DOM. Is there anything else I need to do?

Any help is highly appreciated. Thanks in advance.

Samarth Agarwal
  • 2,044
  • 8
  • 39
  • 79

1 Answers1

0

At the current moment in time the HTML Fallback option will render before the Annotated Canvas option. This means that if you have any extension running that forces the HTML Fallback option then the Annotated Canvas option wont render.

This is sad news for those who has a running integration with Annotated Canvas option because any other application installed might force the script back to the HTML Fallback option.

Personally i apply a simple check and handle both solutions based on what the document returns:

const runInitializers = (): void => {
  const canvasFirstPage = document.querySelector(
    '#kix-appview > div.kix-appview-editor-container > div > div:nth-child(1) > div.kix-rotatingtilemanager.docs-ui-hit-region-surface > div > div.kix-page-paginated.canvas-first-page'
  );

  const fallbackFirstPage = document.querySelector(
    '#kix-appview > div.kix-appview-editor-container > div > div:nth-child(1) > div.kix-zoomdocumentplugin-outer > div > div > div > div:nth-child(2) > div'
  );

  if (canvasFirstPage) {
    initAnnotatedCanvas();
  } else if (fallbackFirstPage) {
    initHTMLFallback();
  }
};
Axtru
  • 171
  • 1
  • 9
  • That's not my question. My question is how to force gdocs to render annotated canvas. – Samarth Agarwal Mar 02 '22 at 18:49
  • Ah, sry for our misunderstanding. I've been working with some of the same issues thus understood your problem could be caused by another extension forcing the HTML Fallback, while you were trying to make your application force the Annotated canvas. See this post where its explained that you need a whitelist to access these features for your extension. https://stackoverflow.com/a/71321036/5432087 – Axtru Mar 02 '22 at 21:54
  • When you are approved for whitelisting then you should receive access to the documentation provided by the Google Docs team. – Axtru Mar 02 '22 at 22:11
  • Does anyone know how to force Docs to render as HTML? In FireFox the Canvas rendering is terrible, causes text/links to be blurry. In HTML rendering everything is crisp. Previously was able to append ?mode=html to URL, and when that stopped working was able (via an extension) to set window._docs_force_html_by_ext = true and that forced HTML rendering. Both of those approaches no longer seem to work. – Lord Null Mar 31 '22 at 21:05
  • The HTML fallback is a temporary option which is bound to be phased out eventually. – Axtru Apr 01 '22 at 11:32
  • @Axtru Do you have any links to the documentation? I filled out the form and seems like my extension ID is whitelisted as well but haven't received any acknowledgement or documentation. Since the HTML fallback does not work anymore, some documentation will definitely help. – Samarth Agarwal Apr 07 '22 at 06:33
  • The documentation can be found here: https://sites.google.com/google.com/docs-canvas-migration/home It can only be accessed by the google account that where used when applying for the whitelist. – Axtru Apr 07 '22 at 07:21
  • Nope. It does not open for me. I tried with the exact account I used to fill out the form. If you have access, can you share a version? – Samarth Agarwal Apr 07 '22 at 09:52
  • Some person will probably share it in the future, but it is not going to be me. Sorry, I believe that the Docs Canvas team made it this way for a reason. What I can tell you is that most of the examples at the docs are simply depictions of the expected return format of the canvas at the HTML DOM. It does not give examples on how to solve your problems, you can only use it to ensure that the HTML fallback or Annotated canvas is setup the right way. So if you are able to get it to return the annotated canvas, then its exactly the same offset everyone else had to make an integration with. – Axtru Apr 07 '22 at 13:42
  • Does the documentation state anything about deprecation of the annotated canvas? Will that be phased out eventually as well? Also, do you have any idea regarding how some browser extensions are working on canvas mode without forcing the annotation of the canvas? – Samarth Agarwal Apr 08 '22 at 19:41
  • 1
    The documentation states for the HTML fallback and the Annotated canvas, that: "..these are temporary solutions, we are providing them 'AS-IS' and are unable to make any commitments, including promises relating to their reliability, availability or capability". Those applications could be using the Google Docs Rest API you can find the documentation here: https://developers.google.com/docs/api/reference/rest . – Axtru Apr 11 '22 at 09:27