Read contents from a Google document

157 views
Skip to first unread message

Martin Sonesson [C]

unread,
Jun 20, 2024, 7:22:36 AMJun 20
to Chromium Extensions
Lets say I open a document in my browser on . I want my extension to be able to read the contents of the the document of the current page, in order to look for certain words like if the document contains references to malicious URLs or CVE-references.

Before this was no problem, but a few years back Google changed so that google docs would use a canvas-element to generate all the document UI, so you can no longer read the document content by just traversing the DOM tree.

Is there any way around this? Any API I can use? There seems to be some way because other extensions seem to be able to access the document contents, like this one:

Oliver Dunk

unread,
Jun 20, 2024, 7:34:56 AMJun 20
to Martin Sonesson [C], Chromium Extensions
Hi Martin,

You can find more information from the Docs team about the move to canvas rendering here: https://workspaceupdates.googleblog.com/2021/05/Google-Docs-Canvas-Based-Rendering-Update.html. I appreciate that this makes things harder for building Chrome extensions, and we do regularly pass on feedback. Unfortunately however, it's not a decision we have control over.

If you're just looking to build something for fun, I would say that this is probably too tricky to be worthwhile right now. If you have a more serious use case, I'd encourage you to fill out the form linked in that blog post, even if you don't strictly fall into the audience that form was targeted to. Google Docs has some functionality where allowlisted extensions can enable an "annotated canvas" mode that provides more information in the DOM. My understanding is that they regularly reach out to respondents of that form to offer access and more information.

Thanks,
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB


--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/4c4a5527-dbc6-4fb5-9136-f1dc03c76c17n%40chromium.org.

woxxom

unread,
Jun 20, 2024, 10:43:18 AMJun 20
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Martin Sonesson [C]
You can force the document into HTML mode, see https://stackoverflow.com/q/69803427/

Martin Sonesson [C]

unread,
Jun 24, 2024, 5:47:52 AMJun 24
to Chromium Extensions, Oliver Dunk, Chromium Extensions, Martin Sonesson [C]
Thank you Oliver!
This is for an extension with lots of paid users, so it's not a little side project for fun I'm afraid. In that case I would just forget about this functionality, but for this extension it's quite important. I will go fill out that form and then hope for the best.

Martin Sonesson [C]

unread,
Jun 24, 2024, 5:50:24 AMJun 24
to Chromium Extensions, Martin Sonesson [C], Oliver Dunk, Chromium Extensions
Woxxom,
Thanks for the tip! That may have worked in the past, when that was written in 2022, but it seems it no longer works unfortunately. I tried myself to add the "mode=html" parameter but it doesn't do anything, the document is still using a canvas.

Oliver Dunk

unread,
Jun 24, 2024, 9:31:45 AMJun 24
to Martin Sonesson [C], Chromium Extensions
Ah, got it.

If you don't hear back in the next week or so, let me know and I can follow-up internally to make sure you get access.

Thanks,
Oliver Dunk | DevRel, Chrome Extensions | https://developer.chrome.com/ | London, GB

Reply all
Reply to author
Forward
0 new messages