1

After Google Docs' update to canvas based rendering instead of HTML rendering, is it possible to force Google Docs' to render HTML from a chrome extension instead of a canvas? Somehow chrome extensions like Grammarly are able to do it but I'm not entirely sure how.

From my research though I think what allows them to do it through the _docs_force_html_by_ext variable, however I believe this is only for whitelisted extensions.

Is there some sort of alternative or a form I can fill out to get my extension whitelisted?

enter image description here

_docs_force_html_by_ext is undefined:enter image description here

_docs_force_html_by_ext is set through Grammarly:enter image description here

Hudson Kim
  • 416
  • 6
  • 15
  • 1
    This variable should be set as `window._docs_force_html_by_ext =true` inside [page context](/a/9517879) and your content script should run at [document_start](https://developer.chrome.com/extensions/content_scripts#run_time). – wOxxOm Nov 02 '21 at 07:56
  • @wOxxOm - Do you know if setting this variable (to force HTML mode) works in Firefox extensions also? – Lord Null Jan 26 '22 at 20:49

2 Answers2

7

There are two solutions to the problem: For older versions of Google Docs And for new versions.

Solution is for older versions of Google Docs

You need to add the GET-parameter ?mode=html to the URL.

For example if document URL is:
docs.google.com/document/exampleId/edit

Change URL to:
docs.google.com/document/d/exampleId/edit?mode=html

This will force Google Docs to use HTML-renderer.


Update March 4, 2022

Google changed the html render activation code. The html renderer is in the current code, and it works if you turn it on manually. I'm now looking into what new conditions need to be met to enable it automatically. I will report the results later.


Update March 9, 2022

The New solution

Once again, it proves that Google programmers are not as good as they are made out to be. So...

Now there are three ways to enable html rendering. At least I found three:

  1. Before the start of the Google Docs code:
    window._docs_force_html_by_ext == true ? 'html render' : 'canvas render'
  2. Before the start of the Google Docs code:
    (GET['mode']=='html' && window._docs_flag_initialData['kix-awcp'] == true) ? 'html' : 'canvas'
  3. Set the required parameters manually in the right place in the Google Doc code.

But, programmers at Google forgot that the window object also contains references to elements that have an id attribute set. For example:

HTML:
<span id="spanId"></id>
JS:
window['spanId'] == true;

That is, if we can add an id attribute to any element on the page, the value of which will be equal to _docs_force_html_by_ext, then we will automatically receive an identifier in the window object with !=false value. From which it follows that html rendering will turn on, since the conditions of method 1 are met. For example

<body id="_docs_force_html_by_ext ">

Hint 1: As far as I know, any browser plugin can run before the main code and add an id attribute to any element.

Hint 2: link element can have an id attribute to. I think you get the hint.

Demi Murych
  • 129
  • 3
  • Demi, how did you find that? Your response is the only place I've seen that mentioned (and I'm glad I saw it because it's very useful.) Are you aware of any way to permanently force Docs to render as HTML? IMO Docs has become almost unusable now in Firefox since the switch to using Canvas...text is blurry. – Lord Null Jan 26 '22 at 20:34
  • 3
    I did reverse engineering of all Google docs. – Demi Murych Feb 02 '22 at 00:55
  • Thank you, @Demi Murych. I was happily using your ?mode=html code and recently noticed that even with that addition the text seemed to be blurry again. I thought it was just my eyes! But now I see from your comment something has changed behind the scenes. Please let us know if you discover how to fix this again . It's annoying that Google keeps messing with this. – Lord Null Mar 05 '22 at 12:59
  • Demi, your points 1 and 2...they seem to use the ternary operator and return some text ('html render'/'html' if true or 'canvas render'/'canvas' if false), but what is this text for? Where does it go? Your code doesn't seem to be setting any variable with the returned text, does it? – Lord Null Mar 09 '22 at 13:29
  • 1
    My code explains what happens if certain conditions are met. For example I write: window._docs_force_html_by_ext == true ? 'html render' : 'canvas render' This code should be understood as - if before running the Google Docs script, the window._docs_force_html_by_ext identifier is set to a value that makes the expression window._docs_force_html_by_ext == true true, then html rendering will be enabled. That is, you need to set the value of the window._docs_force_html_by_ext identifier to any value before running the Google Docs code. I described other conditions in the same way. – Demi Murych Mar 09 '22 at 19:16
  • Demi...it looks like Google have changed something AGAIN! Text in a Google Doc in FF looks blurry again. I was setting window._docs_force_html_by_ext = true to fix this and it seems to have worked right up to today. But it looks odd again. Any ideas how this can be fixed now, or what needs to be set to have the page render as HTML? Thanks. – Lord Null Mar 30 '22 at 16:49
  • 1
    Yes. I work about this – Demi Murych Apr 01 '22 at 07:14
  • 1
    Any updates on this? @DemiMurych – Samarth Agarwal Apr 06 '22 at 19:33
  • 1
    I would be interested to know about this too. – Michael Apr 06 '22 at 22:54
  • 1
    Apparently, Google itself does not understand what is happening. Google programmers for one week either adds a white list of modules that are allowed htmlrender, then resets it three days later. Right now there is only one universal way to disable canvas rendering. We need to find a function that contains the literal _docs_force_html_by_ext. This function must be forced to return true. It's easy by hand. There are two more new behaviors. I analyze them. – Demi Murych Apr 07 '22 at 00:37
  • Yes I see what you're saying @DemiMurych. This is the function: `function jJd(a) { var b = To._docs_force_html_by_ext; b ? U(a, 'kix-dhf') ? (usd(), a = gv(tsd, b)) : a = !0 : a = !1; return a } ` If I force that function to return true (using FireFox Dev Tools) then the Doc renders as HTML. (This is obvious in FF because the text is crisp when rendered as HTML but blurry when rendered as Canvas.) Now, how to make that function return true using a WebExtension, that's the problem! – Lord Null Apr 07 '22 at 14:59
0

Google is whitelisting some applications which can use a script forcing the document to a HTML Fallback version which reminds of the time before canvas or as an Annotated Canvas which makes it possible to make extension integrations with the SVG canvas.

You need to apply for whitelisting to access these features: https://docs.google.com/forms/d/e/1FAIpQLScFxMgvXlq2KMsp0UIM66pvThTF1hpojiXQTqyq9txW79OWag/viewform

Axtru
  • 171
  • 1
  • 9
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/low-quality-posts/31194666) – Mario Petrovic Mar 02 '22 at 11:21
  • 1
    The message is small, so pasted it all and kept a link for the origin. – Axtru Mar 02 '22 at 12:26
  • If you believe that another question has answers to this question, the correct thing to do is flag the question as a duplicate, not post the same answer. – General Grievance Mar 02 '22 at 13:51
  • Is the newest question then the one which should get flagged, or does this not matter? – Axtru Mar 02 '22 at 14:18
  • The less popular one should point to the more popular one. – General Grievance Mar 02 '22 at 18:10
  • I have flagged the other (newer) post and removed the link at this post. Hope its satisfying. – Axtru Mar 02 '22 at 22:08